首页 > 解决方案 > 在不扩展 WebSecurityConfigurerAdapter 的情况下访问 Global AuthenticationManagerBuilder?

问题描述

我正在使用spring-authorization-server。我已经按照示例中所示的方式配置了它,SecurityFilterChain而不是像示例中那样扩展WebSecurityConfigurerAdapter它,例如

@Bean
SecurityFilterChain defaultSecurityFilterChain(HttpSecurity http) throws Exception {
    http
        .authorizeRequests(authorizeRequests ->
            authorizeRequests.anyRequest().authenticated()
        )
        .formLogin(withDefaults());
    return http.build();
}

现在的问题是:如何访问AuthenticationManagerBuilder以添加自定义AuthenticationProvider?(不使用WebSecurityConfigurerAdapter; 因为我不能将它与 a 一起使用SecurityFilterChain

我已经配置了带有 JWT 的 OAuth,现在我正在尝试添加 SAML 支持,但我相信我需要访问全局AuthenticationManagerBuilder才能添加我的 SAMLAuthenticationProvider 并将构建的内容公开AuthenticationManager为 bean,以便在我的配置中进一步使用。

我看到它完成的唯一方法是通过覆盖WebSecurityConfigurerAdapter的方法。

例如

public class SecurityConfig extends WebSecurityConfigurerAdapter {

  @Autowired
  private CustomAuthenticationProvider authProvider;

  @Bean
  @Override
  public AuthenticationManager authenticationManagerBean() throws Exception {
      return super.authenticationManagerBean();
  }

  @Override
  protected void configure(AuthenticationManagerBuilder auth) throws Exception {
      auth.authenticationProvider(authProvider);
  }
}

有没有办法在AuthenticationManager不扩展的情况下配置和访问 bean WebSecurityConfigurerAdapter

标签: spring-bootspring-security

解决方案


推荐阅读