jerqi commented on code in PR #6100:
URL: https://github.com/apache/gravitino/pull/6100#discussion_r1904993869


##########
authorizations/authorization-ranger/src/main/java/org/apache/gravitino/authorization/ranger/RangerAuthorizationHDFSPlugin.java:
##########
@@ -118,27 +128,319 @@ public List<String> policyResourceDefinesRule() {
     return ImmutableList.of(RangerDefines.PolicyResource.PATH.getName());
   }
 
+  String getAuthorizationPath(PathBasedMetadataObject pathBasedMetadataObject) 
{
+    return HDFS_PATTERN.matcher(pathBasedMetadataObject.path()).replaceAll("");
+  }
+
+  /**
+   * Find the managed policy for the ranger securable object.
+   *
+   * @param authzMetadataObject The ranger securable object to find the 
managed policy.
+   * @return The managed policy for the metadata object.
+   */
+  public RangerPolicy findManagedPolicy(AuthorizationMetadataObject 
authzMetadataObject)
+      throws AuthorizationPluginException {
+    List<RangerPolicy> policies = wildcardSearchPolies(authzMetadataObject);
+    if (!policies.isEmpty()) {
+      /**
+       * Because Ranger doesn't support the precise search, Ranger will return 
the policy meets the
+       * wildcard(*,?) conditions, If you use `/a/b` condition to search 
policy, the Ranger will
+       * match `/a/b1`, `/a/b2`, `/a/b*`, So we need to manually precisely 
filter this research
+       * results.
+       */
+      List<String> nsMetadataObj = authzMetadataObject.names();
+      PathBasedMetadataObject pathAuthzMetadataObject =
+          (PathBasedMetadataObject) authzMetadataObject;
+      Map<String, String> preciseFilters = new HashMap<>();
+      for (int i = 0; i < nsMetadataObj.size() && i < 
policyResourceDefinesRule().size(); i++) {
+        preciseFilters.put(
+            policyResourceDefinesRule().get(i), 
getAuthorizationPath(pathAuthzMetadataObject));
+      }
+      policies =
+          policies.stream()
+              .filter(
+                  policy ->
+                      policy.getResources().entrySet().stream()
+                          .allMatch(
+                              entry ->
+                                  preciseFilters.containsKey(entry.getKey())
+                                      && entry.getValue().getValues().size() 
== 1

Review Comment:
   Maybe some resource isn't managed by Gravitino, is it?



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