Custom Keycloak LDAP mapper that adds imported LDAP users to a Keycloak group when email regex and LDAP attributes regex match.
| Mapper Version | Supported Keycloak Version | Status |
|---|---|---|
v1.0.0 |
26.4.5 |
Supported |
- Runs during LDAP user import/sync (
onImportUserFromLDAP). - Can skip disabled users (configurable with
Skip Disabled Users, defaulttrue). - Checks email first using a configured LDAP/AD email attribute key and regex.
- Builds a normalized payload of LDAP attributes in
attribute=valuelines. - Evaluates one regex against that payload (case-sensitive or case-insensitive).
- Adds the user to the configured Keycloak group path only if both checks match.
mvn clean packageThe output jar is created at:
target/keycloak-conditional-mapper-<semantic-version>.jar
- Copy the jar to your Keycloak providers directory:
- Container:
/opt/keycloak/providers/ - Local distribution:
<keycloak-home>/providers/
- Container:
- Rebuild Keycloak:
bin/kc.sh build
- Start Keycloak:
bin/kc.sh start
In your LDAP user federation provider, add this mapper and set:
Email Attribute Key: email attribute key (example:mailoruserPrincipalName).Email Regex: regex to filter users by email (example:.*@gmail\.com).LDAP Attributes Regex: regex evaluated against all LDAP attributes inattribute=valuelines.Keycloak Group Path: target group path (example:/employees/engineering).Case-Insensitive Match:trueorfalse.Skip Disabled Users:trueorfalse(defaulttrue).
keycloak-conditional-mapper