사용자가 입력한 password 와 디비에 저장된 password 가 같은지 검증하고, 다르다면 BadCredentialsException 를 던진다.
마지막으로 UsernamePasswordAuthenticationToken 으로 만들어서 반환해 준다.
SecurityConfig 에 CustomAuthenticationProvider 등록
@Configuration
@EnableWebSecurity
@Slf4j
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.authenticationProvider(authenticationProvider());
}
@Bean
public AuthenticationProvider authenticationProvider() {
return new CustomAuthenticationProvider();
}
}
먼저 CustomAuthenticationProvider 를 빈으로 등록하고, authenticationProvider 메소드에 인자로 넘겨 줌으로써, 스프링 시큐리티가 기본적으로 제공하는 AuthenticationProvider 를 사용하지 않고, 직접 만든 CustomAuthenticationProvider 를 사용할 수 있다.