흐름을 생각해보자, 사용자 요청이 들어오면 커스텀인증필터로 가장 먼저 들어온다.

case1)

  1. 요청 식별자(ex. username)로된 시큐리티 컨텍스트에 인증객체가 존재하지않는다면
  2. UserDetailsService로 사용자가 정의한 저장소에서 UserDetails을 가져와 요청 식별자와 비교한다.
  3. 일치한다면 새로운 authentication객체를 생성하고 context에 등록한다.
  4. 일치하지않는다면 다른 필터로 위임하고 다 실패시 익명사용자가 된다.

개요

구성 요소 역할
UserDetails 사용자 정보 모델
UserDetailsService 사용자 정보 조회 (DB 등에서)
AuthenticationProvider 인증 로직 수행
AuthenticationManager 인증 위임 및 관리
AuthenticationFilter 인증 시도 트리거 (예: 로그인 요청 처리)

Authentication 인터페이스

메서드 설명
getPrincipal() 사용자 정보 (UserDetails)
getCredentials() 자격 증명 (예: 비밀번호, 인증 후 null 처리)
getAuthorities() 권한 목록 (ROLE_...)
getDetails() 요청에 대한 추가 정보 (IP, 세션 등)
authToken.setDetails(new WebAuthenticationDetailsSource().buildDetails(request));
getName() 사용자 ID (보통 username)
isAuthenticated() 인증 여부 (true면 로그인된 상태)

📝 UserDetails