在反应式编程模型中注册自定义 AuthenticationProvider

pix*_*xel 5 spring-security spring-boot spring-webflux

我正在尝试注册我自己的AuthenticationProvider.

我的配置:

@EnableWebFluxSecurity
class SecurityConfig {

  @Bean
  fun customAuthenticationProvider(): CustomAuthenticationProvider {
    return CustomAuthenticationProvider()
  }

  @Bean
  fun securityWebFilterChain(http: ServerHttpSecurity): SecurityWebFilterChain {
    return http.authorizeExchange()
        .anyExchange().authenticated()
        .and().build()
  }
}
Run Code Online (Sandbox Code Playgroud)

但由于我使用 webflux 我无法使用WebSecurityConfigurerAdapter.

启用此类功能的正确方法是什么AuthenticationProvider

pix*_*xel 6

好吧,我已经得到答案了——我需要注册 Bean 类型ReactiveAuthenticationManager。来源: https: //github.com/spring-projects/spring-security/issues/5565