DeepSeek V4 Pro · Heavy

add-caching-support-for-identityproviderstorageprovider-getforlogin-operations-keycloak

Keycloak · Java · M · 100–299 lines · 3 files

The generalist plus 9 specialist lens agents in parallel, then the same verify and dedup steps. Judge: Claude Opus 5.5.

Gold bugs found
1 of 7
Comments published
4
Comments matching a bug
1
Comments not matching
3
Cost of this PR
$1.710

Published comments (4)

mediumperformancemodel/infinispan/src/main/java/org/keycloak/models/cache/infinispan/idp/InfinispanIdentityProviderStorageProvider.java:245-252

N+1 JPA queries in getForLogin cache-miss loop — Each cached internalId triggers a separate database lookup on the login page when the cache is cold, causing O(N) queries for realms with many IDPs. Reuse the models already loaded by `idpDelegate.getForLogin` or load them in bulk instead of calling `session.identityProviders().getById(id)` inside the loop.

mediumbugtestsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/organization/cache/OrganizationCacheTest.java:417-428

Login cache invalidation on qualified IDP create/remove is untested — The current steps never touch login-qualified IDPs, so a broken `registerIDPLoginInvalidation` in `create()` or `remove()` would leave stale login caches and all assertions would still pass. Add a create and a remove step for a login-qualified IDP and assert all three login caches are invalidated each time.

mediumbugtestsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/organization/cache/OrganizationCacheTest.java:378-386

Login cache test lacks org-linked IDP with BROKER_PUBLIC false/absent — Because every org-linked IDP sets `OrganizationModel.BROKER_PUBLIC=true`, the false/absent branch in `getLoginPredicate` is never exercised and a broken condition would not change the expected counts. Add an org-linked IDP without `BROKER_PUBLIC` and assert it is excluded from login results.

mediumbugtestsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/organization/cache/OrganizationCacheTest.java:381

IDP cleanup uses literal alias instead of created alias — Cleanup callbacks use the literal `"alias"` instead of the generated alias, so none of the created IDPs are removed and they persist into the shared realm for later tests. Register the cleanup with `testRealm().identityProviders().get(idpRep.getAlias())::remove`.

Gold bugs found (1)

lowThe test registers cleanup for the literal alias "alias" instead of the created IDP aliases, so the created identity providers are never cleaned up.

Gold bugs missed (6)

mediumOn a partial cache miss getForLogin merges the previously read login query into a newly revisioned entry, so a concurrent invalidation can be lost and stale IDP IDs for other organizations persist.
mediumLogin-cache invalidation on update compares the organization-aware enabled state, so changing a broker to private while its organization is disabled skips invalidation and leaves the now-private IDP in the cached login list.
mediumregisterIDPLoginInvalidationOnUpdate returns early when the IDP stays a login IDP with the same organizationId without comparing BROKER_PUBLIC, so toggling kc.org.broker.public on a realm-level IDP leaves the login caches stale.
mediumThe cache-hit path of getForLogin collects IDPs into a HashSet and streams it, so results come in hash order instead of the delegate's order returned on a miss, making ordering differ by cache state.
highAdding the organization/BROKER_PUBLIC check to the shared LoginFilter.getLoginPredicate also changes IdentityProviderBean.federatedProviderPredicate, so with organizations disabled a user's linked IdP that has an organizationId but is not public is no longer shown on the login page.
mediumgetLoginPredicate treats BROKER_PUBLIC case-insensitively, but the JPA delegate matches the exact value "true". An update that only changes the case (e.g. true -> TRUE) skips login-cache invalidation, so the cached login IDP list no longer matches the delegate.