8000 Fix read-only username validation for LDAP users by upramod · Pull Request #53514 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content

Fix read-only username validation for LDAP users - #53514

Open
upramod wants to merge 6 commits into
keycloak:mainfrom
upramod:fix/ldap-readonly-username-case-52215
Open

upramod wants to merge 6 commits into
keycloak:mainfrom
upramod:fix/ldap-readonly-username-case-52215

Conversation

@upramod
@upramod upramod commented Oct 5, 2026
Copy link
Copy Markdown

Closes #52215

Problem

When username editing is disabled, UsernameMutationValidator lowercases the submitted username but compares it with the stored username without normalizing the stored value. LDAP-backed users can preserve username casing, so an unchanged username such as LDAP-Case-User submitted as ldap-case-user is treated as a mutation and blocks unrelated profile updates.

Change

Use a case-insensitive comparison when deciding whether the read-only username changed. Real username changes are still rejected.

Test

Added a regression in UserProfileTest that simulates an LDAP-style stored username with preserved case and validates the same username with a case-only difference while username editing is disabled.

Fork validation: upramod#1

@upramod
upramod marked this pull request as ready for review October 5, 2026 03:12
@upramod
upramod requested a review from a team as a code owner October 5, 2026 03:12
Copilot AI balanced review requested due to automatic review settings October 5, 2026 03:12
@upramod
upramod marked this pull request as draft October 5, 2026 03:12
Closes keycloak#52215

Signed-off-by: Pramod Ubbala <16706816+upramod@users.noreply.github.com>
@upramod
upramod force-pushed the fix/ldap-readonly-username-case-52215 branch from f40d23e to 7ab41dc Compare October 5, 2026 03:13
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.

Copilot review overview

🟢 Approval recommended

The focused validator change resolves the reported behavior while existing tests continue to cover real username mutations.

Review effort: Balanced
Findings: None

What changed in this PR

Fixes LDAP-backed profile updates when an unchanged read-only username differs only by case.

Changes:

  • Compares read-only usernames case-insensitively.
  • Adds regression coverage for LDAP-style preserved casing.
File Description
services/​src/​main/​java/​org/​keycloak/​userprofile/​validator/​UsernameMutationValidator.java Allows case-only username differences.
tests/​base/​src/​test/​java/​org/​keycloak/​tests/​user/​profile/​UserProfileTest.java Tests the LDAP casing scenario.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@upramod
upramod marked this pull request as ready for review October 5, 2026 03:29
Copilot AI balanced review requested due to automatic review settings October 5, 2026 03:29
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.

Copilot review overview

🟢 Approval recommended

The focused change 8000 resolves the reported validation failure while existing coverage still verifies that genuine username changes are rejected.

Review effort: Balanced
Findings: None

@upramod
upramod commented Oct 11, 2026
Copy link
Copy Markdown
Author

@pedroigor This implements the server-side case-insensitive username validation you suggested in #52215.

The change is limited to UsernameMutationValidator and a regression test covering LDAP-style username casing. Actual username changes remain rejected.

All five fork validation workflows passed, and the commit is signed off. Upstream CI still requires maintainer authorization.

Could you review this approach and let me know whether any changes are needed before acceptance?

Copilot AI balanced review requested due to automatic review settings October 17, 2026 21:33
@upramod
upramod commented Oct 17, 2026
Copy link
Copy Markdown
Author

@keycloak/core-iam Could someone please review this when available?

The change is narrowly scoped to the LDAP-backed read-only username case: comparisons are now case-insensitive while genuine username changes remain rejected. The regression test covers the preserved-case LDAP scenario, and the automated review found no issues.

Please let me know if any additional changes or validation are needed.

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.

🟡 Changes recommended

Immutable-attribute validation still blocks case-only federated updates, and the new test passes without the fix.

2 open issues

Review effort: Balanced


String valueLowercased = value.toLowerCase();
if (!realm.isEditUsernameAllowed() && user != null && !valueLowercased.equals(user.getFirstAttribute(UserModel.USERNAME))) {
if (!realm.isEditUsernameAllowed() && user != null && !value.equalsIgnoreCase(user.getFirstAttribute(UserModel.USERNAME))) {
10000
Copilot AI balanced review requested due to automatic review settings October 19, 2026 00:50
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.

🟡 Changes recommended

The regression test’s null federation link causes profile creation to fail before validation.

2 open issues
1 resolved since last review

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings October 19, 2026 00:54
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.

🔵 Needs a closer look

The regression test’s null federation link causes profile construction to fail before validation runs.

2 open issues

Review effort: Balanced

Signed-off-by: Pramod Ubbala <16706816+upramod@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings October 21, 2026 03:54
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

The focused changes preserve rejection of genuine username changes and include regression coverage, with no blocking issues identified.

1 open issue
1 resolved since last review

Review effort: Balanced

@upramod
upramod commented Oct 27, 2026
Copy link
Copy Markdown
Author

The latest automated review reports no blocking findings for the read-only LDAP username validation fix.

Could a maintainer review the implementation and regression coverage and advise whether any additional changes are required?

I can address specific feedback.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Account console: Personal Info save fails with "The field Username is read only" for LDAP users with a read-only username

2 participants

0