[Spring Security] DaoAuthenticationProvider

JD_S·2022년 10월 20일
0

Spring-Security

목록 보기
3/5

DaoAuthenticationProvider는 UserDetailsService 및 PasswordEncoder를 활용하여 사용자 이름과 암호를 인증하는 AuthenticationProvider(인터페이스)의 구현체이다.

AuthenticationProvider는 AbstractUserDetailsAuthenticationProvider(추상 클래스)에 의해 구현됐는데 DaoAuthenticationProvider가 AbstractUserDetailsAuthenticationProvider를 상속했다.

1. UsernamePasswordAuthenticationFilterUsernamePasswordAuthenticationToken을 생성 후에 ProviderManager에 의해 구현이 된 AuthenticationManager에게 전달한다. 아래 코드는 UsernamePasswordAuthenticationFilter클래스의 attemptAuthentication(...)메서드이다. 이 메서드에 의해 UsernamePasswordAuthenticationToken이 생성되는 것을 알 수 있다.

2. ProviderManagerDaoAuthenticationProvider에 의해 구현된 AuthenticationProvider를 사용하도록 구성되어 있다.

3. DaoAuthenticationProviderUserDetailsService에서 UserDetails를 찾는다.

4. 그런 다음 DaoAuthenticationProviderPasswordEncoder를 사용하여 이전 단계에서 반환된 UserDetails의 암호를 확인한다.

5. 인증이 성공하면, 반환된 AuthenticationUsernamePasswordAuthenticationToken 유형이고 구성된 UserDetailService에서 반환된UserDetailsprincipal을 가진다. 결국 반환된 UsernamePasswordAuthenticationTokenUsernamePasswordAuthenticationFilter에 의해 SecurityContextHolder에 설정된다.

Reference

profile
Whatever does not destroy me makes me stronger.

0개의 댓글