I list users from LDAP with the following code:
Hashtable<String, String> env = new Hashtable<String, String>();
env.put(Context.INITIAL_CONTEXT_FACTORY, CONTEXT);
env.put(Context.PROVIDER_URL, HOST);
env.put(Context.SECURITY_PRINCIPAL,USER);
env.put(Context.SECURITY_CREDENTIALS,PASSWORD);
DirContext ctx = new InitialDirContext(env);
SearchControls sc = new SearchControls();
sc.setSearchScope(SearchControls.SUBTREE_SCOPE);
NamingEnumeration items = ctx.search(BASE, filter, sc);
while (items != null && items.hasMore()) {
SearchResult sr = (SearchResult)items.next();
System.out.println("SR : " + sr) ;
}
Now I get an output of;
SR : cn=smith: null:null:{objectclass=objectClass: person, sn=sn: smith, cn=cn: smith}
SR : cn=king: null:null:{objectclass=objectClass: person, sn=sn: king, cn=cn: king}
How can I get from SearchControls just the output like:
sn = smith | cn = smith
sn = king | cn = king