Authentication
객체를 만들고 → AuthenticationManager
가 AuthenticationProvider
에게 인증을 위임 → 인증 성공 시 인증된 Authentication을 반환하는 구조다.사용자가 로그인 요청 → UsernamePasswordAuthenticationToken
생성
authenticationManager.authenticate()
호출 후 인증 위임
내부적으로 위임 받은 AuthenticationProvider
가 인증 수행
인증 성공 시 새로운 인증된 Authentication
반환, 실패 시 AuthenticationException
발생
SecurityContextHolder
에 저장
클라이언트 요청(Authentication 객체)
│
▼
AuthenticationManager
┌─────────────────────────┐
│ Provider 목록 순회 │
│ ┌───────────────┐ │
│ │ DaoAuthProvider │ supports() ──> true? ──┐
│ └───────────────┘ │ │
│ ┌───────────────┐ │ ▼
│ │ JwtAuthProvider │ supports() ──> true? ──┐
│ └───────────────┘ │ ▼
│ ┌───────────────┐ │ ▼
│ │ OAuth2Provider │ supports() ──> true? ──┐
│ └───────────────┘ │
└─────────────────────────┘ │
▼
authenticate() 호출
│
성공 → 인증된 Authentication 반환
실패 → AuthenticationException 던짐
Authentication
은 Spring Security에서 인증 객체를 추상화한 인터페이스를 말한다.
public interface Authentication extends Principal, Serializable {
Collection<? extends GrantedAuthority> getAuthorities();
Object getCredentials();
Object getDetails();
Object getPrincipal();
boolean isAuthenticated();
void setAuthenticated(boolean isAuthenticated) throws IllegalArgumentException;
}
즉, 인증 전/후 정보를 모두 담을 수 있는 표준 구조이다.