CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-com-unboundid--unboundid-ldapsdk

Comprehensive Java LDAP SDK providing full LDAPv3 protocol support, connection pooling, schema handling, and persistence framework for LDAP directory operations.

Pending
Overview
Eval results
Files

core-operations.mddocs/

Core LDAP Operations

Essential LDAP directory operations including connection management, authentication, and basic CRUD operations for interacting with LDAP directory servers.

Capabilities

Connection Management

LDAPConnection

Primary class for establishing and managing LDAP connections.

/**
 * Primary class for establishing and managing LDAP connections
 */
public final class LDAPConnection implements FullLDAPInterface, LDAPConnectionInfo, ReferralConnector, Closeable {
    // Constructors
    public LDAPConnection() throws LDAPException;
    public LDAPConnection(String host, int port) throws LDAPException;
    public LDAPConnection(String host, int port, SSLSocketFactory socketFactory) throws LDAPException;
    public LDAPConnection(SocketFactory socketFactory, LDAPConnectionOptions connectionOptions, String host, int port) throws LDAPException;
    
    // Connection state
    public boolean isConnected();
    public String getConnectedAddress();
    public int getConnectedPort();
    public LDAPConnectionStatistics getConnectionStatistics();
    public void close();
    public void close(Control[] controls);
}

LDAPConnectionPool

Connection pooling implementation with load balancing and failover capabilities.

/**
 * Connection pooling implementation with load balancing and failover
 */
public final class LDAPConnectionPool extends AbstractConnectionPool {
    // Constructors
    public LDAPConnectionPool(LDAPConnection connection, int initialConnections, int maxConnections) throws LDAPException;
    public LDAPConnectionPool(LDAPConnection connection, int initialConnections, int maxConnections, int initialConnectThreads) throws LDAPException;
    public LDAPConnectionPool(ServerSet serverSet, BindRequest bindRequest, int initialConnections, int maxConnections) throws LDAPException;
    
    // Pool management
    public LDAPConnection getConnection() throws LDAPException;
    public void releaseConnection(LDAPConnection connection);
    public void releaseDefunctConnection(LDAPConnection connection);
    public LDAPConnectionPoolStatistics getConnectionPoolStatistics();
    public int getCurrentAvailableConnections();
    public int getMaximumAvailableConnections();
    public void close();
}

LDAPConnectionOptions

Configuration options for LDAP connections.

/**
 * Configuration options for LDAP connections
 */
public class LDAPConnectionOptions {
    public LDAPConnectionOptions();
    
    // Timeout settings
    public void setConnectTimeoutMillis(int connectTimeoutMillis);
    public int getConnectTimeoutMillis();
    public void setResponseTimeoutMillis(long responseTimeoutMillis);
    public long getResponseTimeoutMillis();
    
    // Connection behavior
    public void setAutoReconnect(boolean autoReconnect);
    public boolean autoReconnect();
    public void setBindWithDNRequiresPassword(boolean bindWithDNRequiresPassword);
    public boolean bindWithDNRequiresPassword();
    
    // SSL/TLS settings
    public void setSSLSocketVerifier(SSLSocketVerifier sslSocketVerifier);
    public SSLSocketVerifier getSSLSocketVerifier();
    
    // Connection pooling
    public void setMaxMessageSize(int maxMessageSize);
    public int getMaxMessageSize();
}

ServerSet Classes

Server selection strategies for connection pooling and high availability configurations.

/**
 * Abstract base class for server selection strategies
 */
public abstract class ServerSet {
    public abstract LDAPConnection getConnection() throws LDAPException;
    public abstract LDAPConnection getConnection(LDAPConnectionPoolHealthCheck healthCheck) throws LDAPException;
    public ServerSet[] getServerSets();
}

/**
 * Single server configuration
 */
