roryqi commented on code in PR #10908:
URL: https://github.com/apache/gravitino/pull/10908#discussion_r3168531197
##########
server-common/src/main/java/org/apache/gravitino/server/authorization/jcasbin/JcasbinAuthorizer.java:
##########
@@ -440,20 +447,59 @@ private boolean loadPrivilegeAndAuthorize(
return false;
}
loadRolePrivilege(metalake, username, userId, requestContext);
- return authorizeByJcasbin(userId, metadataObject, metadataId, privilege);
+ return authorizeByIndex(userId, metadataObject, metadataId, privilege,
requestContext);
}
- private boolean authorizeByJcasbin(
- Long userId, MetadataObject metadataObject, Long metadataId, String
privilege) {
+ /**
+ * Resolve a single privilege probe against the per-role policy index.
Replaces the previous
+ * {@code enforcer.enforce} call, which scanned every policy line in the
enforcer for each
+ * probe. Per-request cost goes from {@code O(total_policies)} to {@code
O(roles_per_user)} hash
+ * probes.
+ */
+ private boolean authorizeByIndex(
+ Long userId,
+ MetadataObject metadataObject,
+ Long metadataId,
+ String privilege,
+ AuthorizationRequestContext requestContext) {
if (AuthConstants.OWNER.equals(privilege)) {
Optional<Long> owner = ownerRel.getIfPresent(metadataId);
return Objects.equals(Optional.of(userId), owner);
}
- return enforcer.enforce(
- String.valueOf(userId),
- String.valueOf(metadataObject.type()),
- String.valueOf(metadataId),
- privilege);
+ Set<Long> roleIds = requestContext.getUserRoleIds();
+ if (roleIds.isEmpty()) {
+ return false;
+ }
+ PolicyKey key = new PolicyKey(metadataObject.type().name(), metadataId,
privilege);
+ if (authorizationMode == AuthorizationMode.DENY) {
Review Comment:
We shouldn't have authorizationMode in my view.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]