【发布时间】:2015-09-26 22:19:04
【问题描述】:
我正在使用 Spring Security 4.0.1 并希望使用多个身份验证提供程序来使用基于 Java 的配置进行身份验证。如何指定提供者顺序?
我希望使用AuthenticationManagerBuilder,因为这是WebSecurityConfigurerAdapter.configureGlobal() 公开的内容,但我看不到任何指定顺序的方法。我需要手动创建ProviderManager吗?
更新:这是基于 Arun 回答的问题说明。我要使用的特定提供程序是 ActiveDirectoryLdapAuthenticationProvider 和 DaoAuthenticationProvider 用于自定义 UserService。
最后,我想先验证DaoAuthenticationProvider,然后再验证ActiveDirectoryLdapAuthenticationProvider。
AD 提供程序涉及对AuthenticationManagerBuilder.authenticationProvider() 的调用,但 DAO 提供程序涉及对AuthenticationManagerBuilder.userService() 的调用,这会在幕后围绕用户服务创建一个DaoAuthenticationProvider。查看源代码,它没有直接将提供程序放在提供程序列表中(它创建了一个配置器),所以 Arun 的答案在这里对我不起作用。
我尝试手动创建DaoAuthenticationProvider 并将其传递给authenticationProvider()。对订单没有影响。
【问题讨论】:
-
我可以看看你的 spring 安全配置代码吗?我想看看身份验证提供程序是如何配置的
标签: java spring authentication spring-security