2023.09.02 - Filter

mjjin·2023년 9월 2일
0

업로드중..

Filter

Spring Security - Filter Chain 기반에서 동작

UsernamePasswordAuthenticationFilter는 Spring Security의 필터인 AbstractAuthenticationProcessingFilter를 상속한 Filter입니다.
기본적으로 Form Login 기반을 사용할 때 username 과 password 확인하여 인증합니다.
인증 과정
사용자가 username과 password를 제출하면 UsernamePasswordAuthenticationFilter는 인증된 사용자의 정보가 담기는 인증 객체인 Authentication의 종류 중 하나인 UsernamePasswordAuthenticationToken을 만들어 AuthenticationManager에게 넘겨 인증을 시도합니다.
실패하면 SecurityContextHolder를 비웁니다.
성공하면 SecurityContextHolder에 Authentication를 세팅합니다.
SecurityContextHolder

SecurityContext는 인증이 완료된 사용자의 상세 정보(Authentication)를 저장합니다.
SecurityContext는 SecurityContextHolder 로 접근할 수 있습니다.

현재 인증된 사용자를 나타내며 SecurityContext에서 가져올 수 있습니다.
principal : 사용자를 식별합니다.
Username/Password 방식으로 인증할 때 일반적으로 UserDetails 인스턴스입니다.
credentials : 주로 비밀번호, 대부분 사용자 인증에 사용한 후 비웁니다.
authorities : 사용자에게 부여한 권한을 GrantedAuthority로 추상화하여 사용합니다.
Validation

Bean Validation

검증해주는 @annotation 확인

@Valid 를 Controller 에 적용을 시켜줘야 확인할 수 있다!

출처 : https://gukjan9.tistory.com/51

0개의 댓글