我如何根据具有 spring 安全性的 db 或 ldap 动态验证用户?
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(?)");
问题在于,如果用户还存在于配置的 ldap 中,并且从第 6 次身份验证请求开始使用另一个密码,则会出现以下异常:
org.springframework.ldap.InvalidAttributeValueException: [LDAP: error code 19 - Exceed password retry limit. Please try later.];
如果用户设置了 db auth 标志,我会检查登录过滤器,我可以在那里动态配置 AuthenticationManagerBuilder 吗?
我最终在 doFilter
方法中进行了从 db auth 服务器实例到 ldap auth 服务器实例的 307 重定向:
httpResponse.setStatus(TEMPORARY_REDIRECT);
httpResponse.setHeader("Location", req.getScheme() + "://"redirectLocation);
我将身份验证配置为与 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(?)");
问题在于,如果用户还存在于配置的 ldap 中,并且从第 6 次身份验证请求开始使用另一个密码,则会出现以下异常:
org.springframework.ldap.InvalidAttributeValueException: [LDAP: error code 19 - Exceed password retry limit. Please try later.];
如果用户设置了 db auth 标志,我会检查登录过滤器,我可以在那里动态配置 AuthenticationManagerBuilder 吗?
我最终在 doFilter
方法中进行了从 db auth 服务器实例到 ldap auth 服务器实例的 307 重定向:
httpResponse.setStatus(TEMPORARY_REDIRECT);
httpResponse.setHeader("Location", req.getScheme() + "://"redirectLocation);