public class SingleServerSet extends ServerSet {
    public SingleServerSet(String host, int port);
    public SingleServerSet(String host, int port, SocketFactory socketFactory);
    public SingleServerSet(String host, int port, SocketFactory socketFactory, LDAPConnectionOptions connectionOptions);
    public SingleServerSet(String host, int port, SocketFactory socketFactory, LDAPConnectionOptions connectionOptions, BindRequest bindRequest, PostConnectProcessor postConnectProcessor);
}

/**
 * Round-robin server selection across multiple servers
 */
public class RoundRobinServerSet extends ServerSet {
    public RoundRobinServerSet(String[] hosts, int[] ports);
    public RoundRobinServerSet(String[] hosts, int[] ports, SocketFactory socketFactory);
    public RoundRobinServerSet(String[] hosts, int[] ports, SocketFactory socketFactory, LDAPConnectionOptions connectionOptions);
    public RoundRobinServerSet(String[] hosts, int[] ports, SocketFactory socketFactory, LDAPConnectionOptions connectionOptions, BindRequest bindRequest, PostConnectProcessor postConnectProcessor);
}

/**
 * Failover server selection with primary/backup servers
 */
public class FailoverServerSet extends ServerSet {
    public FailoverServerSet(ServerSet[] serverSets);
    public FailoverServerSet(ServerSet[] serverSets, long maxFailoverConnectionAgeMillis);
    public ServerSet[] getServerSets();
}

/**
 * Connects to the server with the fastest connection time
 */
public class FastestConnectServerSet extends ServerSet {
    public FastestConnectServerSet(String[] hosts, int[] ports);
    public FastestConnectServerSet(String[] hosts, int[] ports, SocketFactory socketFactory);
    public FastestConnectServerSet(String[] hosts, int[] ports, SocketFactory socketFactory, LDAPConnectionOptions connectionOptions);
}

/**
 * Connects to the server with the fewest established connections
 */
public class FewestConnectionsServerSet extends ServerSet {
    public FewestConnectionsServerSet(String[] hosts, int[] ports);
    public FewestConnectionsServerSet(String[] hosts, int[] ports, SocketFactory socketFactory);
    public FewestConnectionsServerSet(String[] hosts, int[] ports, SocketFactory socketFactory, LDAPConnectionOptions connectionOptions);
}

/**
 * Uses DNS SRV records to discover servers
 */
public class DNSSRVRecordServerSet extends ServerSet {
    public DNSSRVRecordServerSet(String serviceName, String providerURL);
    public DNSSRVRecordServerSet(String serviceName, String providerURL, long cacheTimeoutMillis);
    public DNSSRVRecordServerSet(String serviceName, String providerURL, long cacheTimeoutMillis, SocketFactory socketFactory, LDAPConnectionOptions connectionOptions);
}

Basic LDAP Operations

Add Operations

/**
 * Add a new entry to the directory
 * @param entry The entry to add
 * @return Result of the add operation
 * @throws LDAPException if the operation fails
 */
public LDAPResult add(Entry entry) throws LDAPException;

/**
 * Add a new entry to the directory with controls
 * @param addRequest Complete add request with controls
 * @return Result of the add operation
 * @throws LDAPException if the operation fails
 */
public LDAPResult add(AddRequest addRequest) throws LDAPException;

/**
 * Add request for LDAP add operations
 */
public class AddRequest extends UpdatableLDAPRequest {
    public AddRequest(String dn, Attribute... attributes);
    public AddRequest(String dn, Collection<Attribute> attributes);
    public AddRequest(Entry entry);
    
    public String getDN();
    public List<Attribute> getAttributes();
    public void addAttribute(Attribute attribute);
    public void addAttribute(String name, String... values);
}

Search Operations

/**
 * Search for entries in the directory
 * @param baseDN The base DN for the search
 * @param scope The search scope
 * @param filter The search filter
 * @param attributes Attributes to return
 * @return Search results
 * @throws LDAPException if the search fails
 */
public SearchResult search(String baseDN, SearchScope scope, String filter, String... attributes) throws LDAPException;

