I am trying to use JLDAP to perform a search of an ActiveDirectory tree. I
need to bind to the tree to perform the search so I am using a known DN and
pwd to do my initial bind.

When I perform my search I get a LDAPReferralException. I implemented a
LDAPBindHandler to handle the bind to the referral url. The code is
similar to the BindImpl in the SerachUtils example:

When the bind() method of the handle is invoked, it successfully connects
to the new server then binds with the credentials that I used to bind to
the original LDAP server. The new connection is then returned as normal.

However, when I call sr.next(); to get the next element of my search result
I get an exception saying that I need to bind to perform this operation:

LDAPException: Operations Error (1) Operations Error
LDAPException: Server Message: 00000000: LdapErr: DSID-0C090627, comment:
In ord
er to perform this operation a successful bind must be completed on the
on., data 0, vece
LDAPException: Matched DN:

Here is how I define my search constraints and perform my search:

LDAPSearchConstraints cons = new LDAPSearchConstraints(20000, // client
// timeout
20000, // server timeout
LDAPSearchConstraints.DEREF_SEARCHING, // alias dereference
100, // max search results
true, // referral following
1000, // results batch size
new BindImpl(initialDN,initialCred), // referral handler
10); //ReferralHopLimit

// if connection has been dropped, reconnect
if (!lc.isConnected())
lc.connect(LDAPServer, LDAPPort);

//Bind with know users
lc.bind(3,initialDN,initialCred.getBytes("UTF8"),c ons);
LDAPEntry le = null;

LDAPSearchResults sr = lc.search(searchBase,
LDAPConnection.SCOPE_SUB, filter,
new String[] { hrAttribute }, false);
if (!sr.hasMore())
System.out.println("Result has no elements");
error = "Invalid user ID: " + userIDTest;
return false;

le = sr.next();
//This is where I am now getting my error, even though I have already bound
to both servers.

One strange thing that I have noticed is that the referral server that I am
getting sent is a DNS name that points to the same IP address of the LDAP
server that I have already connected to.

Any help is greatly appreciated.