Spring Security - 세션 기반 Form 로그인 인증 절차

·2024년 6월 9일

Spring Security

목록 보기
5/13

Form 로그인 인증 절차

이 글은 세션 기반의 Form 로그인 인증 절차에 대해서 다루고 있다.

이미지 출처 : 유튜브 "개발자 유미"님

기본 로직은 다음과 같다.

  1. 로그인 폼 제출
  2. 요청 과정에서 서블릿 필터들 중 DelegatingFilterProxy에 도달.
    필터 내부의 FilterChainProxy(스프링 빈)을 호출
  3. FilterChainProxy 가 Filter Chain을 호출
  4. Filter Chain 내부의 시큐리티 필터들이 차례로 호출됨
  5. 그 중 UsernamePasswordAuthentication 필터에서 인증을 진행
  6. 인증 완료

UsernamePasswordAuthenticationFilter는 폼 로그인 활성화 시 사용되는 필터로, username과 password 기반의 인증을 처리하는 시큐리티 필터이다.

UsernamePasswordAuthenticationFilter 인증 절차

DaoAuthenticationProvider는 AuthenticationProvider의 구현체 중 하나이다.
또한 UsernamePasswordAuthenticationFilter의 인증 과정에서 Authentication Manager에 의해 호출되는 Authentication Provider 중 하나로써, 실질적인 인증 기능을 담당한다.

DaoAuthenticationProvider

DaoAuthenticationProvider가 사용되는 UsernamePasswordAuthenticationFilter의 인증 절차는 다음과 같다.

  1. UsernamePasswordAuthenticationFilter가 HttpServletRequest로부터 제출된 username과 password를 추출하여 UsernamePassword Authentication Token을 생성한다. 그리고 생성된 토큰을 Authentication Manager의 구현체인 ProviderManager로 넘겨준다.

  2. ProviderManager는 DaoAuthenticationProvider라는 타입의 AuthenticationProvider를 사용하도록 설정되어 있다.

  3. DaoAuthenticationProviderUserDetailsService로부터 UserDetails를 확인한다.

  4. DaoAuthenticationProviderPasswordEncoder(ex. 빈으로 등록한 BcryptPasswordEncoder)를 사용하여 이전 단계에서 넘겨받은 UserDetails의 password를 검증하는 데 사용한다.

  5. 인증(Authentication)이 성공하면, 설정된 UserDetailsService에 의해 반환된 UserDetails의 주요 정보를 담은 UsernamePasswordAuthenticationToken을 반환하게 된다.
    최종적으로, 반환된 UsernamePasswordAuthenticationTokenauthentication Filter에 의하여 SecurityContextHolder에 set된다.

3, 4번에서 DaoAuthenticationProvider에 의한 실질적인 인증 과정이 진행된다.

UsernamePasswordAuthenticationFilter 역할 참고 :
https://docs.spring.io/spring-security/reference/servlet/authentication/architecture.html#servlet-authentication-abstractprocessingfilter


DaoAuthenticationProvider 절차 참고 :
https://docs.spring.io/spring-security/reference/servlet/authentication/passwords/dao-authentication-provider.html#page-title

profile
티스토리로 블로그 이전합니다. 최신 글들은 suhsein.tistory.com 에서 확인 가능합니다.

0개의 댓글