/**
 * Search with a Filter object
 * @param baseDN The base DN for the search
 * @param scope The search scope
 * @param filter The search filter as Filter object
 * @param attributes Attributes to return
 * @return Search results
 * @throws LDAPException if the search fails
 */
public SearchResult search(String baseDN, SearchScope scope, Filter filter, String... attributes) throws LDAPException;

/**
 * Search with full request object
 * @param searchRequest Complete search request
 * @return Search results
 * @throws LDAPException if the search fails
 */
public SearchResult search(SearchRequest searchRequest) throws LDAPException;

/**
 * Search scope enumeration
 */
public enum SearchScope {
    BASE(0),
    ONE(1), 
    SUB(2),
    SUBORDINATE_SUBTREE(3);
}

Modify Operations

/**
 * Modify an existing entry
 * @param dn The DN of the entry to modify
 * @param modifications The modifications to apply
 * @return Result of the modify operation
 * @throws LDAPException if the operation fails
 */
public LDAPResult modify(String dn, Modification... modifications) throws LDAPException;

/**
 * Modify with full request object
 * @param modifyRequest Complete modify request
 * @return Result of the modify operation
 * @throws LDAPException if the operation fails
 */
public LDAPResult modify(ModifyRequest modifyRequest) throws LDAPException;

/**
 * Represents a modification to an LDAP entry
 */
public class Modification {
    public Modification(ModificationType modificationType, String attributeName, String... values);
    public Modification(ModificationType modificationType, Attribute attribute);
    
    public ModificationType getModificationType();
    public String getAttributeName();
    public String[] getValues();
}

/**
 * Types of modifications
 */
public enum ModificationType {
    ADD(0),
    DELETE(1),
    REPLACE(2),
    INCREMENT(3);
}

Delete Operations

/**
 * Delete an entry from the directory
 * @param dn The DN of the entry to delete
 * @return Result of the delete operation
 * @throws LDAPException if the operation fails
 */
public LDAPResult delete(String dn) throws LDAPException;

/**
 * Delete with full request object
 * @param deleteRequest Complete delete request
 * @return Result of the delete operation
 * @throws LDAPException if the operation fails
 */
public LDAPResult delete(DeleteRequest deleteRequest) throws LDAPException;

/**
 * Delete request for LDAP delete operations
 */
public class DeleteRequest extends UpdatableLDAPRequest {
    public DeleteRequest(String dn);
    
    public String getDN();
}

Compare Operations

/**
 * Compare an attribute value against an entry
 * @param dn The DN of the entry
 * @param attributeName The attribute name
 * @param assertionValue The value to compare
 * @return Compare result
 * @throws LDAPException if the operation fails
 */
public CompareResult compare(String dn, String attributeName, String assertionValue) throws LDAPException;

/**
 * Compare with full request object
 * @param compareRequest Complete compare request
 * @return Compare result
 * @throws LDAPException if the operation fails
 */
public CompareResult compare(CompareRequest compareRequest) throws LDAPException;

/**
 * Result of a compare operation
 */
public class CompareResult extends LDAPResult {
    public boolean compareMatched();
}

Modify DN Operations

/**
 * Modify the DN of an entry (rename/move)
 * @param dn Current DN of the entry
 * @param newRDN New relative DN
 * @param deleteOldRDN Whether to delete the old RDN
 * @return Result of the modify DN operation
 * @throws LDAPException if the operation fails
 */
public LDAPResult modifyDN(String dn, String newRDN, boolean deleteOldRDN) throws LDAPException;

/**
 * Modify DN with new superior
 * @param dn Current DN of the entry
 * @param newRDN New relative DN
 * @param deleteOldRDN Whether to delete the old RDN
 * @param newSuperiorDN New parent DN
 * @return Result of the modify DN operation
 * @throws LDAPException if the operation fails
 */
public LDAPResult modifyDN(String dn, String newRDN, boolean deleteOldRDN, String newSuperiorDN) throws LDAPException;

Result Processing

LDAPResult

