[#11403] improvement(authz): use per-request cache for group owner check in JcasbinAuthorizer#11404
Open
yuqi1129 wants to merge 1 commit into
Open
[#11403] improvement(authz): use per-request cache for group owner check in JcasbinAuthorizer#11404yuqi1129 wants to merge 1 commit into
yuqi1129 wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request updates JcasbinAuthorizer to resolve GROUP ownership checks through the per-request group info cache (via groupMetaMapper.getGroupUpdatedAt) rather than loading full GroupEntity objects from EntityStore, reducing redundant DB work during repeated owner checks within a request.
Changes:
- Updated GROUP owner matching to use
currentPrincipalGroupNames()+loadGroupInfo()(per-request dedup) instead ofentityStore.batchGet(..., GROUP, GroupEntity.class). - Removed the now-unused
resolveCurrentUserGroups()helper and itsGroupEntityusage in the authorizer. - Updated and added unit tests to assert the new query path and per-request dedup behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| server-common/src/main/java/org/apache/gravitino/server/authorization/jcasbin/JcasbinAuthorizer.java | Switches GROUP owner resolution to use per-request cached group meta lookups instead of loading full group entities. |
| server-common/src/test/java/org/apache/gravitino/server/authorization/jcasbin/TestJcasbinAuthorizer.java | Updates existing owner-by-group test expectations and adds a test ensuring group info lookups are deduplicated within a single request context. |
Code Coverage Report
Files
|
…ner check in JcasbinAuthorizer Replace resolveCurrentUserGroups(entityStore) in ownerMatchesUserOrGroups() with currentPrincipalGroupNames() + loadGroupInfo(), routing group-id lookups through requestContext.groupInfoCache (per-request dedup) instead of issuing a direct entityStore.batchGet(GROUP) on every GROUP owner check. Remove the now-unused resolveCurrentUserGroups() method and its GroupEntity import. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
520015f to
e2bc035
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What changes were proposed in this pull request?
Replace
resolveCurrentUserGroups(metalake, entityStore)inownerMatchesUserOrGroups()withcurrentPrincipalGroupNames()+loadGroupInfo(). The new path routes throughrequestContext.groupInfoCache(per-request dedup) before falling back to a lightweightgroup_metaquery viaGroupMetaMapper#getGroupUpdatedAt, and removes the need to load fullGroupEntityobjects. The now-unusedresolveCurrentUserGroups()method and itsGroupEntityimport are removed.Why are the changes needed?
The old path bypassed all caches and issued an
entityStore.batchGet(GROUP)DB call on every GROUP owner check. InhasSetOwnerPermission, which walks the full parent chain callingisOwnerin a loop, this could fire multiple times per request when the owner is a group. The fix ensures group identity is resolved through the same version-validated cache path as all other identity lookups in the authorizer.Fix: #11403
Does this PR introduce any user-facing change?
No.
How was this patch tested?
testAuthorizeByGroupOwnerto mockgroupMetaMapper.getGroupUpdatedAtinstead ofentityStore.batchGet(GROUP), and added averifyassertion thatentityStore.batchGet(GROUP)is never called.testGroupOwnerCheckDeduplicatesGroupInfoWithinRequestwhich callsisOwnertwice within the sameAuthorizationRequestContextand asserts thatgroupMetaMapper.getGroupUpdatedAtis invoked exactly once (per-request cache dedup).