mneethiraj commented on code in PR #3928:
URL: https://github.com/apache/polaris/pull/3928#discussion_r2922625677


##########
extensions/auth/ranger/src/main/java/org/apache/polaris/extension/auth/ranger/utils/RangerUtils.java:
##########
@@ -0,0 +1,255 @@
+/*
+ * 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.polaris.extension.auth.ranger.utils;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Collections;
+import java.util.EnumSet;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+import java.util.stream.Collectors;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.polaris.core.auth.PolarisAuthorizableOperation;
+import org.apache.polaris.core.auth.PolarisPrincipal;
+import org.apache.polaris.core.entity.PolarisEntity;
+import org.apache.polaris.core.entity.PolarisEntityType;
+import org.apache.polaris.core.entity.PolarisPrivilege;
+import org.apache.polaris.core.persistence.PolarisResolvedPathWrapper;
+import org.apache.polaris.core.persistence.ResolvedPolarisEntity;
+import org.apache.polaris.extension.auth.ranger.RangerPolarisAuthorizer;
+import org.apache.ranger.authz.model.RangerAccessInfo;
+import org.apache.ranger.authz.model.RangerResourceInfo;
+import org.apache.ranger.authz.model.RangerUserInfo;
+import org.apache.ranger.authz.util.RangerResourceNameParser;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class RangerUtils {
+  private static final Logger LOG = LoggerFactory.getLogger(RangerUtils.class);
+
+  public static Properties loadProperties(String resourcePath) {
+    if (resourcePath == null) {
+      throw new IllegalStateException("invalid resource path: null");
+    }
+
+    resourcePath = resourcePath.trim();
+
+    if (!resourcePath.startsWith("/")) {
+      LOG.info("Prefixing / to resource path: {}", resourcePath);
+
+      resourcePath = "/" + resourcePath;
+    }
+
+    try (InputStream in = 
RangerPolarisAuthorizer.class.getResourceAsStream(resourcePath)) {
+      if (in != null) {
+        Properties prop = new Properties();
+
+        prop.load(in);
+
+        return prop;
+      } else {
+        LOG.error("Unable to find {} in the classpath", resourcePath);
+
+        throw new IllegalStateException("failed to find " + resourcePath);
+      }
+    } catch (IOException e) {
+      LOG.error("Unable to load {}", resourcePath, e);
+
+      throw new IllegalStateException("failed to load " + resourcePath);
+    }
+  }
+
+  public static String toResourceType(PolarisEntityType entityType) {
+    return switch (entityType) {
+      case ROOT -> "root";
+      case PRINCIPAL -> "principal";
+      case CATALOG -> "catalog";
+      case NAMESPACE -> "namespace";
+      case TABLE_LIKE -> "table";
+      case POLICY -> "policy";
+      default -> entityType.name(); // NULL_TYPE, PRINCIPAL_ROLE, 
CATALOG_ROLE, TASK, FILE
+    };
+  }
+
+  public static String toAccessType(PolarisPrivilege privilege) {
+    return switch (privilege) {

Review Comment:
   Authorizer SPI requires implementations to ensure that the principal is 
allowed to perform the operation on specified targets and secondaries. It seems 
reasonable to require the implementations to honor `PolarisPrivilege` 
requirements as well on targets and secondaries. An implementation can map 
multiple `PolarisPrivilege`s into a single permission or a single 
`PolarisPrivilege`to multiple permissions. It seems SPI will be incomplete 
without `PolarisPrivilege`.



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