![](/img/trans.png)
[英]Spring Security - Verify user in DB first and then authenticate against AD
[英]How can I dynamically authenticate a user against the db or ldap with spring security?
我將身份驗證配置為可同時與db和ldap一起使用:
auth.ldapAuthentication()
.groupSearchBase(groupSearchBase)
.groupSearchFilter(groupFilter)
.userSearchFilter(userFilter).userSearchBase(userSearchBase)
.contextSource(contextSource())
.and()
.jdbcAuthentication().dataSource(dataSource).usersByUsernameQuery(
"SELECT lower(username), password, active from USER_BTABLE where lower(username)=lower(?) and LDAPAUTH=0"
).authoritiesByUsernameQuery("select lower(username), 'ROLE_USER' from USER_ATABLE where lower(username)=lower(?)");
問題在於,如果用戶還以另一個密碼(從第6個身份驗證請求開始)存在於已配置的ldap中,則會出現以下異常:
org.springframework.ldap.InvalidAttributeValueException: [LDAP: error code 19 - Exceed password retry limit. Please try later.];
如果用戶設置了db auth標志,我將檢查登錄過濾器,是否也可以在此動態配置AuthenticationManagerBuilder ?
我最終做了一個307重定向,從db auth服務器實例到doFilter
方法中的ldap auth服務器實例:
httpResponse.setStatus(TEMPORARY_REDIRECT);
httpResponse.setHeader("Location", req.getScheme() + "://"redirectLocation);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.