ExceptionTranslationFilter doc에 보면 필터체인에서 던진 인증예외를 처리할 수 있다고 했는데
ExceptionTranslationFilter 필터 순서 상 무조건 뒤에 호출된 필터만 처리할 수 있다는걸 알았습니다.
ExceptionTranslationFilter 뒤에 위치한 UsernamePasswordAuthenticationFilter 입니다.
http.httpBasic().disable()
.csrf().disable()
.authorizeRequests()
.antMatchers(matchers).anonymous()
.and()
.exceptionHandling().authenticationEntryPoint(new AuthenticationEntryPointImpl())
.and()
.logout()
.logoutRequestMatcher(new AntPathRequestMatcher(Urls.logout))
.invalidateHttpSession(true) // 세션 초기화
.and().formLogin().disable()
.addFilterAfter(getUsernamePasswordAuthenticationFilterEx(), ExceptionTranslationFilter.class);
UsernamePasswordAuthenticationFilter 필터에서 인증예외 exception이 발생하면 authenticationEntryPoint 클래스에 commence 함수를 호출하게 되어 인증예외 처리가 됩니다.
필터 순서에 의해 인증예외를 처리할 수 있다면 doc가 잘 못 작성된게 아닌지 의구심이 들어 글 올려봅니다.
저와 동일한 의문을 품은 stackoverflow 질문이 있는데 아쉽게 그건 답변이 안달렸고 고심끝에 여기다가 저도 올려봅니다.
How Spring Security Filter Chain Works in case of `ExceptionTranslationFilter` - Stack Overflow