[처리 흐름]
1. Username, Password를 포함한 request를 Spring Security 적용 애플리케이션에 전송
2. Filter Chain 중 하나인 UsernamePasswordAuthenticationFilter은 받은 정보를 UsernamePasswordAuthentiacitonToken에 넘겨 해당 필터가 Username+Password를 이용해 아직 인증되지 않은 Authentication을 생성해 받음
3. 인증처리 총괄 인터페이스인 AuthenticationManager은 이를 받아 실질 총괄 작업 매니저인 ProviderManger에게 넘김
4. ProvideManger은 인증을 위해 Authentication을 AuthenticationProvider에게 넘겨 인증 처리를 위임함
5. UserDetailsService를 이용해 UserDetails를 조회
6. Credential을 조회하여 크리덴셜 저장소에서 크리덴셜을 포함한 사용자 정보를 조회함
7. 저장소에서 조회한 사용자 크리덴셜을 포함한 정보를 기반으로 UserDetails를 생성 및 전달함
8. PasswordEncoder는 이를 받아 UserDetails에 포함된 암호화된 Password와 인증을 위한 Authentication 내 Password 일치 여부를 확인
9. 인증에 성공할 경우 인증된 Authentiaciton을 생성하며, 실패할 경우 Exception을 발생시킴
10. 인증된 Authentication을 AuthenticationManager에게 전달
11. 인증된 Authenticaiton을 UsernamePasswordAuthenticationFilter에 전달
12. UsernamePasswordAuthenticationFilter은 인증된 Authentiactiond을 SecurityContext에 저장함
[단어 설명]
- UsernamePasswordAuthenticationFilter : 사용자의 로그인 요청을 처리하는 Spring Security Filter
- UsernamePasswordAuthenticationToken : Authentication 인터페이스를 구현한 클래스로, 여기서의 Authentication은 아직 인증되지 않은 Authentication을 의미
- AuthenticationManager : 인증 처리를 총괄하는 매너지 역할을 하는 인터페이스
- ProviderManager : AuthenticationManager을 구현한 구현 클래스로 작업을 총괄하는 실질적인 매니저
- UserDetails : 데이터베이스 등의 저장소에 저장된 사용자의 Username과 사용자의 자격을 증명해주는 크리덴션(Credentail)인 Password, 그리고 사용자의 권한 정보를 포함하고 있는 컴포넌트
- UserDetailsService : UserDetails를 제공하는 컴포넌트
- UserDetailsService는 데이터베이스 등의 저장소에서 사용자의 크리덴셜을 포함한 사용자의 정보를 조회하여 AuthenticationProvider에게 제공하며, 이는 인증에 성공한 사용자의 정보(Principal, Credential, GrantedAuthorities)를 가지고 있음