JAVA: Connecting to Tivoli Directory Server (TDS)
A totally unpolished piece of code, but a working one:) Just put it out there as an example for other people trying to accomplish this. This is also able to retrieve Password Policy attributes from TDS (if a Password Policy was defined).
public class LdapTest {
public static void main(String[] args) throws NamingException {
// Create your search string
String userId = "mytestuser";
String INITIAL_ENTRY = "uid" + "=" + userId +
",cn=" + "users" +
"," + "dc=ibm,dc=com";
String pwdChangedTime = "";
InitialLdapContext ctx = null;
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "ldap://myhostname.com:389");
env.put(Context.SECURITY_PRINCIPAL, "cn=root");
env.put(Context.SECURITY_CREDENTIALS, "rootpassword");
env.put("java.naming.ldap.version", "3");
ctx = new InitialLdapContext(env, null);
Attribute attr = null;
// Set up Search Controls
SearchControls sc = new SearchControls();
sc.setSearchScope(SearchControls.OBJECT_SCOPE);
String[] userAttrList = {"sn", "cn", "pwdChangedTime", "pwdAccountLockedTime", "pwdFailureTime", "ibm-pwdIndividualPolicyDN"};
sc.setReturningAttributes(userAttrList);
NamingEnumeration ne = ctx.search(INITIAL_ENTRY,"(objectclass=*)", sc);
while(ne.hasMore()){
SearchResult searchresult = (SearchResult) ne.next();
Attributes attrs = searchresult.getAttributes();
NamingEnumeration ae = attrs.getAll();
while (ae.hasMore()) {
System.out.println(ae.nextElement());
}
}
}
}
Comments
Post a Comment