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.

Rationale

Developers need LDAP integration for their products, but the JNDI API is cumbersome and takes a great deal of resources to learn and use. In addition, most applications only require a subset of LDAP functionality: search and authentication.

version [2.0.0-RC3] is now available in maven central for testing.

v1 docs are still available.

Note that the JNDI provider is broken in Java versions 9 through 13. If you’re upgrading to Java 11 or greater you should upgrade ldaptive to v1.3.0 and make sure you’re not explicitly using the JNDI provider.

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?