我想从使用java检索LDAP的PwdLastSet属性。它失败并且不会抛出错误。下面的代码:获取ldap属性PwdLastSet使用java
private String getPasswordLastSet() {
int searchScope = LDAPConnection.SCOPE_BASE;
int ldapVersion = LDAPConnection.LDAP_V3;
int ldapPort = 389;
String ldapHost = "Adapps.domain.mycompany.com";
String loginDN = "cn=myNTusername,OU=users,OU=colorado,OU=corporate,dc=domain,dc=mycompany,dc=com";
String password = "myNTpassword";
String baseDn = "dc=mycompany,dc=com";
LDAPConnection lc = new LDAPConnection();
String attributes[] = {"PwdLastSet"};
String pwdLastSet = null;
try {
lc.connect(ldapHost, ldapPort);
lc.bind(ldapVersion, loginDN, password.getBytes("UTF8"));
String filter = "(sAMAccountName=myNtusername)";
LDAPSearchResults searchResults =
lc.search( baseDn,
searchScope,
filter,
attributes,
true); // return attributes and values
while (searchResults.hasMore()) {
LDAPEntry nextEntry = null;
try {
actionlogger.debug("about to searchResults.next...");
nextEntry = searchResults.next();
actionlogger.debug("about to nextEntry.getAttribute...");
LDAPAttribute pwdLastSetAttribute = nextEntry.getAttribute("PwdLastSet");
pwdLastSet = pwdLastSetAttribute.getStringValue();
} catch(LDAPException e) {
e.printStackTrace();
} catch(Exception e){
e.printStackTrace();
}
}
} catch(LDAPException e) {
actionlogger.error("Error occured while LDAP Search : " + e.getMessage(),e);
} catch (Exception e) {
e.printStackTrace();
}
return pwdLastSet;
}
输出是
即将searchResults.next ...
但
即将nextEntry.getAttribute ...
从未被击中。有任何想法吗?
2016-07-08
tekknow
+0
您正在使用哪种Java LDAP API?您应该检查您是否在nextEntry处收到了LDAPEntry?记录条目的DN,以便知道哪个条目。另外,您确定条目上有一个pwdLastSet值吗? –
+0
com.novell.ldap - 是的,我知道有一个PwdLastSet属性,因为我可以从linux命令行运行ldapSearch并可以看到它。 –