LDAP library for Java.

Ldaptive is a simple, extensible Java API for interacting with LDAP servers. It was designed to provide easy LDAP integration for application developers.

Features

Quick Start Guide

Searching

SearchOperation search = new SearchOperation(
  new DefaultConnectionFactory("ldap://directory.ldaptive.org"), "dc=ldaptive,dc=org");
SearchResponse response = search.execute("(uid=dfisher)");
LdapEntry entry = response.getEntry();
// do something useful with the entry

StartTLS

SearchOperation search = new SearchOperation(
  DefaultConnectionFactory.builder()
    .config(ConnectionConfig.builder()
      .url("ldap://directory.ldaptive.org")
      .useStartTLS(true)
      .build())
    .build(),
    "dc=ldaptive,dc=org");
SearchResponse response = search.execute("(uid=*fisher)", "mail", "sn");
for (LdapEntry entry : response.getEntries()) {
  // do something useful with the entry
}

Binding

SearchOperation search = new SearchOperation(
  DefaultConnectionFactory.builder()
    .config(ConnectionConfig.builder()
      .url("ldap://directory.ldaptive.org")
      .useStartTLS(true)
      .connectionInitializers(BindConnectionInitializer.builder()
        .dn("cn=manager,ou=people,dc=ldaptive,dc=org")
        .credential("manager_password")
        .build())
      .build())
    .build(),
  "dc=ldaptive,dc=org");
SearchResponse response = search.execute("(uid=*fisher)", "mail", "sn");
for (LdapEntry entry : response.getEntries()) {
  // do something useful with the entry
}

These search examples all leverage the SearchOperation class. For more details on searching and more control over the search operation in general, see the search operation documentation.

Authentication

ConnectionConfig connConfig = ConnectionConfig.builder()
  .url("ldap://directory.ldaptive.org")
  .useStartTLS(true)
  .build();

SearchDnResolver dnResolver = SearchDnResolver.builder()
  .factory(new DefaultConnectionFactory(connConfig))
  .dn("ou=people,dc=ldaptive,dc=org")
  .filter("uid={user}")
  .build();

SimpleBindAuthenticationHandler authHandler = new SimpleBindAuthenticationHandler(new DefaultConnectionFactory(connConfig));
Authenticator auth = new Authenticator(dnResolver, authHandler);
AuthenticationResponse response = auth.authenticate(new AuthenticationRequest("dfisher", new Credential("password")));
if (response.isSuccess()) {
  // authentication succeeded
} else {
  // authentication failed
}

For more details on authentication, see the authentication documentation.

What changed between v1 and v2?

v1 docs are still available.