-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Use RoleRetrievalResult for better caching #34197
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
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
daf7712
Use RoleRetrievalResult for better caching
jaymode b91e631
Merge branch 'master' into role_retrieval_result
jaymode 7950ebb
rename method/variables
jaymode 7762e50
simplify code using iterating listener for everything
jaymode 073f71c
Merge branch 'master' into role_retrieval_result
jaymode 1e7e602
prebuild lists like we do for realms
jaymode d898344
Merge branch 'master' into role_retrieval_result
jaymode 6b9aa32
Merge branch 'master' into role_retrieval_result
jaymode 2984699
add nullable annotation
jaymode a0adc25
failure -> success
jaymode 6ba1a8d
minor cleanups
jaymode 4d63622
fix negative lookup cache settings and add test
jaymode cc8c37f
Merge branch 'master' into role_retrieval_result
jaymode 8bf9a7a
Merge branch 'master' into role_retrieval_result
jaymode File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
.../src/main/java/org/elasticsearch/xpack/core/security/authz/store/RoleRetrievalResult.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License; | ||
| * you may not use this file except in compliance with the Elastic License. | ||
| */ | ||
|
|
||
| package org.elasticsearch.xpack.core.security.authz.store; | ||
|
|
||
| import org.elasticsearch.common.Nullable; | ||
| import org.elasticsearch.xpack.core.security.authz.RoleDescriptor; | ||
|
|
||
| import java.util.Objects; | ||
| import java.util.Set; | ||
|
|
||
| /** | ||
| * The result of attempting to retrieve roles from a roles provider. The result can either be | ||
| * successful or a failure. A successful result indicates that no errors occurred while retrieving | ||
| * roles, even if none of the requested roles could be found. A failure indicates an error | ||
| * occurred while retrieving the results but the error is not fatal and the request may be able | ||
| * to continue. | ||
| */ | ||
| public final class RoleRetrievalResult { | ||
|
|
||
| private final Set<RoleDescriptor> descriptors; | ||
|
|
||
| @Nullable | ||
| private final Exception failure; | ||
|
|
||
| private RoleRetrievalResult(Set<RoleDescriptor> descriptors, @Nullable Exception failure) { | ||
| if (descriptors != null && failure != null) { | ||
| throw new IllegalArgumentException("either descriptors or failure must be null"); | ||
| } | ||
| this.descriptors = descriptors; | ||
| this.failure = failure; | ||
| } | ||
|
|
||
| /** | ||
| * @return the resolved descriptors or {@code null} if there was a failure | ||
| */ | ||
| public Set<RoleDescriptor> getDescriptors() { | ||
| return descriptors; | ||
| } | ||
|
|
||
| /** | ||
| * @return the failure or {@code null} if retrieval succeeded | ||
| */ | ||
| @Nullable | ||
| public Exception getFailure() { | ||
| return failure; | ||
| } | ||
|
|
||
| /** | ||
| * @return true if the retrieval succeeded | ||
| */ | ||
| public boolean isSuccess() { | ||
| return descriptors != null; | ||
| } | ||
|
|
||
| /** | ||
| * Creates a successful result with the provided {@link RoleDescriptor} set, | ||
| * which must be non-null | ||
| */ | ||
| public static RoleRetrievalResult success(Set<RoleDescriptor> descriptors) { | ||
| Objects.requireNonNull(descriptors, "descriptors must not be null if successful"); | ||
| return new RoleRetrievalResult(descriptors, null); | ||
| } | ||
|
|
||
| /** | ||
| * Creates a failed result with the provided non-null exception | ||
| */ | ||
| public static RoleRetrievalResult failure(Exception e) { | ||
| Objects.requireNonNull(e, "Exception must be provided"); | ||
| return new RoleRetrievalResult(null, e); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.