ranger-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gau...@apache.org
Subject incubator-ranger git commit: RANGER-761 : Transaction logs not getting generated under audit menu admin tab if policy name is changed
Date Fri, 04 Dec 2015 03:39:43 GMT
Repository: incubator-ranger
Updated Branches:
  refs/heads/ranger-0.5 ad5393599 -> 740fa9514


RANGER-761 : Transaction logs not getting generated under audit menu admin tab if policy name
is changed


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

Branch: refs/heads/ranger-0.5
Commit: 740fa9514fa59e2e9a07ad5110f8844551b37d5e
Parents: ad53935
Author: Gautam Borad <gautam@apache.org>
Authored: Thu Dec 3 10:20:59 2015 +0530
Committer: Gautam Borad <gautam@apache.org>
Committed: Fri Dec 4 09:09:36 2015 +0530

----------------------------------------------------------------------
 .../ranger/service/RangerPolicyService.java     | 35 ++++++++++++++++++++
 1 file changed, 35 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/740fa951/security-admin/src/main/java/org/apache/ranger/service/RangerPolicyService.java
----------------------------------------------------------------------
diff --git a/security-admin/src/main/java/org/apache/ranger/service/RangerPolicyService.java
b/security-admin/src/main/java/org/apache/ranger/service/RangerPolicyService.java
index d853972..aaadea7 100644
--- a/security-admin/src/main/java/org/apache/ranger/service/RangerPolicyService.java
+++ b/security-admin/src/main/java/org/apache/ranger/service/RangerPolicyService.java
@@ -53,6 +53,7 @@ public class RangerPolicyService extends RangerPolicyServiceBase<XXPolicy,
Range
 	
 	public static final String POLICY_RESOURCE_CLASS_FIELD_NAME = "resources";
 	public static final String POLICY_ITEM_CLASS_FIELD_NAME = "policyItems";
+	public static final String POLICY_NAME_CLASS_FIELD_NAME = "name";
 
 	static HashMap<String, VTrxLogAttr> trxLogAttrs = new HashMap<String, VTrxLogAttr>();
 	String actionCreate;
@@ -178,6 +179,8 @@ public class RangerPolicyService extends RangerPolicyServiceBase<XXPolicy,
Range
 				value = processPolicyResourcesForTrxLog(field.get(vObj));
 			} else if (fieldName.equalsIgnoreCase(POLICY_ITEM_CLASS_FIELD_NAME)) {
 				value = processPolicyItemsForTrxLog(field.get(vObj));
+			} else if (fieldName.equalsIgnoreCase(POLICY_NAME_CLASS_FIELD_NAME)){
+				value = processPolicyNameForTrxLog(field.get(vObj));
 			} else {
 				value = "" + field.get(vObj);
 			}
@@ -216,6 +219,10 @@ public class RangerPolicyService extends RangerPolicyServiceBase<XXPolicy,
Range
 					if (oldPolicy != null) {
 						oldValue = processPolicyItemsForTrxLog(oldPolicy.getPolicyItems());
 					}
+				} else if (fieldName.equalsIgnoreCase(POLICY_NAME_CLASS_FIELD_NAME)){
+					if (oldPolicy != null) {
+						oldValue = processPolicyNameForTrxLog(oldPolicy.getName());
+					}
 				}
 				if (oldValue == null || value.equalsIgnoreCase(oldValue)) {
 					return null;
@@ -229,6 +236,11 @@ public class RangerPolicyService extends RangerPolicyServiceBase<XXPolicy,
Range
 					if(compareTwoPolicyItemList(value, oldValue)) {
 						return null;
 					}
+				} else if (fieldName.equalsIgnoreCase(POLICY_NAME_CLASS_FIELD_NAME)) {
+					//compare old and new policyName
+					if(compareTwoPolicyName(value, oldValue)) {
+						return null;
+					}
 				}
 				xTrxLog.setPreviousValue(oldValue);
 				xTrxLog.setNewValue(value);
@@ -368,4 +380,27 @@ public class RangerPolicyService extends RangerPolicyServiceBase<XXPolicy,
Range
 		return ret;
 	}
 
+	private boolean compareTwoPolicyName(String value, String oldValue) {
+		if (value==null && oldValue==null) {
+			return org.apache.commons.lang.StringUtils.equals(value, oldValue);
+		}
+		if (value!=null && oldValue!=null && value.trim().isEmpty() &&
oldValue.trim().isEmpty()) {
+			return true;
+		}
+		if (stringUtil.isEmpty(value) || stringUtil.isEmpty(oldValue)) {
+			return false;
+		}
+		if(!value.equals(oldValue)) {
+			return false;
+		}
+		return true;
+	}
+
+	private String processPolicyNameForTrxLog(Object value) {
+		if (value == null) {
+			return "";
+		}
+		String name = (String) value;
+		return name;
+	}
 }


Mime
View raw message