sungwy commented on code in PR #4409:
URL: https://github.com/apache/polaris/pull/4409#discussion_r3335641324


##########
extensions/auth/opa/impl/src/main/java/org/apache/polaris/extension/auth/opa/OpaPolarisAuthorizer.java:
##########
@@ -117,17 +125,52 @@ public void resolveAuthorizationInputs(
   @NonNull
   public AuthorizationDecision authorize(
       @NonNull AuthorizationState authzState, @NonNull AuthorizationRequest 
request) {
-    boolean allowed =
-        queryOpa(
-            buildOpaAuthorizationInput(
-                request.getPrincipal(),
-                request.getOperation(),
-                toResourceEntitiesFromSecurables(request.getTargets()),
-                toResourceEntitiesFromSecurables(request.getSecondaries())));
-    return allowed
-        ? AuthorizationDecision.allow()
-        : AuthorizationDecision.deny(
-            "OPA denied authorization for " + 
request.formatForAuthorizationMessage());
+    for (AuthorizationIntent intent : request.intents()) {
+      PolarisAuthorizableOperation operation = intent.getOperation();
+      List<ResourceEntity> targets;
+      List<ResourceEntity> secondaries;
+      switch (intent) {
+        case TargetlessAuthorizationIntent ignored -> {
+          targets = List.of();
+          secondaries = List.of();
+        }
+        case SingleTargetAuthorizationIntent singleTargetIntent -> {
+          targets = 
toResourceEntitiesFromSecurable(singleTargetIntent.target());
+          secondaries = List.of();
+        }
+        case RenameAuthorizationIntent renameIntent -> {
+          targets = toResourceEntitiesFromSecurable(renameIntent.from());
+          secondaries = toResourceEntitiesFromSecurable(renameIntent.to());
+        }
+        case PolicyAttachmentAuthorizationIntent policyAttachmentIntent -> {
+          targets = 
toResourceEntitiesFromSecurable(policyAttachmentIntent.policy());
+          secondaries = 
toResourceEntitiesFromSecurable(policyAttachmentIntent.attachedTo());
+        }
+        case RoleAssignmentAuthorizationIntent roleAssignmentIntent -> {
+          targets = 
toResourceEntitiesFromSecurable(roleAssignmentIntent.role());
+          secondaries = 
toResourceEntitiesFromSecurable(roleAssignmentIntent.assignee());
+        }
+        case PrivilegeGrantAuthorizationIntent privilegeGrantIntent -> {
+          targets = 
toResourceEntitiesFromSecurable(privilegeGrantIntent.grantTarget());
+          secondaries = 
toResourceEntitiesFromSecurable(privilegeGrantIntent.grantee());
+        }
+        case RootPrivilegeGrantAuthorizationIntent rootPrivilegeGrantIntent -> 
{
+          targets = List.of();
+          secondaries = 
toResourceEntitiesFromSecurable(rootPrivilegeGrantIntent.grantee());

Review Comment:
   note to reviewer: we map these to `targets` and `secondaries` today, but we 
could map it to other attribute holders in the future.



-- 
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]

Reply via email to