Repository navigation
Declare each LDAP mapper attribute once in the user profile - #55187
Open
kevinveenbirkenbach wants to merge 1 commit into
Open
kevinveenbirkenbach wants to merge 1 commit into
kevinveenbirkenbach wants to merge 1 commit into
Conversation
Two LDAP mappers of one provider may declare the same user attribute: FullNameLDAPStorageMapper always declares firstName and lastName, so it overlaps the first name and last name user attribute mappers. In a user profile context that does not define those attributes, such as UPDATE_EMAIL, decorateUserProfile built one metadata entry per declaration, and DefaultAttributes.getUserStorageProviderMetadata failed in Collectors.toMap with 'Duplicate key firstName', so the UPDATE_EMAIL required action answered HTTP 500 for LDAP users. Deduplicate the attribute names before the metadata is built. Closes keycloak#55185 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Kevin Veen-Birkenbach <kevin@veen.world>
1 of 2 tasks
kevinveenbirkenbach
marked this pull request as ready for review
November 14, 2026 12:48
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
There are no active review issues for the change that deduplicates LDAP mapper attribute names.
No open issues 🎉
What changed in this PR
Fixes #55185 by deduplicating LDAP mapper attribute names before creating user-profile metadata. This prevents overlapping name mappers from causing duplicate-key errors during UPDATE_EMAIL profile creation.
Changes:
- Adds
.distinct()to mapper-declared attribute names while preserving existing profile definitions. - Adds regression coverage for overlapping full-name and last-name mappers, asserting that email and last-name metadata are available.
| File | Description |
|---|---|
testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/federation/ldap/LDAPProvidersFullNameMapperTest.java |
Adds an UPDATE_EMAIL regression test for overlapping mapper declarations. |
federation/ldap/src/main/java/org/keycloak/storage/ldap/LDAPStorageProvider.java |
Deduplicates attribute names before building metadata. |
Review effort: Balanced
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #55185
Two LDAP mappers of one provider may declare the same user attribute.
FullNameLDAPStorageMapperalways declaresfirstNameandlastName, so it overlaps thefirst nameandlast nameuser attribute mappers. In a user profile context that does not define those attributes, such asUPDATE_EMAIL(which supports onlyemail),LDAPStorageProvider.decorateUserProfilebuilt one metadata entry per declaration.DefaultAttributes.getUserStorageProviderMetadatathen failed inCollectors.toMapwithIllegalStateException: Duplicate key firstName, and theUPDATE_EMAILrequired action answered HTTP 500 for every LDAP user.The change deduplicates the attribute names before the metadata is built, so a name declared by several mappers yields one entry. Contexts that already define the attribute are unaffected, because
UserProfileUtil.createAttributeMetadataskips those names as before.The same collector failed for Kerberos in #31957.
Tests:
LDAPProvidersFullNameMapperTestgetstestUpdateEmailProfileOfUserWhoseNameIsDeclaredByTwoMappers. The class fixture already pairs thefull namemapper with thelast namemapper, so the case creates theUPDATE_EMAILuser profile of an LDAP user and asserts theemailandlastNamemetadata.I have not built Keycloak or run the testsuite locally; this PR is a draft until CI has run the new case. On 26.8.2 the failure reproduces in a live deployment with the mapper setup from the issue; there,
UPDATE_EMAILis disabled for LDAP realms as a workaround.🤖 Generated with Claude Code