如何在spring ldap中实现编码(SHA)密码

时间:2016-10-07 12:00:37

标签: java spring spring-security ldap

我已经使用ldap实现了Spring安全性,并且在ldif文件中使用纯文本密码时工作正常,但是当我在ldap文件中使用散列{SHA}密码时,它会抛出“未授权”

代码:

     AndFilter filter = new AndFilter();
    filter.and(new EqualsFilter("objectclass", "person")).and(
        new EqualsFilter("uid", authentication.getPrincipal()
      .toString()));  

   boolean authenticatedUser = ldapTemplate.authenticate(<DN>, filter.encode(),<password>);

test.ldif:

  dn: uid=test ,ou=people,dc=springframework,dc=org
  objectclass: top
  objectclass: person
  objectclass: organizationalPerson
  objectclass: inetOrgPerson
  cn: Rod Johnson
  sn: Johnson
  uid: test
  userPassword: {SHA}a94a8fe5ccb19ba61c4c0873d391e987982fbbd3

实现ldapTemplate.authenticate的正确方法是什么?

1 个答案:

答案 0 :(得分:0)

LDAP目录服务器通常会对用户密码进行哈希处理,以防止有人发现它们。服务器如何处理导入或添加明文密码或散列密码是服务器特有的。如果这是样本数据,请以明文形式使用。如果要使用已经过哈希处理的密码导入现有用户数据,则应检查所选目录服务器是否支持所使用的算法,以及服务器的表示形式。