【问题标题】:Spring boot - how to use 2 authentication providersSpring boot - 如何使用 2 个身份验证提供程序
【发布时间】:2019-10-04 12:31:13
【问题描述】:

我正在尝试使用 Kotlin 将 2 个身份验证提供程序与 Spring Boot 一起使用:

这个方法在一个类中:

@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true, securedEnabled = true)
@Import(SecurityProblemSupport::class)
class SecurityConfiguration(
    ...
) : WebSecurityConfigurerAdapter() {
  @Throws(Exception::class)
  override fun configure(auth: AuthenticationManagerBuilder) {
      //super.configure(auth); DON'T DO THIS - for sure...
      val dap = DaoAuthenticationProvider()
      dap.setUserDetailsService(domanUserDetailsService)
      auth.authenticationProvider(LegacyUserDaoAuthenticationProvider(legacyUserService)) . 
      auth.authenticationProvider(dap)
     // Breakpoint here shows that both authentication providers are in the builder
  }
...
}

当我在应用程序运行后运行调试器时,ProviderManager 只有 1 个提供程序。不知何故,AuthenticationManagerBuilder 没有使用这里添加的 2 个authenticationProviders。我验证了我的 configure 方法正在被调用,并且 AuthenticationManagerBuilder 在此方法之后有 2 个身份验证提供程序。

在我在这里完成的设置上发生了一些事情(或者 Spring 没有使用我设置的 AuthenticationManagerBuilder

有人知道为什么吗?

【问题讨论】:

    标签: spring spring-boot kotlin


    【解决方案1】:

    我想知道是否正在加载另一个安全配置或自动配置。您可以尝试在配置中设置@Order(1)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-04-10
      • 2017-11-21
      • 1970-01-01
      • 2012-02-18
      • 2020-07-19
      • 2019-08-08
      • 2019-01-23
      • 2021-02-28
      相关资源
      最近更新 更多