【发布时间】:2015-09-05 02:03:33
【问题描述】:
我正在设置我的 Spring Security (v4.0.1) Web 应用程序。我想要两个身份验证提供程序,一个用于管理管理员帐户的“内存中”提供程序,另一个是我自己的实现的自定义提供程序。系统应该首先尝试对“内存中”提供者进行身份验证,然后对自定义提供者进行身份验证。我的代码如下所示:
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth,
AuthenticationProvider provider) throws Exception {
auth.inMemoryAuthentication()
.withUser("admin")
.password("s3cr3t")
.authorities("ADMIN");
auth.authenticationProvider(provider);
}
但是,此代码导致框架首先尝试我的自定义实现。这有点道理,因为AuthenticationManagerBuilder#authenticationProvider 方法将提供程序添加到内部列表中,而AuthenticationManagerBuilder#inMemoryAuthentication 方法在内部对其进行配置。我怎样才能让它发挥作用?
【问题讨论】:
标签: java spring-security