Back to all terms
Authentication
Authintermediate

LDAP Integration

Integration with LDAP directory services to authenticate users and retrieve organizational attributes like groups, departments, and roles from a centralized directory.

Also known as: LDAP, Lightweight Directory Access Protocol, Active Directory Integration, LDAP Authentication

Description

LDAP (Lightweight Directory Access Protocol) is an open protocol for accessing and maintaining distributed directory information services. In the context of authentication, LDAP integration allows applications to authenticate users against a centralized directory (most commonly Microsoft Active Directory) and retrieve user attributes like group memberships, department, manager, and organizational unit. This eliminates the need for application-specific user databases in enterprise environments where a corporate directory already exists.

LDAP authentication typically follows a bind-and-search pattern: the application binds to the LDAP server using a service account (bind DN and password), searches for the user's Distinguished Name (DN) using their username or email in the configured base DN and search filter (e.g., (sAMAccountName={username})), then attempts to bind again using the user's DN and submitted password. If this second bind succeeds, the user is authenticated. Group memberships are then retrieved to map to application roles.

Secure LDAP integration requires LDAPS (LDAP over TLS on port 636) or StartTLS to encrypt all communications, including credentials. The service account should have minimal read-only permissions. Connection pooling is essential for performance, as establishing LDAP connections is expensive. Implement a local cache (with short TTL) for group membership lookups to reduce directory load. Handle LDAP-specific error codes (invalid credentials, account disabled, password expired, account locked) and map them to appropriate application responses. Consider LDAP referral handling for multi-domain forests and failover configuration for high availability.

Prompt Snippet

Implement LDAP authentication using ldapjs (Node.js) or python-ldap. Connect over LDAPS (port 636) with TLS certificate verification. Use a read-only service account to bind and search for the user DN with a filter like (&(objectClass=user)(sAMAccountName={{username}})). Perform a second bind with the user's DN and submitted password to verify credentials. Retrieve group memberships via the memberOf attribute and map LDAP groups to application roles. Implement connection pooling (min: 2, max: 10) and cache group lookups in Redis with 5-minute TTL. Handle LDAP error codes: 49 (invalid credentials), 532 (password expired), 533 (account disabled), 775 (account locked).

Tags

ldapdirectoryactive-directoryenterprisecentralized