This content has been marked as final.
Show 3 replies
-
1. Re: How to pull user information from ldap
lcbdl888 Dec 5, 2008 7:22 PM (in response to rogerwbmd)Hi, Please refer to this tutorial: http://java.sun.com/docs/books/tutorial/jndi/ldap/index.html
I have a piece of code that might help you
public List search(String filter, String rootDn) throws RegistryException { List persons = new ArrayList(); LdapContext ctx = null; try { if (StringUtils.isNotEmpty(filter)) { ctx = new InitialLdapContext(getContextEnv(adminDn, adminPassword), null); String[] attrIDs = {"uid", "cn"}; SearchControls ctls = new SearchControls(); ctls.setReturningAttributes(attrIDs); ctls.setSearchScope(SearchControls.SUBTREE_SCOPE); NamingEnumeration results = ctx.search(rootDn, filter, ctls); SearchResult result = null; String dn = null; while (results.hasMore()) { result = (SearchResult) results.next(); dn = result.getName() + "," + rootDn; persons.add(getPersonByDn(dn)); } } } catch (NameNotFoundException e) { if (e.getExplanation().indexOf("LDAP: error code 32 - No Such Object") > -1) { log.debug("No result found searched by filter[" + filter + "]"); } } catch (NamingException e) { StringBuffer msg = new StringBuffer("Failed to search by filter["); msg.append(filter); msg.append("]. "); msg.append(e.getExplanation()); log.error(msg, e); throw new IrrecoverableRegistryException(msg.toString()); } finally { try { if (ctx != null) ctx.close(); } catch(NamingException e) { log.warn("Failed to close LDAP context["+ctx+"]."); } } return persons; }
-
2. Re: How to pull user information from ldap
rogerwbmd Dec 8, 2008 8:37 PM (in response to rogerwbmd)Thanks. I am able to get it done now!
-
3. Re: How to pull user information from ldap
eduardoyc Dec 9, 2008 9:14 PM (in response to rogerwbmd)Hi Roger,
Can you share the source-code that you wrote to authenticate against the ldap?
Thanks,
Eduardo