Amazon Ergo 1.0 · 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
2 of 7
Comments published
4
Comments matching a bug
2
Comments not matching
2
Cost of this PR
$3.714

Published comments (4)

highbugmodel/infinispan/src/main/java/org/keycloak/models/cache/infinispan/idp/InfinispanIdentityProviderStorageProvider.java:233-240

Stale pre-invalidation ID sets copied back into login cache — A concurrent login-cache invalidation between the pre-invalidation read and re-add can restore stale per-organization ID sets, so `getForLogin` may return hidden, private, or unlinked IDPs and omit newly visible ones. Re-read `query` after `cache.invalidateObject(cacheKey)` and carry over only ID sets from the newer read.

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

Login cache invalidation on IDP create/remove is untested — The test only creates and removes login-ineligible IDPs, so removing `registerIDPLoginInvalidation` from `create()` or `remove()` would go unnoticed, leaving a new login-eligible IDP absent from the login page until an unrelated invalidation. After populating the caches, create then remove a login-eligible IDP and assert all login caches are cleared.

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

Org-linked IDPs are all public, so BROKER_PUBLIC=false is never exercised — The false branch of the `BROKER_PUBLIC` check in `getLoginPredicate()` is untested, so removing or inverting it would still pass while every org-linked IDP is public. Add an org-linked IDP with `BROKER_PUBLIC=false`; verify updates leave login caches intact, then make it public and verify invalidation.

mediumbugmodel/infinispan/src/main/java/org/keycloak/models/cache/infinispan/idp/InfinispanIdentityProviderStorageProvider.java:404-407

Org-disabled IdP updates can leave stale login cache entries — A hidden, link-only, or non-public broker can remain cached while its organization is disabled, then reappear after re-enabling because `OrganizationAwareIdentityProviderBean` only rechecks `isEnabled()`. Compare raw state from `idpDelegate` instead of the org-aware wrapper, or invalidate on login-relevant changes regardless of organization status.

Gold bugs found (2)

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.

Gold bugs missed (5)

lowThe test registers cleanup for the literal alias "alias" instead of the created IDP aliases, so the created identity providers are never cleaned up.
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.