简体   繁体   English

如何使用Spring Security针对db或ldap对用户进行动态身份验证?

[英]How can I dynamically authenticate a user against the db or ldap with spring security?

I configured the authentication to work with both the db and ldap like this: 我将身份验证配置为可同时与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(?)");

The trouble is that if the user also exists in the configured ldap with another password starting with the 6th authentication request the following exception appears: 问题在于,如果用户还以另一个密码(从第6个身份验证请求开始)存在于已配置的ldap中,则会出现以下异常:

 org.springframework.ldap.InvalidAttributeValueException: [LDAP: error code 19 - Exceed password retry limit. Please try later.];

I check in the login filter if the user has the db auth flag set, can I configure the AuthenticationManagerBuilder on the fly there also? 如果用户设置了db auth标志,我将检查登录过滤器,是否也可以在此动态配置AuthenticationManagerBuilder

I eventually did a 307 redirect from a db auth server instance to an ldap auth server instance inside a doFilter method: 我最终做了一个307重定向,从db auth服务器实例到doFilter方法中的ldap auth服务器实例:

httpResponse.setStatus(TEMPORARY_REDIRECT);
httpResponse.setHeader("Location", req.getScheme() + "://"redirectLocation);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Spring 安全 - 首先验证数据库中的用户,然后再针对 AD 进行身份验证 - Spring Security - Verify user in DB first and then authenticate against AD 如何使用spring Security通过基于邮件和uid的LDAP对用户进行身份验证? - How to authenticate a user from LDAP based on mail and by uid with spring Security? Spring安全性配置来认证ldap用户 - Spring security configuration to authenticate ldap user 如何使用DaoAuthenticationProvider以编程方式使用Spring Security对用户进行身份验证 - How can I programmatically authenticate user with Spring Security using DaoAuthenticationProvider 使用Spring Security 3对仅具有用户名的用户进行REST身份验证 - Using Spring security 3 to authenticate against REST a user only with username 如何在CQ 6中通过LDAP通过目录对用户进行身份验证 - How to authenticate user against directory via LDAP in CQ 6 如何在spring security中只通过ip地址验证用户? - How can authenticate user by only ip address in spring security? 配置Spring Security以针对LDAP进行身份验证而无需匿名和绑定DN - Configuring Spring Security to Authenticate against LDAP without anonymous and without bind DN Spring Security无法验证用户 - Spring security not authenticate the user 如何通过Android应用针对Spring Security进行身份验证? - How to authenticate against Spring Security from Android app?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM