ranger-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mad...@apache.org
Subject incubator-ranger git commit: RANGER-1208: Optimize tag enricher for requests containing empty resource (2)
Date Tue, 08 Nov 2016 03:00:48 GMT
Repository: incubator-ranger
Updated Branches:
  refs/heads/master 3c395a53e -> ebc63ac3f


RANGER-1208: Optimize tag enricher for requests containing empty resource (2)

Signed-off-by: Madhan Neethiraj <madhan@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/incubator-ranger/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ranger/commit/ebc63ac3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ranger/tree/ebc63ac3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ranger/diff/ebc63ac3

Branch: refs/heads/master
Commit: ebc63ac3ff26f36e577e333f022459bc44c142a0
Parents: 3c395a5
Author: Abhay Kulkarni <akulkarni@hortonworks.com>
Authored: Mon Nov 7 14:04:39 2016 -0800
Committer: Madhan Neethiraj <madhan@apache.org>
Committed: Mon Nov 7 18:59:55 2016 -0800

----------------------------------------------------------------------
 .../contextenricher/RangerTagEnricher.java      | 22 ++++++++++++--------
 .../RangerDefaultPolicyResourceMatcher.java     |  4 +---
 .../test_defaultpolicyresourcematcher.json      | 12 +++++------
 3 files changed, 20 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/ebc63ac3/agents-common/src/main/java/org/apache/ranger/plugin/contextenricher/RangerTagEnricher.java
----------------------------------------------------------------------
diff --git a/agents-common/src/main/java/org/apache/ranger/plugin/contextenricher/RangerTagEnricher.java
b/agents-common/src/main/java/org/apache/ranger/plugin/contextenricher/RangerTagEnricher.java
index 274d6be..43d501a 100644
--- a/agents-common/src/main/java/org/apache/ranger/plugin/contextenricher/RangerTagEnricher.java
+++ b/agents-common/src/main/java/org/apache/ranger/plugin/contextenricher/RangerTagEnricher.java
@@ -39,7 +39,11 @@ import org.apache.ranger.plugin.util.RangerPerfTracer;
 import org.apache.ranger.plugin.util.RangerResourceTrie;
 import org.apache.ranger.plugin.util.ServiceTags;
 
-import java.io.*;
+import java.io.File;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.Reader;
+import java.io.Writer;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
@@ -178,12 +182,12 @@ public class RangerTagEnricher extends RangerAbstractContextEnricher
{
 			}
 		}
 
-		Set<RangerTagForEval> allTagsForEval = new HashSet<RangerTagForEval>();
+		Set<RangerTagForEval> tagsForEmptyResourceAndAnyAccess = new HashSet<RangerTagForEval>();
 		for (Map.Entry<Long, RangerTag> entry : serviceTags.getTags().entrySet()) {
-			allTagsForEval.add(new RangerTagForEval(entry.getValue(), RangerPolicyResourceMatcher.MatchType.ANCESTOR));
+			tagsForEmptyResourceAndAnyAccess.add(new RangerTagForEval(entry.getValue(), RangerPolicyResourceMatcher.MatchType.ANCESTOR));
 		}
 
-		enrichedServiceTags = new EnrichedServiceTags(serviceTags, resourceMatchers, serviceResourceTrie,
allTagsForEval);
+		enrichedServiceTags = new EnrichedServiceTags(serviceTags, resourceMatchers, serviceResourceTrie,
tagsForEmptyResourceAndAnyAccess);
 	}
 
 	@Override
@@ -218,7 +222,7 @@ public class RangerTagEnricher extends RangerAbstractContextEnricher {
 		RangerAccessResource resource = request.getResource();
 
 		if ((resource == null || resource.getKeys() == null || resource.getKeys().size() == 0)
&& request.isAccessTypeAny()) {
-			ret = enrichedServiceTags.getAllTagsForEval();
+			ret = enrichedServiceTags.getTagsForEmptyResourceAndAnyAccess();
 		} else {
 
 			final List<RangerServiceResourceMatcher> serviceResourceMatchers = getEvaluators(resource,
enrichedServiceTags);
@@ -368,19 +372,19 @@ public class RangerTagEnricher extends RangerAbstractContextEnricher
{
 		final private ServiceTags                        serviceTags;
 		final private List<RangerServiceResourceMatcher> serviceResourceMatchers;
 		final private Map<String, RangerResourceTrie<RangerServiceResourceMatcher>>
   serviceResourceTrie;
-		final private Set<RangerTagForEval>              allTagsForEval;
+		final private Set<RangerTagForEval>              tagsForEmptyResourceAndAnyAccess;
// Used only when accessed resource is empty and access type is 'any'
 
 		EnrichedServiceTags(ServiceTags serviceTags, List<RangerServiceResourceMatcher> serviceResourceMatchers,
-							Map<String, RangerResourceTrie<RangerServiceResourceMatcher>> serviceResourceTrie,
Set<RangerTagForEval> allTagsForEval) {
+							Map<String, RangerResourceTrie<RangerServiceResourceMatcher>> serviceResourceTrie,
Set<RangerTagForEval> tagsForEmptyResourceAndAnyAccess) {
 			this.serviceTags             = serviceTags;
 			this.serviceResourceMatchers = serviceResourceMatchers;
 			this.serviceResourceTrie     = serviceResourceTrie;
-			this.allTagsForEval          = allTagsForEval;
+			this.tagsForEmptyResourceAndAnyAccess          = tagsForEmptyResourceAndAnyAccess;
 		}
 		ServiceTags getServiceTags() {return serviceTags;}
 		List<RangerServiceResourceMatcher> getServiceResourceMatchers() { return serviceResourceMatchers;}
 		Map<String, RangerResourceTrie<RangerServiceResourceMatcher>> getServiceResourceTrie()
{ return serviceResourceTrie;}
-		Set<RangerTagForEval> getAllTagsForEval() { return allTagsForEval;}
+		Set<RangerTagForEval> getTagsForEmptyResourceAndAnyAccess() { return tagsForEmptyResourceAndAnyAccess;}
 	}
 
 	static class RangerTagRefresher extends Thread {

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/ebc63ac3/agents-common/src/main/java/org/apache/ranger/plugin/policyresourcematcher/RangerDefaultPolicyResourceMatcher.java
----------------------------------------------------------------------
diff --git a/agents-common/src/main/java/org/apache/ranger/plugin/policyresourcematcher/RangerDefaultPolicyResourceMatcher.java
b/agents-common/src/main/java/org/apache/ranger/plugin/policyresourcematcher/RangerDefaultPolicyResourceMatcher.java
index 7b1fb8b..5e2fa74 100644
--- a/agents-common/src/main/java/org/apache/ranger/plugin/policyresourcematcher/RangerDefaultPolicyResourceMatcher.java
+++ b/agents-common/src/main/java/org/apache/ranger/plugin/policyresourcematcher/RangerDefaultPolicyResourceMatcher.java
@@ -415,10 +415,8 @@ public class RangerDefaultPolicyResourceMatcher implements RangerPolicyResourceM
 
 		if (!isValid(resource)) {
 			ret = MatchType.NONE;
-		} else if (matchersSize == 0) {
+		} else if (matchersSize == 0 || lastNonAnyMatcherIndex == 0) {
 			ret = resourceKeysSize == 0 ? MatchType.SELF : MatchType.ANCESTOR;
-		} else if (lastNonAnyMatcherIndex == 0) {
-			ret = MatchType.ANCESTOR;
 		} else if (resourceKeysSize == 0) {
 			ret = MatchType.DESCENDANT;
 		} else {

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/ebc63ac3/agents-common/src/test/resources/resourcematcher/test_defaultpolicyresourcematcher.json
----------------------------------------------------------------------
diff --git a/agents-common/src/test/resources/resourcematcher/test_defaultpolicyresourcematcher.json
b/agents-common/src/test/resources/resourcematcher/test_defaultpolicyresourcematcher.json
index 1ca9161..71995dc 100644
--- a/agents-common/src/test/resources/resourcematcher/test_defaultpolicyresourcematcher.json
+++ b/agents-common/src/test/resources/resourcematcher/test_defaultpolicyresourcematcher.json
@@ -133,8 +133,8 @@
         }
         ,
         {
-          "name": "MATCH for parent ''",
-          "type": "ancestorMatch",
+          "name": "MATCH for exact ''",
+          "type": "exactMatch",
           "resource": {
             "elements": {}
           },
@@ -371,8 +371,8 @@
         }
       ,
         {
-          "name": "MATCH for parent ''",
-          "type": "ancestorMatch",
+          "name": "MATCH for exact ''",
+          "type": "exactMatch",
           "resource": {
             "elements": {}
           },
@@ -420,8 +420,8 @@
         }
       ,
         {
-          "name": "MATCH for parent ''",
-          "type": "ancestorMatch",
+          "name": "MATCH for exact ''",
+          "type": "exactMatch",
           "resource": {
             "elements": {}
           },


Mime
View raw message