/**
 * Generic result for LDAP operations
 */
public class LDAPResult {
    public int getMessageID();
    public ResultCode getResultCode();
    public String getDiagnosticMessage();
    public String getMatchedDN();
    public String[] getReferralURLs();
    public Control[] getResponseControls();
    public boolean hasResponseControl(String oid);
    public <T extends Control> T getResponseControl(Class<T> controlClass);
}

/**
 * LDAP result codes
 */
public enum ResultCode {
    SUCCESS(0),
    OPERATIONS_ERROR(1),
    PROTOCOL_ERROR(2),
    TIME_LIMIT_EXCEEDED(3),
    SIZE_LIMIT_EXCEEDED(4),
    COMPARE_FALSE(5),
    COMPARE_TRUE(6),
    AUTH_METHOD_NOT_SUPPORTED(7),
    STRONG_AUTH_REQUIRED(8),
    REFERRAL(10),
    ADMIN_LIMIT_EXCEEDED(11),
    UNAVAILABLE_CRITICAL_EXTENSION(12),
    CONFIDENTIALITY_REQUIRED(13),
    SASL_BIND_IN_PROGRESS(14),
    NO_SUCH_ATTRIBUTE(16),
    UNDEFINED_ATTRIBUTE_TYPE(17),
    INAPPROPRIATE_MATCHING(18),
    CONSTRAINT_VIOLATION(19),
    ATTRIBUTE_OR_VALUE_EXISTS(20),
    INVALID_ATTRIBUTE_SYNTAX(21),
    NO_SUCH_OBJECT(32),
    ALIAS_PROBLEM(33),
    INVALID_DN_SYNTAX(34),
    ALIAS_DEREFERENCING_PROBLEM(36),
    INAPPROPRIATE_AUTHENTICATION(48),
    INVALID_CREDENTIALS(49),
    INSUFFICIENT_ACCESS_RIGHTS(50),
    BUSY(51),
    UNAVAILABLE(52),
    UNWILLING_TO_PERFORM(53),
    LOOP_DETECT(54),
    NAMING_VIOLATION(64),
    OBJECT_CLASS_VIOLATION(65),
    NOT_ALLOWED_ON_NONLEAF(66),
    NOT_ALLOWED_ON_RDN(67),
    ENTRY_ALREADY_EXISTS(68),
    OBJECT_CLASS_MODS_PROHIBITED(69),
    AFFECTS_MULTIPLE_DSAS(71),
    OTHER(80);
}

SearchResult

/**
 * Result of a search operation
 */
public class SearchResult extends LDAPResult {
    public List<SearchResultEntry> getSearchEntries();
    public List<SearchResultReference> getSearchReferences();
    public int getEntryCount();
    public int getReferenceCount();
}

/**
 * Individual entry from search results
 */
public class SearchResultEntry extends Entry {
    public SearchResultEntry(String dn, Attribute... attributes);
    public SearchResultEntry(String dn, Collection<Attribute> attributes);
    public Control[] getControls();
    public boolean hasControl(String oid);
}

Asynchronous Operations

/**
 * Asynchronous request ID for tracking operations
 */
public class AsyncRequestID {
    public int getMessageID();
    public OperationType getOperationType();
}

/**
 * Asynchronous search operations
 * @param searchRequest The search request
 * @param resultListener Listener for handling results
 * @return Request ID for tracking
 * @throws LDAPException if the operation fails
 */
public AsyncRequestID asyncSearch(SearchRequest searchRequest, AsyncSearchResultListener resultListener) throws LDAPException;

/**
 * Listener interface for asynchronous search results
 */
public interface AsyncSearchResultListener extends AsyncResultListener {
    void searchEntryReturned(SearchResultEntry entry);
    void searchReferenceReturned(SearchResultReference reference);
    void searchResultReceived(AsyncRequestID requestID, SearchResult result);
}

Usage Examples

Basic Connection and Search

import com.unboundid.ldap.sdk.*;

