스프링 시큐리티 - AnonymousAuthenticationFilter와 ExceptionTranslationFilter

HUSII·2023년 8월 25일
0

스프링 시큐리티

목록 보기
7/7

AnonymousAuthenticationFilter의 역할

SecurityContextHolder에 Authentication 객체가 있는지 검사합니다.

Authentication 객체가 있다면, 그대로 다음 필터로 넘어갑니다.

Authentication 객체가 없다면, AnonymousAuthenticationToken 객체가 담긴 SecurityContext를 SecurityContextHolder에 넣습니다.


ExceptionTranslationFilter의 역할

ExceptionTranslationFilter는 유저 인증, 인가 예외를 처리하는 필터입니다.

AccessDeniedExceptionAuthenticationException을 handle 해줍니다.

AuthenticationException가 감지되면 AuthenticationEntryPointcommence 메소드를 호출합니다.

AccessDeniedException가 감지되면 Authentication 객체가 익명 사용자인지 검증합니다.

익명 사용자(AnonymousAuthenticationFilter가 넣은 객체)라면, AuthenticationException이 터진것처럼 AuthenticationEntryPointcommence 메소드를 호출합니다.

익명 사용자가 아니라면 AccessDeniedHandlerhandle 메소드를 호출합니다.

익명사용자에 따라 나뉘는 이유가 뭘까?

익명사용자가 있다는것 -> 사용자 인증이 되지 않아서 AnonymouAuthenticationFilter가 익명사용자를 SecurityContext에 넣은것 -> 인증 오류

익명사용자가 아니라는것 -> 사용자 인증은 되었지만, 해당 자원이나, 메소드에 접근하는 권한이 없다 -> 인가 오류


ExceptionTranslationFilter 정리

AuthenticationException -> AuthenticationEntryPointcommence 메소드를 호출

AccessDeniedException
-> (익명사용자) AuthenticationEntryPointcommence 메소드를 호출
-> (익명사용자x) AccessDeniedHandlerhandle 메소드 호출

개인적으로 공부한 내용을 정리한 글입니다.
지적, 피드백 환영합니다.

profile
공부하다가 생긴 궁금한 것들을 정리하는 공간

0개의 댓글