Bind Operation

Authenticates to the LDAP and if successful, changes the authentication context of the connection. Further LDAP operations will be performed as the authenticated principal. Typically it’s desirable to configure bind properties for all connections rather than on a connection-by-connection basis. The ConnectionConfig object contains properties such that the appropriate bind operation is automatically performed when a connection is opened. See the connection documentation. If you need to support changing the authenticated principal after a connection has been opened, the following operations are available:

Simple Bind

Connection conn = DefaultConnectionFactory.getConnection("ldap://directory.ldaptive.org");
try {
  conn.open();
  BindOperation bind = new BindOperation(conn);
  bind.execute(new BindRequest("uid=dfisher,ou=people,dc=ldaptive,dc=org", new Credential("password")));
  // perform another operation as this principal
} finally {
  conn.close();
}

To perform an anonymous bind, execute a bind operation with an empty bind request.

SASL Bind

The following SASL mechanisms are supported:

Note that the default JNDI provider supports all these mechanisms, but others may not. UnsupportedOperationException will be thrown by providers if a SASL mechanism is attempted but not supported.

Connection conn = DefaultConnectionFactory.getConnection("ldap://directory.ldaptive.org");
try {
  conn.open();
  BindOperation bind = new BindOperation(conn);
  bind.execute(new BindRequest("dfisher@ldaptive.org", new Credential("password"), new DigestMd5Config()));
  // perform another operation as this principal
} finally {
  conn.close();
}