Skip to content

Declare each LDAP mapper attribute once in the user profile - #55187

Open
kevinveenbirkenbach wants to merge 1 commit into
keycloak:mainfrom
kevinveenbirkenbach:fix/ldap-dedupe-user-profile-attributes
Open

kevinveenbirkenbach wants to merge 1 commit into
keycloak:mainfrom
kevinveenbirkenbach:fix/ldap-dedupe-user-profile-attributes

Conversation

@kevinveenbirkenbach

Copy link
Copy Markdown

Closes #55185

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 (which supports only email), LDAPStorageProvider.decorateUserProfile built one metadata entry per declaration. DefaultAttributes.getUserStorageProviderMetadata then failed in Collectors.toMap with IllegalStateException: Duplicate key firstName, and the UPDATE_EMAIL required 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.createAttributeMetadata skips those names as before.

The same collector failed for Kerberos in #31957.

Tests: LDAPProvidersFullNameMapperTest gets testUpdateEmailProfileOfUserWhoseNameIsDeclaredByTwoMappers. The class fixture already pairs the full name mapper with the last name mapper, so the case creates the UPDATE_EMAIL user profile of an LDAP user and asserts the email and lastName metadata.

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_EMAIL is disabled for LDAP realms as a workaround.

🤖 Generated with Claude Code

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>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

UPDATE_EMAIL fails with "Duplicate key firstName" when the full-name LDAP mapper overlaps the first and last name mappers

2 participants