AnonymousAuthenticationFilter란?

박진형·2022년 5월 17일
0

SpringSecurity

목록 보기
1/1

AnonymousAuthenticationFilter

AnonymousAuthenticationFilter는 인증 정보가 존재하지 않을 때, 익명 사용자임을 명시해주기 위해 익명 사용자 정보를 SecurityContext에 저장해주기 위해 동작하는 필터다.

SecurityContextholder.getContext().getAuthentication() 를 통해서 인증 정보를 가져오고 존재하지 않을 시에 다음과 같이 익명 사용자 authentication을 생성한다.

여기서 key, principal, authorities는 AnonymousAuthenticationFilter가 생성될 때 생성자를 통해서 다음과 같이 지정된다.

  • key : 랜덤 값
  • princiapl : anonymousUser
  • authorities : ROLE_ANONYMOUS

이렇게 사용자가 인증을 받지 않았다고 인증 정보를 null로 다루기보다는 인증 정보가 없는 익명 사용자라는 정보를 가진 authentication을 사용하게 된다.

  • 익명 사용자인지 체크하는 부분

0개의 댓글