[英]How to handle exceptions from Spring Boot's LdapAuthenticationProviderConfigurer
我在 Spring 引導應用程序中有以下 web 安全性:
@Override
public void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.ldapAuthentication()
.contextSource(contextSource)
.userSearchBase("OU=users,DC=example,DC=com")
.userSearchFilter("userName={0}")
.ldapAuthoritiesPopulator(authoritiesPopulator)
.and()
// fall back to the admin group if not found
.ldapAuthentication()
.contextSource(contextSource)
.userSearchBase("OU=admins,DC=example,DC=com")
.userSearchFilter("userName={0}")
.ldapAuthoritiesPopulator(authoritiesPopulator)
;
}
這個想法非常簡單:嘗試在users
組中搜索,如果找不到用戶,則嘗試admin
組。 在第一次查找出現問題之前,所有這些都非常有效。 例如,如果users
組突然消失,第一次查找將生成異常,並且永遠不會嘗試第二次查找。 有沒有辦法配置LdapAuthenticationProviderConfigurer
或AuthenticationManagerBuilder
在身份驗證提供程序異常之一出現時不中止整個過程?
遵循這個答案- 也許這個(未經測試的代碼)
public void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.ldapAuthentication()
.contextSource(contextSource)
.userSearchBase("DC=example,DC=com")
//.userSearchFilter("&((userName={0}))")
.userDnPatterns("userName={0},OU=users", "userName={0},OU=admins")
.ldapAuthoritiesPopulator(authoritiesPopulator))
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.