Referrals

An LDAP server can include a referral result code for all operations. (Except Unbind and Abandon.) Ldaptive provides an interface called ReferralHandler to allow users to manage referrals however they like. If no referral handler is provided and a referral result code is received, the referral URL(s) can be inspected at Response.getReferralURLs().

The referral handler interface looks like:

public interface ReferralHandler<Q extends Request, S> extends Handler<Q, Response<S>>
{
  @Override
  HandlerResult<Response<S>> handle(Connection conn, Q request, Response<S> response)
    throws LdapException;

  void initializeRequest(Q request);
}

The most common use case for referrals is for searching. If you wish to follow referrals, Ldaptive provides an implementation called SearchReferralHandler for this purpose. This implementation will also follow search references.

Connection conn = DefaultConnectionFactory.getConnection("ldap://directory.ldaptive.org");
SearchRequest request = new SearchRequest("dc=ldaptive,dc=org", "(&(givenName=daniel)(sn=fisher))");
request.setReferralHandler(new SearchReferralHandler());
try {
  conn.open();
  SearchOperation search = new SearchOperation(conn);
  // referrals will be followed to build the response
  SearchResult result = search.execute(request).getResult();
  for (LdapEntry entry : result.getEntries()) {
    // do something useful with the entry
  }

} finally {
  conn.close();
}

Handlers are also provided for Add, Compare, Delete, ModifyDn and Modify operations.