AuthenticationManagerBuilder

AuthenticationManagerBuilder

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

10-09 03:55