Skip to content

Conversation

@Gyuhyeok99
Copy link
Contributor

관련 이슈

작업 내용

문제 내용

유효하지 않은 토큰으로 API 요청 시 JwtAuthenticationFilter에서 발생한 예외(CustomException 등)가 ExceptionHandlerFilter에서 잡히지 않고, WAS 기본 예외 처리로 넘어가면서 500 에러가 발생하는 문제가 있었습니다.

문제 원인

참고사진 지난번 #192 pr에서 인증/인가 관련 예외처리를 잡지 못해 필터순서를 조정하니 jwtAuthenticationFilter 발생한 예외를 잡아줄 exceptionHandlerFilter가 jwtAuthenticationFilter보다 훨씬 뒤인 ExceptionTranslationFilter 뒤에 있어서 잡지 못하는 것이었습니다.

문제 해결

필터 순서를 원복하고, Spring Security의 기본 제공 기능인 AccessDeniedHandler와 AuthenticationEntryPoint를 활용해 인증/인가 예외를 처리하도록 변경했습니다.
CustomAuthenticationEntryPoint, CustomAccessDeniedHandler를 구현하여 예외 발생 시 일관된 JSON 응답이 내려가도록 했습니다.

리뷰 요구사항 (선택)

일단 필터 순서변경만으로 인가 관련 예외 잡는 것과 jwtAuthenticationFilter 예외를 잡는 것을 동시에 해결하는 것이 어려울 거 같아 이 방식으로 구현을 했는데 추후 더 나은 해결책을 찾으면 그거로 적용해보도록 하겠습니다 🥲

@Gyuhyeok99 Gyuhyeok99 added the 버그 Something isn't working label Feb 15, 2025
@Gyuhyeok99 Gyuhyeok99 self-assigned this Feb 15, 2025
Copy link
Member

@wibaek wibaek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@Gyuhyeok99 Gyuhyeok99 merged commit e990385 into solid-connection:develop Feb 15, 2025
@Gyuhyeok99 Gyuhyeok99 deleted the fix/208-security-filter-exception branch February 17, 2025 05:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

버그 Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: 유효하지 않은 토큰으로 api 요청 시 500 error 발생 버그 수정

3 participants