xunliu commented on code in PR #5113:
URL: https://github.com/apache/gravitino/pull/5113#discussion_r1806691146


##########
authorizations/authorization-ranger/src/main/java/org/apache/gravitino/authorization/ranger/RangerSecurableObject.java:
##########
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.gravitino.authorization.ranger;
+
+import java.util.List;
+import org.apache.gravitino.MetadataObject;
+import org.apache.gravitino.annotation.Unstable;
+
+/**
+ * The Ranger securable object is the entity which access can be granted. 
Unless allowed by a grant,
+ * access is denied. <br>
+ * You can use the helper class `RangerSecurableObjects` to create the Ranger 
securable object which
+ * you need.
+ */
+@Unstable
+public interface RangerSecurableObject extends MetadataObject {

Review Comment:
   DONE



##########
authorizations/authorization-ranger/src/main/java/org/apache/gravitino/authorization/ranger/RangerAuthorizationPlugin.java:
##########
@@ -522,36 +657,35 @@ private boolean 
doRemoveSecurableObject(RoleChange.RemoveSecurableObject change)
     return true;
   }
 
-  /**
-   * 1. Find the policy base the metadata object. <br>
-   * 2. If the policy exists, then user new securable object's privilege to 
update. <br>
-   * 3. If the policy does not exist, return false. <br>
-   */
-  private boolean doUpdateSecurableObject(RoleChange.UpdateSecurableObject 
change) {
-    RangerPolicy policy = 
rangerHelper.findManagedPolicy(change.getSecurableObject());
-    if (policy == null) {
-      LOG.warn(
-          "Cannot find the Ranger policy({}) for the Gravitino securable 
object({})!",
-          change.getRoleName(),
-          change.getSecurableObject().fullName());
-      // Don't throw exception or return false, because need support immutable 
operation.
-      return false;
-    }
-
-    rangerHelper.removePolicyItem(policy, change.getRoleName(), 
change.getSecurableObject());
-    rangerHelper.addPolicyItem(policy, change.getRoleName(), 
change.getNewSecurableObject());
-    try {
-      if (policy.getId() == null) {
-        rangerClient.createPolicy(policy);
-      } else {
-        rangerClient.updatePolicy(policy.getId(), policy);
-      }
-    } catch (RangerServiceException e) {
-      throw new RuntimeException(e);
-    }
-    return true;
-  }
-
   @Override
   public void close() throws IOException {}
+
+  public boolean validAuthorizationOperation(List<SecurableObject> 
securableObjects) {
+    return securableObjects.stream()
+        .noneMatch(
+            securableObject -> {
+              AtomicBoolean match = new AtomicBoolean(true);
+              securableObject.privileges().stream()
+                  .forEach(
+                      privilege -> {
+                        if (!allowPrivilegesRule().contains(privilege.name())) 
{
+                          LOG.error(
+                              "Authorization to ignore privilege({}) on 
metadata object({})!",
+                              privilege.name(),
+                              securableObject.fullName());
+                          match.set(false);
+                          return;
+                        }
+
+                        if (!privilege.canBindTo(securableObject.type())) {
+                          LOG.error(
+                              "The privilege({}) is not supported for the 
metadata object({})!",
+                              privilege.name(),
+                              securableObject.fullName());
+                          match.set(false);
+                        }
+                      });
+              return !match.get();
+            });

Review Comment:
   DONE



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