Add cache for IdentityProviderStorageProvider.getForLogin - #1
Conversation
Closes #32573 Signed-off-by: Stefan Guilhen <sguilhen@redhat.com>
📝 WalkthroughWalkthroughThis PR implements login-specific caching for identity providers with organization-aware predicate filtering. It extends the Infinispan storage provider with dedicated login cache keys and query methods, restricts login-eligible IDPs based on organization and public broker configuration, and validates caching behavior through a comprehensive integration test. ChangesLogin IDP Caching and Organization Scoping
Sequence DiagramsequenceDiagram
participant Caller
participant getForLogin
participant Cache
participant Delegate
participant InvalidationHelper
Caller->>getForLogin: getForLogin(FetchMode, organizationId)
getForLogin->>Cache: Check revisioned cache key
alt Cache Hit
Cache-->>getForLogin: Return cached IDPs
else Cache Miss
getForLogin->>Delegate: getForLogin(FetchMode, organizationId)
Delegate-->>getForLogin: Stream of IDPs
getForLogin->>Cache: Store revisioned results
getForLogin->>InvalidationHelper: Check for missing IDPs
alt IDP Missing
InvalidationHelper->>Cache: Invalidate login caches
end
end
getForLogin-->>Caller: Return IDPs
Estimated code review effort🎯 4 (Complex) | ⏱️ ~50 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In
`@testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/organization/cache/OrganizationCacheTest.java`:
- Around line 380-382: The cleanup callback is using the hardcoded string
"alias" instead of the actual Identity Provider alias; update the cleanup
registration to reference the real alias (e.g., use the variable holding the
alias or call idpRep.getAlias()) when calling
testRealm().identityProviders().get(... )::remove so the created IDP is
correctly removed; ensure you apply the same change to both occurrences around
the test (lines referencing get("alias") that follow
identityProviders().create(idpRep) and similar blocks).
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 6dc46167-2a12-4c74-8926-56774ba84b1e
📒 Files selected for processing (5)
.github/dependabot.ymlmodel/infinispan/src/main/java/org/keycloak/models/cache/infinispan/idp/InfinispanIdentityProviderStorageProvider.javaserver-spi/src/main/java/org/keycloak/models/IdentityProviderStorageProvider.javaservices/src/main/java/org/keycloak/organization/forms/login/freemarker/model/OrganizationAwareIdentityProviderBean.javatestsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/organization/cache/OrganizationCacheTest.java
💤 Files with no reviewable changes (1)
- .github/dependabot.yml
| testRealm().identityProviders().create(idpRep).close(); | ||
| getCleanup().addCleanup(testRealm().identityProviders().get("alias")::remove); | ||
| } |
There was a problem hiding this comment.
Cleanup registration uses hardcoded literal "alias" instead of actual IDP alias.
The cleanup callbacks reference testRealm().identityProviders().get("alias") but "alias" is a string literal, not the variable. This won't properly clean up the created IDPs after the test.
Proposed fix
for (int i = 0; i < 20; i++) {
IdentityProviderRepresentation idpRep = new IdentityProviderRepresentation();
- idpRep.setAlias("idp-alias-" + i);
+ String alias = "idp-alias-" + i;
+ idpRep.setAlias(alias);
idpRep.setEnabled((i % 2) == 0); // half of the IDPs will be disabled and won't qualify for login.
idpRep.setDisplayName("Broker " + i);
idpRep.setProviderId("keycloak-oidc");
if (i >= 10)
idpRep.getConfig().put(OrganizationModel.BROKER_PUBLIC, Boolean.TRUE.toString());
testRealm().identityProviders().create(idpRep).close();
- getCleanup().addCleanup(testRealm().identityProviders().get("alias")::remove);
+ getCleanup().addCleanup(testRealm().identityProviders().get(alias)::remove);
}And similarly for line 425:
testRealm().identityProviders().create(idpRep).close();
- getCleanup().addCleanup(testRealm().identityProviders().get("alias")::remove);
+ getCleanup().addCleanup(testRealm().identityProviders().get("idp-alias-20")::remove);Also applies to: 424-426
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In
`@testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/organization/cache/OrganizationCacheTest.java`
around lines 380 - 382, The cleanup callback is using the hardcoded string
"alias" instead of the actual Identity Provider alias; update the cleanup
registration to reference the real alias (e.g., use the variable holding the
alias or call idpRep.getAlias()) when calling
testRealm().identityProviders().get(... )::remove so the created IDP is
correctly removed; ensure you apply the same change to both occurrences around
the test (lines referencing get("alias") that follow
identityProviders().create(idpRep) and similar blocks).
Closes #32573
Summary by CodeRabbit
New Features
Performance
Bug Fixes
Chores