How to Connect OpenLDAP to Keycloak

If you’re running your own OpenLDAP server and using Keycloak for identity and access management, you can integrate them so that Keycloak reads user data directly from LDAP. This guide shows you how to connect OpenLDAP to Keycloak via the User Federation feature.


Prerequisites

Ensure the following setup is in place:

  • Keycloak Admin Console: https://keycloak.maksonlee.com/admin
  • ✅ Realm created: maksonlee.com
  • OpenLDAP over LDAPS: ldaps://ldap.maksonlee.com:636
  • ✅ LDAP admin DN: cn=admin,dc=maksonlee,dc=com
  • ✅ LDAP base DN: ou=people,dc=maksonlee,dc=com
  • ✅ LDAP filters users using employeeType=active
  • ✅ SMTP configured in Realm Settings → Email

  1. Log into Keycloak
  • Open https://keycloak.maksonlee.com/admin
  • Log in with an admin account
  • Select the realm maksonlee.com

  1. Add LDAP Provider
  • Navigate to User Federation
  • Click Add LDAP provider
  • Fill in the configuration using the table below
SectionSettingValue
General OptionsDisplay NameOpenLDAP
VendorOther
Connection and AuthenticationConnection URLldaps://ldap.maksonlee.com:636
Enable StartTLS❌ Off
Use Truststore SPI✅ Always
Connection Pooling✅ On
Bind Typesimple
Bind DNcn=admin,dc=maksonlee,dc=com
Bind Credentials(LDAP admin password)
LDAP Searching and UpdatingEdit ModeWRITABLE
Users DNou=people,dc=maksonlee,dc=com
User LDAP Filter(employeeType=active)
Username LDAP Attributeuid
RDN LDAP Attributeuid
UUID LDAP AttributeentryUUID
User Object ClassesinetOrgPerson, organizationalPerson
Search ScopeSubtree
Pagination✅ On
Referralignore
SynchronizationImport Users✅ On
Sync Registrations❌ Off
Remove Invalid Users During Searches✅ On
Periodic Full Sync❌ Off
Periodic Changed Users Sync❌ Off
Advanced SettingsLDAPv3 Password Modify Extension✅ On
Validate Password Policy❌ Off
Trust Email✅ On

  1. Save and Sync
  • Click Test Connection
  • Click Test Authentication
  • Click Save

Users with employeeType=active will be imported.
To sync manually later: go to User Federation → OpenLDAP → Synchronize all users.


  1. Prevent Profile Edits (Email, Name, Username)

A. Set LDAP Mappers to Read-Only

  • Go to User Federation → OpenLDAP → Mappers
  • Update these mappers:
MapperLDAP AttributeRead-OnlyAlways Read
emailmail
first namegivenName
last namesn
usernameuid

B. Lock Fields in User Profile

  • Navigate to Realm Settings → User Profile in the Keycloak Admin Console
  • In the Attributes section, locate the attribute you want to lock:
    email
    firstName
    lastName
    usernam
  • Click Edit for each one
  • Under Permissions → Who can edit?:
    Uncheck “User”
    ✅ Keep “Admin” checked
  • Click Save

  1. Enable Self-Service Password Reset

To allow users to reset their LDAP password:

  • Go to Realm Settings → Login
  • Enable:
    Forgot Password

With SMTP configured and LDAPv3 Password Modify enabled, users will receive a reset link and update their password directly in LDAP via Keycloak.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top