java Spring LDAP身份验证Salted SHA类型中的错误凭据密码
我有一个使用REST服务进行LDAP身份验证的项目。我的LDAP配置有Salted SHA(SSHA)密码哈希方法。在Spring的LDAP身份验证最佳实践指南中,当我使用SHA方法时,我得到了错误的凭证,而凭证是正确的
我的配置类参考:
@Configuration
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
public void configure(AuthenticationManagerBuilder auth) throws Exception {
auth
.ldapAuthentication()
.userSearchFilter("uid={0}")
.contextSource(contextSource())
.passwordCompare()
.passwordEncoder(new LdapShaPasswordEncoder())
.passwordAttribute("userPassword");
}
@Bean
public DefaultSpringSecurityContextSource contextSource() {
return new DefaultSpringSecurityContextSource(Arrays.asList("ldap://localhost:8389/"), "dc=springframework,dc=org");
}
}
我的ldif配置
dn: uid=ben,ou=people,dc=springframework,dc=org
objectclass: top
objectclass: person
objectclass: organizationalPerson
objectclass: inetOrgPerson
cn: Ben Alex
sn: Alex
uid: ben
userPassword: {SSHA}pcFdFhO/NS98EhTRup60PMkHMWFRDkJ3jUu1Zg==
我的原始密码是Test1234
。我的pom.xml
文件
<dependency>
<groupId>org.springframework.ldap</groupId>
<artifactId>spring-ldap-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-ldap</artifactId>
</dependency>
<dependency>
<groupId>com.unboundid</groupId>
<artifactId>unboundid-ldapsdk</artifactId>
</dependency>
如何使用我的用户名/密码通过SSHA密码加密对ldap服务器进行身份验证
# 1 楼答案
坚持使用初始代码,但这次尝试将
.userSearchFilter("uid={0}")
变成.userSearchFilter("uid={0},ou=people")
或.userDnPatterns("uid={0},ou=people")
# 2 楼答案
试试这个方法
并创建自定义密码编码器
我也有同样的问题,这对我很有效
希望它能帮助你
# 3 楼答案
我在使用apache目录支持的bcrypt时遇到了类似的问题。由于@jrdalpra建议的解决方案,我解决了这个问题。以下是我为处于相同情况的任何人提供的解决方案: