ranger-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sneet...@apache.org
Subject git commit: ARGUS-67:Create/Update Knox Policy fails to save ipAddress passed
Date Fri, 19 Sep 2014 04:39:33 GMT
Repository: incubator-argus
Updated Branches:
  refs/heads/master 4f5fa69fe -> daac1c6de


ARGUS-67:Create/Update Knox Policy fails to save ipAddress passed

Signed-off-by: sneethiraj <sneethir@apache.org>


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

Branch: refs/heads/master
Commit: daac1c6def680ce8a6fc399c8b1f0dce1c4645c6
Parents: 4f5fa69
Author: vperiasamy <vperiasamy@hortonworks.com>
Authored: Thu Sep 18 00:39:45 2014 -0400
Committer: sneethiraj <sneethir@apache.org>
Committed: Fri Sep 19 00:39:21 2014 -0400

----------------------------------------------------------------------
 .../com/xasecure/service/XPolicyService.java    | 61 +++++++++++++-------
 1 file changed, 40 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-argus/blob/daac1c6d/security-admin/src/main/java/com/xasecure/service/XPolicyService.java
----------------------------------------------------------------------
diff --git a/security-admin/src/main/java/com/xasecure/service/XPolicyService.java b/security-admin/src/main/java/com/xasecure/service/XPolicyService.java
index 73ec978..4fcd90e 100644
--- a/security-admin/src/main/java/com/xasecure/service/XPolicyService.java
+++ b/security-admin/src/main/java/com/xasecure/service/XPolicyService.java
@@ -87,6 +87,8 @@ public class XPolicyService extends PublicAPIServiceBase<VXResource,
VXPolicy> {
 	XResourceService xResourceService;
 
 	String version;
+	
+	private static String uniqueKeySeparator = "_";
 
 	public XPolicyService() {
 		version = PropertiesUtil.getProperty("maven.project.version", "");
@@ -103,7 +105,13 @@ public class XPolicyService extends PublicAPIServiceBase<VXResource,
VXPolicy> {
 		vXPolicy.setRepositoryName(vXResource.getAssetName());
 		vXPolicy.setRepositoryType(AppConstants
 				.getLabelFor_AssetType(vXResource.getAssetType()));
-		vXPolicy.setPermMapList(mapPermMapToPermObj(vXResource.getPermMapList()));
+		
+		
+		List<VXPermObj> permObjList = mapPermMapToPermObj(vXResource
+				.getPermMapList());
+		if (!stringUtil.isEmpty(permObjList)) {
+			vXPolicy.setPermMapList(permObjList);
+		}
 		vXPolicy.setTables(vXResource.getTables());
 		vXPolicy.setColumnFamilies(vXResource.getColumnFamilies());
 		vXPolicy.setColumns(vXResource.getColumns());
@@ -317,9 +325,9 @@ public class XPolicyService extends PublicAPIServiceBase<VXResource,
VXPolicy> {
 						permMapList.add(vXPermMap);
 
 						StringBuilder uniqueKey = new StringBuilder();
-						uniqueKey.append(resId + "_");
-						uniqueKey.append(permFor + "_");
-						uniqueKey.append(userId + "_");
+						uniqueKey.append(resId + uniqueKeySeparator);
+						uniqueKey.append(permFor + uniqueKeySeparator);
+						uniqueKey.append(userId + uniqueKeySeparator);
 						uniqueKey.append(permType);
 						newPermMap.put(uniqueKey.toString(), vXPermMap);
 					}
@@ -354,9 +362,9 @@ public class XPolicyService extends PublicAPIServiceBase<VXResource,
VXPolicy> {
 						permMapList.add(vXPermMap);
 
 						StringBuilder uniqueKey = new StringBuilder();
-						uniqueKey.append(resId + "_");
-						uniqueKey.append(permFor + "_");
-						uniqueKey.append(grpId + "_");
+						uniqueKey.append(resId + uniqueKeySeparator);
+						uniqueKey.append(permFor + uniqueKeySeparator);
+						uniqueKey.append(grpId + uniqueKeySeparator);
 						uniqueKey.append(permType);
 						newPermMap.put(uniqueKey.toString(), vXPermMap);
 					}
@@ -396,13 +404,13 @@ public class XPolicyService extends PublicAPIServiceBase<VXResource,
VXPolicy> {
 			int permType = xxPermMap.getPermType();
 
 			StringBuilder uniqueKey = new StringBuilder();
-			uniqueKey.append(resId + "_");
-			uniqueKey.append(permFor + "_");
+			uniqueKey.append(resId + uniqueKeySeparator);
+			uniqueKey.append(permFor + uniqueKeySeparator);
 
 			if (userId != null) {
-				uniqueKey.append(userId + "_");
+				uniqueKey.append(userId + uniqueKeySeparator);
 			} else if (grpId != null) {
-				uniqueKey.append(grpId + "_");
+				uniqueKey.append(grpId + uniqueKeySeparator);
 			}
 			uniqueKey.append(permType);
 			prevPermMap.put(uniqueKey.toString(), xxPermMap);
@@ -486,6 +494,8 @@ public class XPolicyService extends PublicAPIServiceBase<VXResource,
VXPolicy> {
 		Random rand = new Random();
 
 		for (VXPermObj permObj : permObjList) {
+			
+			String ipAddress = permObj.getIpAddress();
 
 			if (!stringUtil.isEmpty(permObj.getUserList())) {
 				String permGrp = new Date() + " : " + rand.nextInt(9999);
@@ -507,6 +517,7 @@ public class XPolicyService extends PublicAPIServiceBase<VXResource,
VXPolicy> {
 						vXPermMap.setPermGroup(permGrp);
 						vXPermMap.setPermType(permType);
 						vXPermMap.setUserId(xxUser.getId());
+						vXPermMap.setIpAddress(ipAddress);
 
 						permMapList.add(vXPermMap);
 					}
@@ -535,6 +546,7 @@ public class XPolicyService extends PublicAPIServiceBase<VXResource,
VXPolicy> {
 						vXPermMap.setPermGroup(permGrp);
 						vXPermMap.setPermType(permType);
 						vXPermMap.setGroupId(xxGroup.getId());
+						vXPermMap.setIpAddress(ipAddress);
 
 						permMapList.add(vXPermMap);
 					}
@@ -564,31 +576,38 @@ public class XPolicyService extends PublicAPIServiceBase<VXResource,
VXPolicy> {
 				.searchXPermMaps(searchCriteria);
 
 		List<VXPermMap> currentPermMapList = currentPermMaps.getVXPermMaps();
-		HashMap<String, List<Integer>> userPermMap = new HashMap<String, List<Integer>>();
+		HashMap<String, List<String>> userPermMap = new HashMap<String, List<String>>();
 
 		for (VXPermMap currentPermMap : currentPermMapList) {
 			Long userId = currentPermMap.getUserId();
 			Long groupId = currentPermMap.getGroupId();
 			int permFor = currentPermMap.getPermFor();
 			int permType = currentPermMap.getPermType();
-			String uniKey = resId + "_" + permFor;
+			String ipAddress = currentPermMap.getIpAddress();
+			
+			String uniKey = resId + uniqueKeySeparator + permFor;
 			if (permFor == AppConstants.XA_PERM_FOR_GROUP) {
-				uniKey = uniKey + "_" + groupId;
+				uniKey = uniKey + uniqueKeySeparator + groupId;
 			} else if (permFor == AppConstants.XA_PERM_FOR_USER) {
-				uniKey = uniKey + "_" + userId;
+				uniKey = uniKey + uniqueKeySeparator + userId;
 			}
 
-			List<Integer> permList = userPermMap.get(uniKey);
+			List<String> permList = userPermMap.get(uniKey);
 			if (permList == null) {
-				permList = new ArrayList<Integer>();
+				permList = new ArrayList<String>();
 				userPermMap.put(uniKey, permList);
 			}
-			permList.add(permType);
+			permList.add(""+permType);
+			
+			if (stringUtil.isEmpty(ipAddress)) {
+				permList.add(ipAddress);
+			}
+			
 		}
 
 		List<List<String>> masterKeyList = new ArrayList<List<String>>();
 		List<String> proceedKeyList = new ArrayList<String>();
-		for (Entry<String, List<Integer>> upMap : userPermMap.entrySet()) {
+		for (Entry<String, List<String>> upMap : userPermMap.entrySet()) {
 
 			if (proceedKeyList.contains(upMap.getKey())) {
 				continue;
@@ -598,7 +617,7 @@ public class XPolicyService extends PublicAPIServiceBase<VXResource,
VXPolicy> {
 			keyList.add(upMap.getKey());
 			proceedKeyList.add(upMap.getKey());
 
-			for (Entry<String, List<Integer>> entry : userPermMap.entrySet()) {
+			for (Entry<String, List<String>> entry : userPermMap.entrySet()) {
 
 				if (proceedKeyList.contains(entry.getKey())) {
 					continue;
@@ -620,7 +639,7 @@ public class XPolicyService extends PublicAPIServiceBase<VXResource,
VXPolicy> {
 			for (String key : keyList) {
 
 				SearchCriteria scPermMap = new SearchCriteria();
-				String[] keyEle = StringUtils.split(key, "_");
+				String[] keyEle = StringUtils.split(key, uniqueKeySeparator);
 				if (keyEle != null && keyEle.length == 3) {
 
 					int permFor = Integer.parseInt(keyEle[1]);


Mime
View raw message