要在spring boot中提供自定义身份验证提供程序,是否需要以下两项?他们的区别是什么?
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)
// ...
}
}
答案 0 :(得分:2)
您只需使用两个选项中的一个。在内部,http.authenticationProvider只是调用AuthenticationManagerBuilder.authenticationProvider。