gpt4 book ai didi

spring - AuthenticationManagerBuilder 和 HttpSecurity.authenticationProvider 之间的区别

转载 作者:行者123 更新时间:2023-12-02 09:46:55 25 4
gpt4 key购买 nike

要在 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。

关于spring - AuthenticationManagerBuilder 和 HttpSecurity.authenticationProvider 之间的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43070356/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com