5.인증 공급자
AuthenticationProvider 인터페이스는 적합한 인증 방식에 맞게 실제 인증을 처리하는 역할을 수행하는 인터페이스,
→ UserDetailsService를 호출하여 데이터베이스에서 사용자 정보를 조회하도록 함
1-1.DaoAuthenticationProvider
AuthenticationProvider 인터페이스를 구현한 구현 클래스 중 하나
DaoAuthenticationProvider.java
public class DaoAuthenticationProvider extends AbstractUserDetailsAuthenticationProvider {
// AbstractUserDetailsAuthenticationProvider implements AuthenticationProvider
private static final String USER_NOT_FOUND_PASSWORD = "userNotFoundPassword";
private PasswordEncoder passwordEncoder;
// ...
private UserDetailsService userDetailsService;
// ...
@Override
protected final UserDetails retrieveUser(String username, UsernamePasswordAuthenticationToken authentication) throws AuthenticationException {
prepareTimingAttackProtection();
try {
// UserDetailsService를 통해 사용자 정보 조회 처리 수행
UserDetails loadedUser = this.getUserDetailsService().loadUserByUsername(username);
if (loadedUser == null) {
throw new InternalAuthenticationServiceException(
"UserDetailsService returned null, which is an interface contract violation");
}
return loadedUser;
}
catch (UsernameNotFoundException ex) {
mitigateAgainstTimingAttack(authentication);
throw ex;
}
catch (InternalAuthenticationServiceException ex) {
throw ex;
}
catch (Exception ex) {
throw new InternalAuthenticationServiceException(ex.getMessage(), ex);
}
}
}
Last updated on