Spring Example - October - 2009 //Spring public LdapUser findUser1(String uniqueName, String password) throws BadPasswordException, InvalidUserException { SearchControls searchControls = new SearchControls(); searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE); //set dereference aliases searchControls.setDerefLinkFlag(false); // define return attributes String[] returnedAttributes = { "uid", "sn", "givenName", "groupMembership",”entryDN” }; searchControls.setReturningAttributes(returnedAttributes); DnContextMapper contextMapper = new DnContextMapper(); String filterString = "uid=" + uniqueName; // set search base List results = ldapTemplate.search("dc=med,dc=umich,dc=edu", filterString, searchControls, contextMapper, new SortControlDirContextProcessor("uid")); if (results.size() != 1) { throw new InvalidUserException("Invalid user."); } DirContext dirContext = null; try { dirContext = contextSource.getContext(results.get(0), password); Attributes attribs = dirContext.getAttributes(contextMapper .getNamespace()); String entryDN = (String) attribs.get("entryDN").get(); ………………… } catch (Exception e) { throw new BadPasswordException("Invalid password."); } finally { LdapUtils.closeContext(dirContext); } …………………. }