본문 바로가기
개발 관련 지식/Spring Framework Basic

Security - 인증 Flow

by 권태일1147 2022. 4. 3.
  1. 클라이언트가 로그인 요청
  2. Form 인증 방식 요청이면 UsernamePasswordAuthenticationFilter가 로그인 요청을 받아서 Authentication 인증 객체를 생성한다.
    • Authentication : username + password 담은 인증 전 토큰 객체 생성
  3. UsernamePasswordAuthenticationFilter는 AuthenticationManager에 인증 객체를 전달하며 인증 처리를 맡긴다.
  4. AuthenticationManager는 AuthenticationProvider에게 실제 인증을 위임한다.
    • AuthenticationProvider가 여러개 있는데 그 중 하나에 실제 인증을 위임하는 것이 manager의 역할
  5. AuthenticationProvier는 UserDetailsService에 있는 loadUserByUsername(username)을 호출하면서 username을 전달하면서 User객체를 요구한다.
  6. UserDetailsService는 Repository에 findById()를 통해서 User객체를 조회하고 UserDetails 타입으로 반환한다.
  7. UserDetailsService는 Repository로부터 받은 UserDetails 객체와 AuthenticationProvider에게 받은 Authentication 인증 객체의 password를 비교해서 인증 성공, 실패를 판단한다
  8. 성공하면 AuthenticationProvider는 UserDetails + authorities를 담은 Authentication 인증 객체를 생성해서 AuthenticationManager에게 반환한다.
  9. AuthenticationManager는 인증 객체를 UsernamePasswordAuthenticationFilter에게 반환한다.
  10. UsernamePasswordAuthenticationFilter는 SecurityContext에 인증 객체를 저장한다.