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-203: Added RangerResource.getValueAsString(); updates to use StringUtils methods, instead of calling equals()/isEmpty() directly on String objects.
Date Tue, 06 Jan 2015 03:49:38 GMT
Repository: incubator-ranger
Updated Branches:
  refs/heads/stack 29747dcd6 -> 4701f98c5


RANGER-203: Added RangerResource.getValueAsString(); updates to use
StringUtils methods, instead of calling equals()/isEmpty() directly on
String objects.

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

Branch: refs/heads/stack
Commit: 4701f98c513efb73f8cfecd47bf209b31fe9c568
Parents: 29747dc
Author: Madhan Neethiraj <madhan@apache.org>
Authored: Mon Jan 5 19:49:18 2015 -0800
Committer: Madhan Neethiraj <madhan@apache.org>
Committed: Mon Jan 5 19:49:18 2015 -0800

----------------------------------------------------------------------
 .../plugin/model/RangerBaseModelObject.java     |  2 -
 .../plugin/policyengine/RangerAccessResult.java |  7 +---
 .../policyengine/RangerMutableResource.java     |  1 -
 .../plugin/policyengine/RangerPolicyEngine.java |  3 ++
 .../policyengine/RangerPolicyEngineImpl.java    | 11 +++++-
 .../plugin/policyengine/RangerResource.java     |  5 ++-
 .../plugin/policyengine/RangerResourceImpl.java | 40 +++++++++++++++++++-
 .../RangerDefaultPolicyEvaluator.java           | 10 ++---
 .../policyevaluator/RangerPolicyEvaluator.java  |  2 -
 .../RangerAbstractResourceMatcher.java          | 20 +++++-----
 .../RangerDefaultResourceMatcher.java           |  4 +-
 .../RangerPathResourceMatcher.java              |  5 ++-
 .../plugin/store/file/ServiceDefFileStore.java  |  5 ++-
 .../plugin/store/file/ServiceFileStore.java     | 17 +++++----
 14 files changed, 88 insertions(+), 44 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/4701f98c/plugin-common/src/main/java/org/apache/ranger/plugin/model/RangerBaseModelObject.java
----------------------------------------------------------------------
diff --git a/plugin-common/src/main/java/org/apache/ranger/plugin/model/RangerBaseModelObject.java
b/plugin-common/src/main/java/org/apache/ranger/plugin/model/RangerBaseModelObject.java
index 85bbb3e..b5642ce 100644
--- a/plugin-common/src/main/java/org/apache/ranger/plugin/model/RangerBaseModelObject.java
+++ b/plugin-common/src/main/java/org/apache/ranger/plugin/model/RangerBaseModelObject.java
@@ -20,8 +20,6 @@
 package org.apache.ranger.plugin.model;
 
 import java.util.Date;
