我正在尝试实施Spring Boot LDAP Security,并且我使用 unboundid-ldapsdk 嵌入式LDAP服务器进行测试(如教程here)。我将Web安全性配置为使用LDAP绑定进行身份验证,并使用明文密码成功测试。但是,如果我将密码更改为散列版本,则身份验证将失败。我错过了一些配置吗?
这是我的安全配置:
@Configuration
@EnableWebSecurity
public class MyWebSecurityConfiguration extends WebSecurityConfigurerAdapter
{
...
@Override
protected void configure(AuthenticationManagerBuilder authenticationManagerBuilder)
throws Exception
{
authenticationManagerBuilder.
ldapAuthentication().
userSearchFilter(this.ldapUserSearchFilter).
userSearchBase(this.ldapUserSearchBase).
contextSource(this.contextSource()).
ldapAuthoritiesPopulator(this.authoritiesPopulator());
}
@Bean
public DefaultSpringSecurityContextSource contextSource()
{
DefaultSpringSecurityContextSource securityContextSource =
new DefaultSpringSecurityContextSource(
Collections.singletonList(this.ldapUrl),
this.ldapBaseDn);
return securityContextSource;
}
...
}
嵌入式LDAP属性:
spring.ldap.embedded.ldif=classpath:ldap-test.ldif
spring.ldap.embedded.base-dn=dc=testing,dc=com
spring.ldap.embedded.port=8389
和LDIF文件:
dn: dc=testing,dc=com
objectclass: top
objectclass: domain
objectclass: extensibleObject
dc: testing
dn: ou=TestingUsers,dc=testing,dc=com
objectclass: top
objectclass: organizationalUnit
ou: TestingUsers
dn: uid=testUser,ou=TestingUsers,dc=testing,dc=com
objectclass: top
objectclass: person
objectclass: organizationalPerson
objectclass: inetOrgPerson
cn: Blah_1
sn: Blah_2
uid: testingUser
userPassword: pass
使用这些设置,我可以使用用户名进行身份验证 testingUser 和密码传递。但是,如果我使用哈希密码:
userPassword: {SHA}9d4e1e23bd5b727046a9e3b4b7db57bd8d6ee684
我无法进行身份验证,并获得此异常:
javax.naming.AuthenticationException: [LDAP: error code 49 - Unable to bind as user 'uid=testingUser,ou=TestingUsers,dc=testing,dc=com' because the provided password was incorrect.]
感谢您的帮助!
更新
我发现使用散列密码,我可以通过输入散列本身而不是原始密码进行身份验证。那么 unboundid-ldapsdk 可能无法识别{SHA}表示法吗?