1. Authentication이란?
- 사용자의 신원을 확인하는 인증(Authentication) 과정을 나타내는 객체이다.
- 사용자 이름, 비밀번호 같은 자격 증명(credentials)으로 사용자 신원을 증명하는 역할.
- 인증 성공 후에는 인증된 사용자 정보와 권한을 포함한다.
2. Authentication 객체의 주요 속성
속성 설명
principal | 인증 대상 사용자 정보 (예: UserDetails) |
credentials | 인증에 사용된 비밀번호 등 증명 정보 (인증 후 삭제될 수 있음) |
authorities | 사용자가 가진 권한 리스트 (예: ROLE_USER) |
isAuthenticated() | 인증 성공 여부 (true이면 인증된 상태) |
3. 인증 흐름 간단 설명
- 사용자가 로그인 정보를 입력해 요청을 보냄.
- 인증 필터(AuthenticationFilter)가 요청을 가로채서 인증 정보가 담긴 Authentication 객체를 생성함. 이때 authenticated는 false.
- 이 객체를 AuthenticationManager에 전달.
- AuthenticationManager는 내부의 AuthenticationProvider를 통해 실제 인증을 수행.
- 인증이 성공하면, 인증된 Authentication 객체가 반환되고 authenticated가 true가 됨.
- 인증된 객체는 SecurityContextHolder에 저장되어 애플리케이션 전반에서 사용됨.
4. SecurityContextHolder 역할
- Authentication 객체를 담고 있는 SecurityContext를 관리하는 곳.
- 현재 쓰레드에 인증 정보를 안전하게 저장하여, 어디서든 인증된 사용자 정보를 조회할 수 있도록 지원.
'Spring-Security' 카테고리의 다른 글
AuthenticationManager & AuthenticationManagerBuilder (0) | 2025.05.24 |
---|---|
SecurityContext & SecurityContextHolder (0) | 2025.05.23 |
Spring Security 인증 흐름도 (Authentication Flow) (0) | 2025.05.23 |
RequestCache, SavedRequest, RequestCacheAwareFilter (0) | 2025.05.23 |
logout() (0) | 2025.05.23 |