-import java.util.Map;
-import java.util.UUID;
 
 import javax.xml.bind.annotation.XmlAccessType;
 import javax.xml.bind.annotation.XmlAccessorType;

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/4701f98c/plugin-common/src/main/java/org/apache/ranger/plugin/policyengine/RangerAccessResult.java
----------------------------------------------------------------------
diff --git a/plugin-common/src/main/java/org/apache/ranger/plugin/policyengine/RangerAccessResult.java
b/plugin-common/src/main/java/org/apache/ranger/plugin/policyengine/RangerAccessResult.java
index 5d7db60..a5a1ef3 100644
--- a/plugin-common/src/main/java/org/apache/ranger/plugin/policyengine/RangerAccessResult.java
+++ b/plugin-common/src/main/java/org/apache/ranger/plugin/policyengine/RangerAccessResult.java
@@ -99,21 +99,18 @@ public class RangerAccessResult {
 
 		if(accessTypeResults != null) {
 			int numAllowed = 0;
-			int numDenied  = 0;
 
 			for(Map.Entry<String, ResultDetail> e : accessTypeResults.entrySet()) {
 				ResultDetail result = e.getValue();
 				
 				if(result.isAllowed) {
 					numAllowed++;
-				} else {
-					numDenied++;
 				}
 			}
 			
 			if(numAllowed == accessTypeResults.size()) {
 				ret = Result.ALLOWED;
-			} else if(numDenied == accessTypeResults.size()) {
+			} else if(numAllowed == 0) {
 				ret = Result.DENIED;
 			} else {
 				ret = Result.PARTIALLY_ALLOWED;
@@ -180,7 +177,7 @@ public class RangerAccessResult {
 		public ResultDetail() {
 			setIsAllowed(false);
 			setIsAudited(false);
-			setPolicyId(-1);
+			setPolicyId(RangerPolicyEngine.UNKNOWN_POLICY);
 			setReason(null);
 		}
 

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/4701f98c/plugin-common/src/main/java/org/apache/ranger/plugin/policyengine/RangerMutableResource.java
----------------------------------------------------------------------
diff --git a/plugin-common/src/main/java/org/apache/ranger/plugin/policyengine/RangerMutableResource.java
b/plugin-common/src/main/java/org/apache/ranger/plugin/policyengine/RangerMutableResource.java
index fb3c331..98ff4ba 100644
--- a/plugin-common/src/main/java/org/apache/ranger/plugin/policyengine/RangerMutableResource.java
+++ b/plugin-common/src/main/java/org/apache/ranger/plugin/policyengine/RangerMutableResource.java
@@ -19,7 +19,6 @@
 
 package org.apache.ranger.plugin.policyengine;
 
-import java.util.Collection;
 
 public interface RangerMutableResource extends RangerResource {
 	void setOwnerUser(String ownerUser);

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/4701f98c/plugin-common/src/main/java/org/apache/ranger/plugin/policyengine/RangerPolicyEngine.java
----------------------------------------------------------------------
diff --git a/plugin-common/src/main/java/org/apache/ranger/plugin/policyengine/RangerPolicyEngine.java
b/plugin-common/src/main/java/org/apache/ranger/plugin/policyengine/RangerPolicyEngine.java
index fd48ca1..5b0228f 100644
--- a/plugin-common/src/main/java/org/apache/ranger/plugin/policyengine/RangerPolicyEngine.java
+++ b/plugin-common/src/main/java/org/apache/ranger/plugin/policyengine/RangerPolicyEngine.java
@@ -25,6 +25,9 @@ import org.apache.ranger.plugin.model.RangerPolicy;
 import org.apache.ranger.plugin.model.RangerServiceDef;
 
 public interface RangerPolicyEngine {
+	public static final String GROUP_PUBLIC   = "public";
+	public static final long   UNKNOWN_POLICY = -1;
+
 	void setPolicies(RangerServiceDef serviceDef, List<RangerPolicy> policies);
 
 	RangerAccessResult isAccessAllowed(RangerAccessRequest request);

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/4701f98c/plugin-common/src/main/java/org/apache/ranger/plugin/policyengine/RangerPolicyEngineImpl.java
----------------------------------------------------------------------
diff --git a/plugin-common/src/main/java/org/apache/ranger/plugin/policyengine/RangerPolicyEngineImpl.java
b/plugin-common/src/main/java/org/apache/ranger/plugin/policyengine/RangerPolicyEngineImpl.java
index 1f4b2a2..1df9298 100644
--- a/plugin-common/src/main/java/org/apache/ranger/plugin/policyengine/RangerPolicyEngineImpl.java
+++ b/plugin-common/src/main/java/org/apache/ranger/plugin/policyengine/RangerPolicyEngineImpl.java
@@ -36,16 +36,23 @@ import org.apache.ranger.plugin.policyevaluator.RangerPolicyEvaluator;
 public class RangerPolicyEngineImpl implements RangerPolicyEngine {
 	private static final Log LOG = LogFactory.getLog(RangerPolicyEngineImpl.class);
 
+	private boolean                     autoAuditEnabled = true;
 	private List<RangerPolicyEvaluator> policyEvaluators = null;
 
 
 	public RangerPolicyEngineImpl() {
+		this(true);
+	}
+
+	public RangerPolicyEngineImpl(boolean autoAuditEnabled) {
 		if(LOG.isDebugEnabled()) {
-			LOG.debug("==> RangerPolicyEngineImpl()");
+			LOG.debug("==> RangerPolicyEngineImpl(" + autoAuditEnabled + ")");
 		}
 
+		this.autoAuditEnabled = autoAuditEnabled;
+
 		if(LOG.isDebugEnabled()) {
-			LOG.debug("<== RangerPolicyEngineImpl()");
+			LOG.debug("<== RangerPolicyEngineImpl(" + autoAuditEnabled + ")");
 		}
 	}
 	

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/4701f98c/plugin-common/src/main/java/org/apache/ranger/plugin/policyengine/RangerResource.java
----------------------------------------------------------------------
diff --git a/plugin-common/src/main/java/org/apache/ranger/plugin/policyengine/RangerResource.java
b/plugin-common/src/main/java/org/apache/ranger/plugin/policyengine/RangerResource.java
index 03ae5fc..366837d 100644
--- a/plugin-common/src/main/java/org/apache/ranger/plugin/policyengine/RangerResource.java
+++ b/plugin-common/src/main/java/org/apache/ranger/plugin/policyengine/RangerResource.java
@@ -19,7 +19,8 @@
 
 package org.apache.ranger.plugin.policyengine;
 
-import java.util.Collection;
+import org.apache.ranger.plugin.model.RangerServiceDef;
+
 
 public interface RangerResource {
 	public abstract String getOwnerUser();
@@ -27,4 +28,6 @@ public interface RangerResource {
 	public abstract boolean elementExists(String type);
 
 	public abstract String getElementValue(String type);
+
+	public abstract String getValueAsString(RangerServiceDef serviceDef);
 }

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/4701f98c/plugin-common/src/main/java/org/apache/ranger/plugin/policyengine/RangerResourceImpl.java
----------------------------------------------------------------------
diff --git a/plugin-common/src/main/java/org/apache/ranger/plugin/policyengine/RangerResourceImpl.java
b/plugin-common/src/main/java/org/apache/ranger/plugin/policyengine/RangerResourceImpl.java
index fc13cdf..684afb8 100644
--- a/plugin-common/src/main/java/org/apache/ranger/plugin/policyengine/RangerResourceImpl.java
+++ b/plugin-common/src/main/java/org/apache/ranger/plugin/policyengine/RangerResourceImpl.java
@@ -22,8 +22,14 @@ package org.apache.ranger.plugin.policyengine;
 import java.util.HashMap;
 import java.util.Map;
 
+import org.apache.commons.lang.StringUtils;
+import org.apache.ranger.plugin.model.RangerServiceDef;
+import org.apache.ranger.plugin.model.RangerServiceDef.RangerResourceDef;
+
 
 public class RangerResourceImpl implements RangerMutableResource {
+	private static final String RESOURCE_SEP = "/";
+
 	private String              ownerUser = null;
 	private Map<String, String> elements  = null;
 
@@ -53,13 +59,45 @@ public class RangerResourceImpl implements RangerMutableResource {
 	}
 
 	@Override
+	public String getValueAsString(RangerServiceDef serviceDef) {
+		String ret = null;
+
+		if(elements != null && serviceDef != null && serviceDef.getResources()
!= null) {
+			StringBuilder sb = new StringBuilder();
+
+			for(RangerResourceDef resourceDef : serviceDef.getResources()) {
+				if(resourceDef == null) {
+					continue;
+				}
+
+				String value = getElementValue(resourceDef.getName());
+
+				if(StringUtils.isEmpty(value)) {
+					continue;
+				}
+
+				if(sb.length() > 0) {
+					sb.append(RESOURCE_SEP);
+				}
+
+				sb.append(value);
+			}
+
+			if(sb.length() > 0) {
+				ret = sb.toString();
+			}
+		}
+
+		return ret;
+	}
+
+	@Override
 	public void setOwnerUser(String ownerUser) {
 		this.ownerUser = ownerUser;
 	}
 
 	@Override
 	public void setElement(String type, String value) {
-		// TODO: verify that leafElementType != type
 		if(elements == null) {
 			elements = new HashMap<String, String>();
 		}

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/4701f98c/plugin-common/src/main/java/org/apache/ranger/plugin/policyevaluator/RangerDefaultPolicyEvaluator.java
----------------------------------------------------------------------
diff --git a/plugin-common/src/main/java/org/apache/ranger/plugin/policyevaluator/RangerDefaultPolicyEvaluator.java
b/plugin-common/src/main/java/org/apache/ranger/plugin/policyevaluator/RangerDefaultPolicyEvaluator.java
index 05fd334..de8bdd1 100644
--- a/plugin-common/src/main/java/org/apache/ranger/plugin/policyevaluator/RangerDefaultPolicyEvaluator.java
+++ b/plugin-common/src/main/java/org/apache/ranger/plugin/policyevaluator/RangerDefaultPolicyEvaluator.java
@@ -36,7 +36,7 @@ import org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyResource;
 import org.apache.ranger.plugin.model.RangerServiceDef.RangerResourceDef;
 import org.apache.ranger.plugin.policyengine.RangerAccessRequest;
 import org.apache.ranger.plugin.policyengine.RangerAccessResult;
-import org.apache.ranger.plugin.policyengine.RangerAccessResult.Result;
+import org.apache.ranger.plugin.policyengine.RangerPolicyEngine;
 import org.apache.ranger.plugin.policyengine.RangerResource;
 import org.apache.ranger.plugin.resourcematcher.RangerDefaultResourceMatcher;
 import org.apache.ranger.plugin.resourcematcher.RangerResourceMatcher;
@@ -176,7 +176,7 @@ public class RangerDefaultPolicyEvaluator extends RangerAbstractPolicyEvaluator
 			}
 	
 			if(!ret && groups != null && policyItem.getGroups() != null) {
-				ret = policyItem.getGroups().contains(GROUP_PUBLIC) ||
+				ret = policyItem.getGroups().contains(RangerPolicyEngine.GROUP_PUBLIC) ||
 						!Collections.disjoint(policyItem.getGroups(), groups);
 			}
 		}
@@ -214,7 +214,7 @@ public class RangerDefaultPolicyEvaluator extends RangerAbstractPolicyEvaluator
 
 		if(policyItem != null && accessType != null && policyItem.getAccesses()
!= null) {
 			for(RangerPolicyItemAccess access : policyItem.getAccesses()) {
-				if(accessType.equalsIgnoreCase(access.getType())) {
+				if(StringUtils.equalsIgnoreCase(accessType, access.getType())) {
 					ret = access;
 
 					break;
@@ -240,7 +240,7 @@ public class RangerDefaultPolicyEvaluator extends RangerAbstractPolicyEvaluator
 
 		if(serviceDef != null && resourceType != null) {
 			for(RangerResourceDef resourceDef : serviceDef.getResources()) {
-				if(resourceType.equalsIgnoreCase(resourceDef.getName())) {
+				if(StringUtils.equalsIgnoreCase(resourceType, resourceDef.getName())) {
 					ret = resourceDef;
 
 					break;
@@ -265,7 +265,7 @@ public class RangerDefaultPolicyEvaluator extends RangerAbstractPolicyEvaluator
 		String clsName = resourceDef != null ? resourceDef.getMatcher() : null;
 		String options = resourceDef != null ? resourceDef.getMatcherOptions() : null;
 
-		if(clsName == null || clsName.isEmpty()) {
+		if(StringUtils.isEmpty(clsName)) {
 			ret = new RangerDefaultResourceMatcher();
 		} else {
 			try {

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/4701f98c/plugin-common/src/main/java/org/apache/ranger/plugin/policyevaluator/RangerPolicyEvaluator.java
----------------------------------------------------------------------
diff --git a/plugin-common/src/main/java/org/apache/ranger/plugin/policyevaluator/RangerPolicyEvaluator.java
b/plugin-common/src/main/java/org/apache/ranger/plugin/policyevaluator/RangerPolicyEvaluator.java
index 54efb15..b6e0f10 100644
--- a/plugin-common/src/main/java/org/apache/ranger/plugin/policyevaluator/RangerPolicyEvaluator.java
+++ b/plugin-common/src/main/java/org/apache/ranger/plugin/policyevaluator/RangerPolicyEvaluator.java
@@ -25,8 +25,6 @@ import org.apache.ranger.plugin.policyengine.RangerAccessRequest;
 import org.apache.ranger.plugin.policyengine.RangerAccessResult;
 
 public interface RangerPolicyEvaluator {
-	public static final String GROUP_PUBLIC = "public";
-
 	void init(RangerPolicy policy, RangerServiceDef serviceDef);
 
 	RangerPolicy getPolicy();

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/4701f98c/plugin-common/src/main/java/org/apache/ranger/plugin/resourcematcher/RangerAbstractResourceMatcher.java
----------------------------------------------------------------------
diff --git a/plugin-common/src/main/java/org/apache/ranger/plugin/resourcematcher/RangerAbstractResourceMatcher.java
b/plugin-common/src/main/java/org/apache/ranger/plugin/resourcematcher/RangerAbstractResourceMatcher.java
index 500650c..68ff85a 100644
--- a/plugin-common/src/main/java/org/apache/ranger/plugin/resourcematcher/RangerAbstractResourceMatcher.java
+++ b/plugin-common/src/main/java/org/apache/ranger/plugin/resourcematcher/RangerAbstractResourceMatcher.java
@@ -22,6 +22,7 @@ package org.apache.ranger.plugin.resourcematcher;
 import java.util.HashMap;
 import java.util.Map;
 
+import org.apache.commons.lang.StringUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyResource;
@@ -55,23 +56,20 @@ public abstract class RangerAbstractResourceMatcher implements RangerResourceMat
 
 		if(optionsString != null) {
 			for(String optionString : optionsString.split(OPTIONS_SEP)) {
-				if(optionString == null) {
+				if(StringUtils.isEmpty(optionString)) {
 					continue;
 				}
-				optionString = optionString.trim();
 
-				if(!optionString.isEmpty()) {
-					String[] nvArr = optionString.split(OPTION_NV_SEP);
+				String[] nvArr = optionString.split(OPTION_NV_SEP);
 
-					String name  = (nvArr != null && nvArr.length > 0) ? nvArr[0].trim() : null;
-					String value = (nvArr != null && nvArr.length > 1) ? nvArr[1].trim() : null;
+				String name  = (nvArr != null && nvArr.length > 0) ? nvArr[0].trim() : null;
+				String value = (nvArr != null && nvArr.length > 1) ? nvArr[1].trim() : null;
 
-					if(name == null || name.isEmpty()) {
-						continue;
-					}
-
-					options.put(name, value);
+				if(StringUtils.isEmpty(name)) {
+					continue;
 				}
+
+				options.put(name, value);
 			}
 		}
 

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/4701f98c/plugin-common/src/main/java/org/apache/ranger/plugin/resourcematcher/RangerDefaultResourceMatcher.java
----------------------------------------------------------------------
diff --git a/plugin-common/src/main/java/org/apache/ranger/plugin/resourcematcher/RangerDefaultResourceMatcher.java
b/plugin-common/src/main/java/org/apache/ranger/plugin/resourcematcher/RangerDefaultResourceMatcher.java
index cf35131..af413ff 100644
--- a/plugin-common/src/main/java/org/apache/ranger/plugin/resourcematcher/RangerDefaultResourceMatcher.java
+++ b/plugin-common/src/main/java/org/apache/ranger/plugin/resourcematcher/RangerDefaultResourceMatcher.java
@@ -21,8 +21,8 @@ package org.apache.ranger.plugin.resourcematcher;
 
 import java.util.ArrayList;
 import java.util.List;
-import java.util.Map;
 
+import org.apache.commons.lang.StringUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyResource;
@@ -86,7 +86,7 @@ public class RangerDefaultResourceMatcher extends RangerAbstractResourceMatcher
 			}
 
 			for(String policyValue : policyValues) {
-				ret = optWildCard ? resource.matches(policyValue) : resource.equals(policyValue);
+				ret = optWildCard ? resource.matches(policyValue) : StringUtils.equals(resource, policyValue);
 
 				if(ret) {
 					break;

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/4701f98c/plugin-common/src/main/java/org/apache/ranger/plugin/resourcematcher/RangerPathResourceMatcher.java
----------------------------------------------------------------------
diff --git a/plugin-common/src/main/java/org/apache/ranger/plugin/resourcematcher/RangerPathResourceMatcher.java
b/plugin-common/src/main/java/org/apache/ranger/plugin/resourcematcher/RangerPathResourceMatcher.java
index fea3610..d5c2f6f 100644
--- a/plugin-common/src/main/java/org/apache/ranger/plugin/resourcematcher/RangerPathResourceMatcher.java
+++ b/plugin-common/src/main/java/org/apache/ranger/plugin/resourcematcher/RangerPathResourceMatcher.java
@@ -23,6 +23,7 @@ import java.util.ArrayList;
 import java.util.List;
 
 import org.apache.commons.io.FilenameUtils;
+import org.apache.commons.lang.StringUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.ranger.plugin.model.RangerPolicy.RangerPolicyResource;
@@ -86,9 +87,9 @@ public class RangerPathResourceMatcher extends RangerAbstractResourceMatcher
{
 
 			for(String policyValue : policyValues) {
 				if(policyIsRecursive) {
-					ret = optWildCard ? isRecursiveWildCardMatch(resource, policyValue) : resource.startsWith(policyValue);
+					ret = optWildCard ? isRecursiveWildCardMatch(resource, policyValue) : StringUtils.startsWith(resource,
policyValue);
 				} else {
-					ret = optWildCard ? FilenameUtils.wildcardMatch(resource, policyValue) : resource.equals(policyValue);
+					ret = optWildCard ? FilenameUtils.wildcardMatch(resource, policyValue) : StringUtils.equals(resource,
policyValue);
 				}
 
 				if(ret) {

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/4701f98c/plugin-common/src/main/java/org/apache/ranger/plugin/store/file/ServiceDefFileStore.java
----------------------------------------------------------------------
diff --git a/plugin-common/src/main/java/org/apache/ranger/plugin/store/file/ServiceDefFileStore.java
b/plugin-common/src/main/java/org/apache/ranger/plugin/store/file/ServiceDefFileStore.java
index 08c253f..5f6fabf 100644
--- a/plugin-common/src/main/java/org/apache/ranger/plugin/store/file/ServiceDefFileStore.java
+++ b/plugin-common/src/main/java/org/apache/ranger/plugin/store/file/ServiceDefFileStore.java
@@ -24,6 +24,7 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
+import org.apache.commons.lang.StringUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.hadoop.fs.Path;
@@ -120,7 +121,7 @@ public class ServiceDefFileStore extends BaseFileStore implements ServiceDefStor
 
 		String existingName = existing.getName();
 
-		boolean renamed = !serviceDef.getName().equalsIgnoreCase(existingName);
+		boolean renamed = !StringUtils.equalsIgnoreCase(serviceDef.getName(), existingName);
 
 		// renaming service-def would require updating services that refer to this service-def
 		if(renamed) {
@@ -325,7 +326,7 @@ public class ServiceDefFileStore extends BaseFileStore implements ServiceDefStor
 		RangerServiceDef ret = null;
 
 		for(RangerServiceDef sd : serviceDefs) {
-			if(sd != null && sd.getName() != null && sd.getName().equalsIgnoreCase(sdName))
{
+			if(sd != null && StringUtils.equalsIgnoreCase(sd.getName(), sdName)) {
 				ret = sd;
 
 				break;

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/4701f98c/plugin-common/src/main/java/org/apache/ranger/plugin/store/file/ServiceFileStore.java
----------------------------------------------------------------------
diff --git a/plugin-common/src/main/java/org/apache/ranger/plugin/store/file/ServiceFileStore.java
b/plugin-common/src/main/java/org/apache/ranger/plugin/store/file/ServiceFileStore.java
index 789cc3a..85524db 100644
--- a/plugin-common/src/main/java/org/apache/ranger/plugin/store/file/ServiceFileStore.java
+++ b/plugin-common/src/main/java/org/apache/ranger/plugin/store/file/ServiceFileStore.java
@@ -22,6 +22,7 @@ package org.apache.ranger.plugin.store.file;
 import java.util.ArrayList;
 import java.util.List;
 
+import org.apache.commons.lang.StringUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.hadoop.fs.Path;
@@ -97,7 +98,7 @@ public class ServiceFileStore extends BaseFileStore implements ServiceStore
{
 
 		String existingName = existing.getName();
 
-		boolean renamed = !service.getName().equalsIgnoreCase(existingName);
+		boolean renamed = !StringUtils.equalsIgnoreCase(service.getName(), existingName);
 		
 		if(renamed) {
 			RangerService newNameService = getByName(service.getName());
@@ -201,9 +202,9 @@ public class ServiceFileStore extends BaseFileStore implements ServiceStore
{
 
 			if(services != null) {
 				for(RangerService service : services) {
-					if(service.getName().equalsIgnoreCase(name)) {
+					if(StringUtils.equalsIgnoreCase(service.getName(), name)) {
 						ret = service;
-	
+
 						break;
 					}
 				}
@@ -299,11 +300,11 @@ public class ServiceFileStore extends BaseFileStore implements ServiceStore
{
 			throw new Exception("service does not exist - name=" + policy.getService());
 		}
 
-		if(! existing.getService().equalsIgnoreCase(policy.getService())) {
+		if(! StringUtils.equalsIgnoreCase(existing.getService(), policy.getService())) {
 			throw new Exception("policy id=" + policy.getId() + " already exists in service " + existing.getService()
+ ". It can not be moved to service " + policy.getService());
 		}
 
-		boolean renamed = !policy.getName().equalsIgnoreCase(existing.getName());
+		boolean renamed = !StringUtils.equalsIgnoreCase(policy.getName(), existing.getName());
 		
 		if(renamed) {
 			RangerPolicy newNamePolicy = getPolicyByName(service.getName(), policy.getName());
@@ -421,7 +422,7 @@ public class ServiceFileStore extends BaseFileStore implements ServiceStore
{
 
 			if(policies != null) {
 				for(RangerPolicy policy : policies) {
-					if(policy.getName().equals(policyName)) {
+					if(StringUtils.equals(policy.getName(), policyName)) {
 						ret = policy;
 
 						break;
@@ -458,7 +459,7 @@ public class ServiceFileStore extends BaseFileStore implements ServiceStore
{
 
 			if(policies != null) {
 				for(RangerPolicy policy : policies) {
-					if(policy.getService().equals(serviceName)) {
+					if(StringUtils.equals(policy.getService(), serviceName)) {
 						ret.add(policy);
 					}
 				}
@@ -544,7 +545,7 @@ public class ServiceFileStore extends BaseFileStore implements ServiceStore
{
 
 		if(policies != null) {
 			for(RangerPolicy policy : policies) {
-				if(policy.getService().equalsIgnoreCase(oldName)) {
+				if(StringUtils.equalsIgnoreCase(policy.getService(), oldName)) {
 					policy.setService(service.getName());
 	
 					preUpdate(policy);


Mime
View raw message