SecurityContextHolder에 Authentication 객체가 있는지 검사합니다.
Authentication 객체가 있다면, 그대로 다음 필터로 넘어갑니다.
Authentication 객체가 없다면,
AnonymousAuthenticationToken객체가 담긴 SecurityContext를 SecurityContextHolder에 넣습니다.
ExceptionTranslationFilter는 유저 인증, 인가 예외를 처리하는 필터입니다.
AccessDeniedException와 AuthenticationException을 handle 해줍니다.
AuthenticationException가 감지되면 AuthenticationEntryPoint의 commence 메소드를 호출합니다.
AccessDeniedException가 감지되면 Authentication 객체가 익명 사용자인지 검증합니다.
익명 사용자(AnonymousAuthenticationFilter가 넣은 객체)라면, AuthenticationException이 터진것처럼 AuthenticationEntryPoint의 commence 메소드를 호출합니다.
익명 사용자가 아니라면 AccessDeniedHandler의 handle 메소드를 호출합니다.
익명사용자에 따라 나뉘는 이유가 뭘까?
익명사용자가 있다는것 -> 사용자 인증이 되지 않아서 AnonymouAuthenticationFilter가 익명사용자를 SecurityContext에 넣은것 -> 인증 오류
익명사용자가 아니라는것 -> 사용자 인증은 되었지만, 해당 자원이나, 메소드에 접근하는 권한이 없다 -> 인가 오류
ExceptionTranslationFilter 정리AuthenticationException -> AuthenticationEntryPoint의 commence 메소드를 호출
AccessDeniedException
-> (익명사용자) AuthenticationEntryPoint의 commence 메소드를 호출
-> (익명사용자x) AccessDeniedHandler의 handle 메소드 호출
개인적으로 공부한 내용을 정리한 글입니다.
지적, 피드백 환영합니다.