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


##########
authorizations/authorization-ranger/src/main/java/org/apache/gravitino/authorization/ranger/RangerAuthorizationPlugin.java:
##########
@@ -63,18 +62,23 @@
  * 4. The Ranger policy also supports multiple users and groups, But we only 
use a user or group to
  * implement Gravitino Owner concept. <br>
  */
-public class RangerAuthorizationPlugin implements AuthorizationPlugin {
+public abstract class RangerAuthorizationPlugin
+    implements AuthorizationPlugin, RangerPrivilegesMappingProvider {
   private static final Logger LOG = 
LoggerFactory.getLogger(RangerAuthorizationPlugin.class);
 
-  protected String catalogProvider;
+  /** Mapping Gravitino privilege name to the Ranger privileges configuration. 
*/
+  private Map<Privilege.Name, Set<RangerPrivilege>> privilegesMapping;
+  /** The owner privileges, the owner can do anything on the metadata object 
configuration */
+  private Set<RangerPrivilege> ownerPrivileges;
+  /** The Ranger policy resource defines configuration. */
+  private List<String> policyResourceDefines;

Review Comment:
   DONE.



##########
authorizations/authorization-ranger/src/main/java/org/apache/gravitino/authorization/ranger/RangerAuthorizationHivePlugin.java:
##########
@@ -0,0 +1,62 @@
+/*
+ * 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 com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import org.apache.gravitino.authorization.Privilege;
+import 
org.apache.gravitino.authorization.ranger.RangerPrivilege.RangerHivePrivilege;
+import 
org.apache.gravitino.authorization.ranger.reference.RangerDefines.PolicyResource;
+
+public class RangerAuthorizationHivePlugin extends RangerAuthorizationPlugin {
+  public RangerAuthorizationHivePlugin(Map<String, String> config) {
+    super(config);
+  }
+
+  /** Set the default mapping Gravitino privilege name to the Ranger rule */
+  public Map<Privilege.Name, Set<RangerPrivilege>> privilegesMappingRule() {
+    return ImmutableMap.of(
+        Privilege.Name.CREATE_SCHEMA,
+        ImmutableSet.of(RangerHivePrivilege.CREATE),
+        Privilege.Name.CREATE_TABLE,
+        ImmutableSet.of(RangerHivePrivilege.CREATE),
+        Privilege.Name.MODIFY_TABLE,
+        ImmutableSet.of(
+            RangerHivePrivilege.UPDATE, RangerHivePrivilege.ALTER, 
RangerHivePrivilege.WRITE),
+        Privilege.Name.SELECT_TABLE,
+        ImmutableSet.of(RangerHivePrivilege.READ, RangerHivePrivilege.SELECT));
+  }
+
+  /** Set the default owner rule. */
+  public Set<RangerPrivilege> ownerMappingRule() {
+    return ImmutableSet.of(RangerHivePrivilege.ALL);
+  }
+
+  /** Set Ranger policy resource rule. */
+  public List<String> policyResourceDefinesRule() {
+    return ImmutableList.of(
+        PolicyResource.DATABASE.getName(),
+        PolicyResource.TABLE.getName(),
+        PolicyResource.COLUMN.getName());

Review Comment:
   Changed to singleton.



##########
authorizations/authorization-ranger/src/main/java/org/apache/gravitino/authorization/ranger/RangerAuthorizationPlugin.java:
##########
@@ -87,22 +91,42 @@ public RangerAuthorizationPlugin(String catalogProvider, 
Map<String, String> con
     RangerHelper.check(password != null, "Ranger password is required");
     RangerHelper.check(rangerServiceName != null, "Ranger service name is 
required");
     rangerClient = new RangerClientExtend(rangerUrl, authType, 
rangerAdminName, password);
-    rangerHelper = new RangerHelper(this, catalogProvider);
+
+    // Initialize privilegesMapping and ownerPrivileges
+    ownerPrivileges = ownerMappingRule();
+    privilegesMapping = privilegesMappingRule();
+    policyResourceDefines = policyResourceDefinesRule();

Review Comment:
   DONE.



##########
authorizations/authorization-ranger/src/main/java/org/apache/gravitino/authorization/ranger/RangerAuthorizationPlugin.java:
##########
@@ -87,22 +91,42 @@ public RangerAuthorizationPlugin(String catalogProvider, 
Map<String, String> con
     RangerHelper.check(password != null, "Ranger password is required");
     RangerHelper.check(rangerServiceName != null, "Ranger service name is 
required");
     rangerClient = new RangerClientExtend(rangerUrl, authType, 
rangerAdminName, password);
-    rangerHelper = new RangerHelper(this, catalogProvider);
+
+    // Initialize privilegesMapping and ownerPrivileges
+    ownerPrivileges = ownerMappingRule();
+    privilegesMapping = privilegesMappingRule();
+    policyResourceDefines = policyResourceDefinesRule();
+
+    rangerHelper =
+        new RangerHelper(
+            rangerClient,
+            rangerAdminName,
+            rangerServiceName,
+            privilegesMapping,
+            ownerPrivileges,
+            policyResourceDefines);
+  }
+
+  public final Map<Privilege.Name, Set<RangerPrivilege>> 
getPrivilegesMapping() {
+    return privilegesMapping;
+  }
+
+  public final Set<RangerPrivilege> getOwnerPrivileges() {
+    return ownerPrivileges;
+  }
+
+  public final List<String> getPolicyResourceDefines() {
+    return policyResourceDefines;

Review Comment:
   DONE



##########
integration-test-common/src/test/java/org/apache/gravitino/integration/test/container/RangerContainer.java:
##########
@@ -38,7 +38,7 @@ public class RangerContainer extends BaseContainer {
   public static final String DEFAULT_IMAGE = 
System.getenv("GRAVITINO_CI_RANGER_DOCKER_IMAGE");
   public static final String HOST_NAME = "gravitino-ci-ranger";
   public static final int RANGER_SERVER_PORT = 6080;
-  public RangerClient rangerClient;
+  public RangerClientExtend rangerClient;

Review Comment:
   Changed to `RangerClientExtension`.



##########
authorizations/authorization-ranger/src/main/java/org/apache/gravitino/authorization/ranger/RangerPrivilege.java:
##########
@@ -0,0 +1,81 @@
+/*
+ * 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;
+
+/** RangerPrivilege interface is used to define the Ranger privileges. */
+public interface RangerPrivilege {
+  String getName();
+
+  boolean isEquals(String value);

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