OpenLDAP - 获取密码属性

时间:2017-07-24 13:10:00

标签: java ldap openldap

我正在编写一个OpenLdap控制器,我有很多ldap函数。一个功能是获取LdapUser及其不同的属性。

例如:

    NamingEnumeration<SearchResult> enumResult = null;
    UserData ldapUser = new UserData();

    private String[] user_attributes = new String[]{"uid","cn", "sn", "dn", "description", "mail", "displayName",
        "userPassword","pwdChangedTime","pwdExpires", "lastLogonTime"};

    try
    {                  
        SearchControls searchCtrls = new SearchControls();
        searchCtrls.setSearchScope(SearchControls.SUBTREE_SCOPE);
        searchCtrls.setReturningAttributes(user_attributes);


        String filter = "(&(objectClass=inetOrgPerson)(uid="+userUid+"))";

        enumResult = ctx.search(ou,filter,searchCtrls);

        SearchResult result = (SearchResult) enumResult.next();


        ldapUser.setUid(getAttribute(result,"uid"));    
        ldapUser.setCN(getAttribute(result, "cn"));
        ldapUser.setSN(getAttribute(result, "sn"));
        ldapUser.setGivenName(getAttribute(result, "givenName"));
        ldapUser.setDescription(getAttribute(result, "description"));
        ldapUser.setMail(getAttribute(result, "mail"));         

    }

工作正常。我的ldapUser类充满了属性。之前我为TDS控制器做了同样的事情,我甚至可以使用以下属性:

        ldapUser.setPassword(getAttribute(result, "userPassword"));
        ldapUser.setpwdExpires(getAttribute(result,"pwdExpires"));
        ldapUser.setpwdChangedTime(getAttribute(result, "pwdChangedTime"));
        ldapUser.setlastLogonTime(getAttribute(result,"lastLogonTime"));

但似乎这对OpenLdap不起作用了。有没有人知道或有解决方案从OpenLdap获取这些密码属性?

祝你好运

1 个答案:

答案 0 :(得分:-2)

  

&#34;密码&#34;很可能是真实密码的哈希值或加密版本。

来源:How to retrieve LDAP password via JNDI

另见http://bethecoder.com/applications/tutorials/java/ldap/how-to-query-password-attribute-of-ldap-entry.html