반응형
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 에 적용을 시켜줘야 확인할 수 있다
반응형
'개발 ━━━━━ > Spring(boot)' 카테고리의 다른 글
[Spring] Singleton, Prototype Scope Bean (0) | 2024.09.06 |
---|---|
[Spring] 이전 데이터를 불러올때 stream문과 for문의 성능 차이 테스트 - 1 (0) | 2023.11.18 |
[Spring] WebSocket 을 이용한 채팅 구현 (0) | 2023.10.09 |
[Spring] Entity 관계 (0) | 2023.09.02 |
[Spring] 인증 방식 (쿠키-세션, JWT) (0) | 2023.08.30 |