-
Notifications
You must be signed in to change notification settings - Fork 0
[Review] Add caching support for IdentityProviderStorageProvider.getForLogin operations #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: feature-idp-cache-baseline
Are you sure you want to change the base?
Conversation
Closes #32573 Signed-off-by: Stefan Guilhen <[email protected]>
| } | ||
|
|
||
| String orgaId = testRealm().organizations().getAll().get(0).getId(); | ||
| for (int i = 10; i < 20; i++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔴 HIGH | logic_defect
Test cleanup issue: cleanup code references 'alias' but IDPs are created with specific aliases like 'idp-alias-' + i. This will cause cleanup to fail.
💡 Suggestion: Fix the cleanup code to use the correct alias or remove cleanup calls as they seem to be using wrong identifiers.
| for (int i = 10; i < 20; i++) { | |
| getCleanup().addCleanup(() -> testRealm().identityProviders().get("idp-alias-" + 20).remove()); |
| // perform some login IDP searches and ensure they are cached. | ||
| session.identityProviders().getForLogin(FetchMode.REALM_ONLY, null); | ||
| IdentityProviderListQuery identityProviderListQuery = realmCache.getCache().get(cacheKeyForLogin(realm, FetchMode.REALM_ONLY), IdentityProviderListQuery.class); | ||
| assertNotNull(identityProviderListQuery); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔴 HIGH | logic_defect
Same cleanup issue - using 'alias' instead of the actual IDP alias 'idp-alias-20'.
💡 Suggestion: Fix the cleanup alias reference.
| assertNotNull(identityProviderListQuery); | |
| getCleanup().addCleanup(() -> testRealm().identityProviders().get("idp-alias-20").remove()); |
|
|
||
| @Override | ||
| public Stream<IdentityProviderModel> getForLogin(FetchMode mode, String organizationId) { | ||
| String cacheKey = cacheKeyForLogin(getRealm(), mode); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 MEDIUM | static_defect
Potential NPE: idpDelegate.getForLogin() could return null, which would cause NPE when calling .map() on the result.
💡 Suggestion: Add null check or handle null stream appropriately.
| String cacheKey = cacheKeyForLogin(getRealm(), mode); | |
| if (isInvalid(cacheKey)) { | |
| Stream<IdentityProviderModel> result = idpDelegate.getForLogin(mode, organizationId); | |
| return result != null ? result.map(this::createOrganizationAwareIdentityProviderModel) : Stream.empty(); | |
| } |
| IdentityProviderListQuery query = cache.get(cacheKey, IdentityProviderListQuery.class); | ||
| String searchKey = organizationId != null ? organizationId : ""; | ||
| Set<String> cached; | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 MEDIUM | static_defect
Potential NPE: idpDelegate.getForLogin() could return null, causing NPE in collect operation.
💡 Suggestion: Add null check before collecting stream.
| Stream<IdentityProviderModel> idpStream = idpDelegate.getForLogin(mode, organizationId); | |
| if (idpStream == null) { | |
| cached = Set.of(); | |
| } else { | |
| cached = idpStream.map(IdentityProviderModel::getInternalId).collect(Collectors.toSet()); | |
| } |
| cached = idpDelegate.getForLogin(mode, organizationId).map(IdentityProviderModel::getInternalId).collect(Collectors.toSet()); | ||
| query = new IdentityProviderListQuery(loaded, cacheKey, getRealm(), searchKey, cached); | ||
| cache.addRevisioned(query, startupRevision); | ||
| } else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 MEDIUM | static_defect
Potential NPE: idpDelegate.getForLogin() could return null, causing NPE in collect operation.
💡 Suggestion: Add null check before collecting stream.
| } else { | |
| Stream<IdentityProviderModel> idpStream = idpDelegate.getForLogin(mode, organizationId); | |
| if (idpStream == null) { | |
| cached = Set.of(); | |
| } else { | |
| cached = idpStream.map(IdentityProviderModel::getInternalId).collect(Collectors.toSet()); | |
| } |
| } | ||
|
|
||
| Set<IdentityProviderModel> identityProviders = new HashSet<>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 MEDIUM | static_defect
Potential NPE: idpDelegate.getForLogin() could return null, causing NPE when calling .map().
💡 Suggestion: Add null check before mapping stream.
| } | |
| Set<IdentityProviderModel> identityProviders = new HashSet<>(); | |
| if (idp == null) { | |
| realmCache.registerInvalidation(cacheKey); | |
| Stream<IdentityProviderModel> result = idpDelegate.getForLogin(mode, organizationId); | |
| return result != null ? result.map(this::createOrganizationAwareIdentityProviderModel) : Stream.empty(); | |
| } |
Mirrored from ai-code-review-evaluation#2.
Test 2