Repository navigation
Conversation
16c387a to
21d8613
Compare
There was a problem hiding this comment.
🟡 Changes recommended
The test can pass with the old early return because the client representation request prepopulates the username query, preventing it from exercising the intended managed-user cache-miss path.
1 open issue
What changed in this PR
Extends the username/email caching fix from #54646 to federated-identity and service-account lookups, addressing #55237 when users are already managed in the session.
Changes:
- Caches both lookup queries on eligible managed-user paths, preserving revision and lifespan handling.
- Adds realm checks and a service-account client-link check.
- Adds integration tests that inspect cache entries after sequential user lookups.
| File | Description |
|---|---|
tests/base/src/test/java/org/keycloak/tests/model/UserCacheManagedUserQueryTest.java |
Adds managed-user query-caching tests for both lookup types. |
model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/UserCacheSession.java |
Stores eligible lookup queries before returning already-managed users. |
Review effort: Balanced
There was a problem hiding this comment.
🔵 Needs a closer look
The regression test setup prepopulates the username query cache, so the lookup takes the cache-hit path and passes without the production fix rather than exercising the intended managed-user cache-miss branch.
Review effort: Balanced
21d8613 to
d1973ad
Compare
Unreported flaky test detectedIf the flaky tests below are affected by the changes, please review and update the changes accordingly. Otherwise, a maintainer should report the flaky tests prior to merging the PR. org.keycloak.testsuite.broker.KcSamlBrokerTest#loginClientWithDotsInNameKeycloak CI - FIPS IT (strict) |
| // the user was already loaded by another lookup in this session (for example by getUserById), | ||
| // so the service account username query for this key still needs to be cached | ||
| UserModel managedUser = managed.user(); | ||
| if (realm.getId().equals(managed.realmId()) && managedUser instanceof UserAdapter |
There was a problem hiding this comment.
We have a defensive check in getUserById to ensure the returned entry belongs to the realm. Does it make sense to add it here as well?
…users Closes keycloak#55237 Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Signed-off-by: Stefan Guilhen <sguilhen@redhat.com>
d1973ad to
689954d
Compare
There was a problem hiding this comment.
🟡 Changes recommended
Token-only federated identity updates unnecessarily evict the reverse-lookup cache, forcing subsequent broker logins to query the delegate even though the provider/user-ID mapping is unchanged.
1 open issue
Review effort: Balanced
| @Override | ||
| public void updateFederatedIdentity(RealmModel realm, UserModel federatedUser, FederatedIdentityModel federatedIdentityModel) { | ||
| invalidateFederationLink(federatedUser.getId()); | ||
| invalidateFederationLink(realm, federatedUser.getId(), federatedIdentityModel); |

Closes #55237