8000 Only use a managed user for getUserByUsername/getUserByEmail if it ma… by sguilhen · Pull Request #55555 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content

Only use a managed user for getUserByUsername/getUserByEmail if it ma… - #55555

Merged
pedroigor merged 2 commits into
keycloak:mainfrom
sguilhen:54646-usercache-realm-check
Nov 27, 2026
Merged

pedroigor merged 2 commits into
keycloak:mainfrom
sguilhen:54646-usercache-realm-check

Conversation

@sguilhen
@sguilhen sguilhen commented Nov 25, 2026 •
Copy link
Copy Markdown
Contributor

…tches the realm

getUserById already falls back to a fresh lookup when a managed user with the same id belongs to a different realm; getUserByUsername/getUserByEmail (added in #54646) only used that check to decide whether to cache the query, but still returned the managed user regardless of a realm mismatch.

Closes #55554

@sguilhen
sguilhen requested review from a team as code owners November 25, 2026 19:22
Copilot AI balanced review requested due to automatic review settings November 25, 2026 19:22
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 encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

…tches the realm

getUserById already falls back to a fresh lookup when a managed user with the
same id belongs to a different realm; getUserByUsername/getUserByEmail (added
in keycloak#54646) only used that check to decide whether to cache the query, but
still returned the managed user regardless of a realm mismatch.

Closes keycloak#55554

Signed-off-by: Stefan Guilhen <sguilhen@redhat.com>
@sguilhen
sguilhen force-pushed the 54646-usercache-realm-check branch from 02a54c7 to 1672685 Compare November 25, 2026 19:25
@stianst stianst added the kind/bug Categorizes a PR related to a bug label Nov 27, 2026
Copilot AI balanced review requested due to automatic review settings November 27, 2026 15:28
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 new tests leave the managed-user map empty, so they would pass even if the username/email realm guards were reverted; each needs to preload the forged entry before lookup.

1 open issue

Review effort: Balanced

…gs to another realm

- getUserAdapter() handed any cached entry for a user id straight to validateCache(), which
returns null on a realm mismatch, discarding the delegate it was passed even though the
delegate already resolved the correct user for the requested realm

Signed-off-by: Stefan Guilhen <sguilhen@redhat.com>
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

No active review issues were identified for the cross-realm user-cache lookup changes.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@pedroigor
pedroigor merged commit 61d3391 into keycloak:main Nov 27, 2026
97 checks passed
ahus1 pushed a commit to ahus1/keycloak that referenced this pull request Dec 2, 2026
keycloak#55555)

* Only use a managed user for getUserByUsername/getUserByEmail if it matches the realm

getUserById already falls back to a fresh lookup when a managed user with the
same id belongs to a different realm; getUserByUsername/getUserByEmail (added
in keycloak#54646) only used that check to decide whether to cache the query, but
still returned the managed user regardless of a realm mismatch.

Closes keycloak#55554

Signed-off-by: Stefan Guilhen <sguilhen@redhat.com>

* Return the resolved user when the shared cache entry for its id belongs to another realm

- getUserAdapter() handed any cached entry for a user id straight to validateCache(), which
returns null on a realm mismatch, discarding the delegate it was passed even though the
delegate already resolved the correct user for the requested realm

Signed-off-by: Stefan Guilhen <sguilhen@redhat.com>

---------

Signed-off-by: Stefan Guilhen <sguilhen@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

flaky-test kind/bug Categorizes a PR related to a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Username/email cache lookup can return a managed user from a different realm

4 participants

0