// Establish connection
LDAPConnection connection = new LDAPConnection("ldap.example.com", 389);

try {
    // Simple bind
    BindResult bindResult = connection.bind("cn=admin,dc=example,dc=com", "password");
    
    // Search for users
    SearchResult searchResult = connection.search(
        "ou=people,dc=example,dc=com",     // base DN
        SearchScope.ONE,                   // scope
        "(objectClass=inetOrgPerson)",     // filter
        "cn", "mail", "telephoneNumber"    // attributes
    );
    
    System.out.println("Found " + searchResult.getEntryCount() + " entries");
    
    for (SearchResultEntry entry : searchResult.getSearchEntries()) {
        System.out.println("DN: " + entry.getDN());
        System.out.println("CN: " + entry.getAttributeValue("cn"));
        System.out.println("Mail: " + entry.getAttributeValue("mail"));
        System.out.println("Phone: " + entry.getAttributeValue("telephoneNumber"));
        System.out.println("---");
    }
    
} finally {
    connection.close();
}

Connection Pool Usage

import com.unboundid.ldap.sdk.*;

// Create initial connection
LDAPConnection connection = new LDAPConnection("ldap.example.com", 389);
connection.bind("cn=admin,dc=example,dc=com", "password");

// Create connection pool
LDAPConnectionPool pool = new LDAPConnectionPool(connection, 5, 10);

try {
    // Use pool for operations
    SearchResult result = pool.search(
        "dc=example,dc=com",
        SearchScope.SUB,
        "(cn=John*)"
    );
    
    // Pool automatically manages connections
    System.out.println("Available connections: " + pool.getCurrentAvailableConnections());
    
} finally {
    pool.close();
}

Adding Entries

import com.unboundid.ldap.sdk.*;

LDAPConnection connection = new LDAPConnection("ldap.example.com", 389);

try {
    connection.bind("cn=admin,dc=example,dc=com", "password");
    
    // Create new entry
    Entry newEntry = new Entry(
        "cn=Jane Smith,ou=people,dc=example,dc=com",
        new Attribute("objectClass", "inetOrgPerson"),
        new Attribute("cn", "Jane Smith"),
        new Attribute("sn", "Smith"),
        new Attribute("givenName", "Jane"),
        new Attribute("mail", "jane.smith@example.com"),
        new Attribute("telephoneNumber", "+1-555-0123")
    );
    
    // Add entry
    LDAPResult addResult = connection.add(newEntry);
    
    if (addResult.getResultCode() == ResultCode.SUCCESS) {
        System.out.println("Entry added successfully");
    } else {
        System.err.println("Add failed: " + addResult.getDiagnosticMessage());
    }
    
} catch (LDAPException e) {
    System.err.println("LDAP operation failed: " + e.getMessage());
    System.err.println("Result code: " + e.getResultCode());
} finally {
    connection.close();
}

Modifying Entries

import com.unboundid.ldap.sdk.*;

LDAPConnection connection = new LDAPConnection("ldap.example.com", 389);

try {
    connection.bind("cn=admin,dc=example,dc=com", "password");
    
    // Create modifications
    Modification[] mods = {
        new Modification(ModificationType.REPLACE, "mail", "jane.doe@example.com"),
        new Modification(ModificationType.ADD, "description", "Software Engineer"),
        new Modification(ModificationType.DELETE, "telephoneNumber", "+1-555-0123")
    };
    
    // Apply modifications
    LDAPResult modifyResult = connection.modify("cn=Jane Smith,ou=people,dc=example,dc=com", mods);
    
    if (modifyResult.getResultCode() == ResultCode.SUCCESS) {
        System.out.println("Entry modified successfully");
    }
    
} finally {
    connection.close();
}

Install with Tessl CLI

npx tessl i tessl/maven-com-unboundid--unboundid-ldapsdk

docs

authentication.md

controls-extensions.md

core-operations.md

data-types.md

index.md

ldif.md

persistence.md

schema.md

search.md

tile.json