要在 spring boot中提供自定义身份验证提供程序,是否需要以下两项?他们的区别是什么?
AuthenticationManagerBuilder
HttpSecurity.authenticationProvider(…)
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter{
@Autowired
private MyAuthenticationProvider myAuthenticationProvider;
@Autowired
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.authenticationProvider(myAuthenticationProvider);
}
// --------------- OR/AND ? ----------------
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authenticationProvider(myAuthenticationProvider)
// ...
}
}
最佳答案 您只需要使用两个选项之一.在内部,http.authenticationProvider只是调用AuthenticationManagerBuilder.authenticationProvider.