@@ -0,0 +1,1742 @@
+package gov.nih.nci.camod.util;%0A%0Aimport java.util.Hashtable;%0A%0Aimport javax.naming.Context;%0Aimport javax.naming.NamingEnumeration;%0Aimport javax.naming.directory.DirContext;%0Aimport javax.naming.directory.InitialDirContext;%0Aimport javax.naming.directory.SearchControls;%0Aimport javax.naming.directory.SearchResult;%0A%0Apublic class LDAPTest %7B%0A%0A%09/**%0A%09 * @param args%0A%09 */%0A%09public static void main(String%5B%5D args) %7B%0A%09%09// TODO Auto-generated method stub%0A%09%09String%5B%5D attributeIDs = %7B %22cn%22, %22%22 %7D;%0A%09%09String searchFilter = %22(%22 + %22cn%22 + %22=%22 + %22georgeda%22 + %22*)%22;%0A%0A%09%09try %7B%0A%09%09%09Hashtable environment = new Hashtable();%0A%09%09%09environment.clear();%0A%09%09%09environment.put(Context.INITIAL_CONTEXT_FACTORY, %22com.sun.jndi.ldap.LdapCtxFactory%22);%0A%09%09%09environment.put(Context.PROVIDER_URL, %22ldaps://ncids2b.nci.nih.gov:636%22);%0A%09%09%09environment.put(Context.SECURITY_AUTHENTICATION, %22simple%22);%0A%09%09%09environment.put(Context.SECURITY_PROTOCOL, %22ssl%22);%0A%09%09%09DirContext dirContext = new InitialDirContext(environment);%0A%0A%09%09%09SearchControls searchControls = new SearchControls();%0A%09%09%09searchControls.setReturningAttributes(null);%0A%09%09%09searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE);%0A%0A%09%09%09String fullyDistinguishedName = null;%0A%09%09%09NamingEnumeration searchEnum = dirContext.search(%0A%09%09%09%09%09%22ou=nci,o=nih%22,%0A%09%09%09%09%09searchFilter, searchControls);%0A%09%09%09dirContext.close();%0A%0A%09%09%09while (searchEnum.hasMore()) %7B%0A%09%09%09%09SearchResult searchResult = (SearchResult) searchEnum.next();%0A%09%09%09%09fullyDistinguishedName = searchResult.getName()%09+ %22,%22 + %22ou=nci,o=nih%22;%0A%09%09%09%09System.out.println(%22fullyDistinguishedName=%22 + fullyDistinguishedName);%0A%09%09%09%09System.out.println(%22Attributes=%22 + searchResult.getAttributes());%0A%09%09%09%7D%0A%09%09%7D catch (Exception ex) %7B%0A%09%09%09throw new RuntimeException( %22User Name doesnot exists%22 ,ex);%0A%09%09%7D%0A%0A%09%7D%0A%0A%7D%0A

test utility for connecting to LDAP