Microsoft AD, JNDI and LDAP
Hello,
I working to move an application off of Novell eDirectory onto Microsoft AD. The program successfully binds to AD, the search filter executes correctly and the attributes are returned as expected. However, the final call to searchResults.hasMore() is not returning! In other words, the final call, which should return false, is not returning at all.
Any ideas?
-Bryan
try
{
hashtable = null;
hashtable = new Hashtable();
hashtable.put("java.naming.ldap.version", "3");
hashtable.put Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
hashtable.put(Context.SECURITY_AUTHENTICATION, "Simple");
hashtable.put(Context.REFERRAL, "follow");
hashtable.put(Context.PROVIDER_URL, url);
hashtable.put(Context.SECURITY_PRINCIPAL, loginDN);
hashtable.put(Context.SECURITY_CREDENTIALS, passwd);
ctx = new InitialLdapContext(hashtable, null);
SearchControls sc = new SearchControls();
sc.setSearchScope(SearchControls.SUBTREE_SCOPE);
sc.setReturningAttributes(new String[] {"mailNickname", "givenName", "sn", "mail"});
NamingEnumeration results = ctx.search(base, filter, sc);
cns = new ArrayList(25);
givenNames = new ArrayList(25);
mails = new ArrayList(25);
surNames = new ArrayList(25);
while (results.hasMore()) // hangup occurring here when hasMore() should return false
{
SearchResult sr = (SearchResult)results.next();
Attributes attrs = sr.getAttributes();
Enumeration enum = attrs.getAll();
while (enum.hasMoreElements())
System.out.println(enum.nextElement());
cns.add((String)(attrs.get("mailNickname").get()));
givenNames.add((String)(attrs.get("givenName").get()));
surNames.add((String)(attrs.get("sn").get()));
mails.add((String)(attrs.get("mail").get()));
}
}
finally
{
try {ctx.close();}
catch (Exception e) {}
}

