我正在编写一个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获取这些密码属性?
祝你好运