SpringBoot22 OpenFeign 사용 시 헤더 값 넘기기 들어가기 앞서..- 시큐리티 연동(jwtToken 방식)해둔 상태 api 요청 시 헤더에 토큰을 담겨서 서버로 들어온다. 필터에선 토큰 검증 완료하여 원하는 비즈니스 로직을 처리한다. 비즈니스 로직 중 openfeign으로 외부 API 호출하는 로직이 있으며, 외부 API에게 동일하게 첫 요청 시 전달받았던 토큰을 동일하게 세팅해주어야 했다. 즉, 첫 요청 시 전달받은 헤더값을 openFeign으로 외부API요청 시에도 동일하게 세팅하는 해주어야 했다. 시도 1. 쓰레드로컬변수 사용해볼까?스프링MVC는 요청마다 쓰레드를 할당받아 사용하니쓰레드 내 쓰레드로컬변수를 활용하여 토큰을 저장했다가 외부API호출 시 헤더 세팅하고 없애주면 되지않을까?? 쓰레드 로컬변수 선언public class ThreadLoca.. 2024. 3. 27. 리소스 접근 시 인증,인가 Exception 처리 특정 자원 접근 시 발생하는 있는 거절 종류 ( 토큰은 정상 ) - 로그인조차 되지 않은 채 로그인이 필요한 리소스에 접근 시 AuthenticationException -> 인증 실패 - 로그인하였으나 권한 없는 관계로 인한 AccessDeniedException -> 인가 실패 *로그인 은 정상 토큰으로 인증객체 생성 완료된 상태 *비로그인 은 Anonymous인증객체가 생성 완료된 상태 더보기 각각 어떤 식으로 에러 응답을 처리할까? 인가 실패 CustomAccessDeniedHandler 권한 없는 자원 접근 발생하는 예외( AccessDeniedException )에 대하여 AccessDeinedHandler 인터페이스를 구현하여 처리 @Slf4j public class CustomAccessD.. 2023. 10. 19. JwtAuthenticationFilter 내 발생 가능한 Exception 공통 처리 JwtAuthenticationFilter 인증 필터 내 검증되는 부분은 두 종류가 존재한다. 1. ID 존재 여부 2. 비밀번호 일치 여부 두 종류의 검증에 대해 거절 상황 시 하나의 로직으로 응답할 수 있는 방법이 필요하였다.... 인증처리 시 Exception 처리 부분을 먼저 확인해본다. 인증 처리하는 Filter 일부분 1. Authentication authenticationResult = attemptAuthentication(request, response); attemptAuthentication 메소드를 통하여 ID, 패스워드 등 인증한다. 이 때, ID 및 비밀번호 검증 실패 시 AuthenticationException 을 던지게 된다. 2.catch (AuthenticationEx.. 2023. 10. 19. [이슈] AuthenticationProvider 인터페이스 구현 후 적용되지 않는 상황 처리 SpringSecurityConfig 파일 @Configuration @RequiredArgsConstructor @EnableWebSecurity public class SpringSecurityConfig { private final MemberService memberService; private final PasswordEncoder bCryptPasswordEncoder; private final CustomJwtProvider customJwtProvider; private final AuthenticationConfiguration authenticationConfiguration; @Bean public SecurityFilterChain filterChain(HttpSecurity htt.. 2023. 10. 19. 이전 1 2 3 4 5 6 다음