Spring Security(인증 구성요소)

Rina's·2023년 7월 11일

코드스테이츠

목록 보기
64/96

Spring Security 인증 처리 흐름

Security Filter 컴포넌트 실행 과정

/User request/
인증 필터(인증 생성) - 제공 매니저 - 인증 제공자
유저정보 서비스(유저정보 생성) 크레덴셜 저장소를 호출하여
인증 제공자(확인된 인증 생성) - 제공 매니저 - 인증 필터
시큐리티 컨텍스트(검증된 인증 저장)

1. UserPasswordAuthenticationFilter(필터)

HTTP 기반의 인증 요청을 처리
AbstractAuthenticationProcessingFilter상속하여 doFilter() 실행
Authentication 구현-> AbstractAuthenticationToken 상속 ->
UserPasswordAuthenticationToken(Uesername, Password) 생성

검증된 인증을 마지막으로 SecurityContext에 저장 -> HttpSession에 저장

2. ProviderManager(제공 매니저)

AuthenticationManager의 구현 클래스
받은 List<AuthenticationProvider>중 인증 객체를 처리할 수 있는
AuthenticationProvider를 찾아 authenticate()를 실행시킴
인증 후 Token의 Credentials를 바로 삭제

3. AuthenticationPovider(인증 제공자)

authenticate()를 실행, Authentication의 Password와 이름으로 호출한 UserDetails의 Password를 대조하여 인증

UserDetails의 비밀번호는 해시화된 형태로
대조 전 Authentication의 Password도 PasswordEncoder로 인코팅해서 비교
인증 성공 시 UserPasswordAuthenticationToken 생성

  • Principal: Username or UserDetails
  • Credentials: Password
  • GrantedAuthority: SimpleGrantedAuthority로 컬렉션 구현

메서드 실행 흐름

//DaoAuthenticationProvider는 AuthenticationProvider의 구현 클래스 
authenticate()
retrieveUser()
additionalAuthenticationChecks()
createSuccessAuthentication()
인증된 AuthenticationProviderManager에게 리턴

4. UserDetailservice(유저정보 서비스)

Credential Storage
UserDetails

5. SecurityContext

SecurityContext는 인증된 Authentication 객체를 저장하는 컴포넌트
SecurityContextHolder에 의해 저장됨
SecurityContext에 Authentication이 채워져 있다면 인증된 사용자로 간주

profile
갭린이 리나

0개의 댓글