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-960: service-def update should preserve the permission order
Date Fri, 29 Apr 2016 23:20:32 GMT
Repository: incubator-ranger
Updated Branches:
  refs/heads/ranger-0.5 0c9b8be1a -> 0fef5d866


RANGER-960: service-def update should preserve the permission order

(cherry picked from commit 1fc84ff6bd864e908ee173aff37d5b0388de2110)


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

Branch: refs/heads/ranger-0.5
Commit: 0fef5d8669a9e7404904c23d73512334b9f05c00
Parents: 0c9b8be
Author: Madhan Neethiraj <madhan@apache.org>
Authored: Thu Apr 28 22:49:45 2016 -0700
Committer: Madhan Neethiraj <madhan@apache.org>
Committed: Fri Apr 29 16:19:39 2016 -0700

----------------------------------------------------------------------
 .../org/apache/ranger/biz/ServiceDBStore.java   | 25 ++++++++++++++++----
 .../resources/META-INF/jpa_named_queries.xml    |  5 ++--
 .../apache/ranger/biz/TestServiceDBStore.java   |  7 ++++++
 3 files changed, 30 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/0fef5d86/security-admin/src/main/java/org/apache/ranger/biz/ServiceDBStore.java
----------------------------------------------------------------------
diff --git a/security-admin/src/main/java/org/apache/ranger/biz/ServiceDBStore.java b/security-admin/src/main/java/org/apache/ranger/biz/ServiceDBStore.java
index 8ec820a..70118d3 100644
--- a/security-admin/src/main/java/org/apache/ranger/biz/ServiceDBStore.java
+++ b/security-admin/src/main/java/org/apache/ranger/biz/ServiceDBStore.java
@@ -445,13 +445,15 @@ public class ServiceDBStore implements ServiceStore {
 		List<XXEnumDef> xxEnums = daoMgr.getXXEnumDef().findByServiceDefId(serviceDefId);
 
 		XXServiceConfigDefDao xxServiceConfigDao = daoMgr.getXXServiceConfigDef();
-		for (RangerServiceConfigDef config : configs) {
+		for (int i = 0; i < configs.size(); i++) {
+			RangerServiceConfigDef config = configs.get(i);
 			boolean found = false;
 			for (XXServiceConfigDef xConfig : xxConfigs) {
 				if (config.getItemId() != null && config.getItemId().equals(xConfig.getItemId()))
{
 					found = true;
 					xConfig = serviceDefService.populateRangerServiceConfigDefToXX(config, xConfig, createdSvcDef,
 							RangerServiceDefService.OPERATION_UPDATE_CONTEXT);
+					xConfig.setOrder(i);
 					xConfig = xxServiceConfigDao.update(xConfig);
 					config = serviceDefService.populateXXToRangerServiceConfigDef(xConfig);
 					break;
@@ -461,6 +463,7 @@ public class ServiceDBStore implements ServiceStore {
 				XXServiceConfigDef xConfig = new XXServiceConfigDef();
 				xConfig = serviceDefService.populateRangerServiceConfigDefToXX(config, xConfig, createdSvcDef,
 						RangerServiceDefService.OPERATION_CREATE_CONTEXT);
+				xConfig.setOrder(i);
 				xConfig = xxServiceConfigDao.create(xConfig);
 				config = serviceDefService.populateXXToRangerServiceConfigDef(xConfig);
 			}
@@ -522,13 +525,15 @@ public class ServiceDBStore implements ServiceStore {
 		}
 
 		XXAccessTypeDefDao xxATDDao = daoMgr.getXXAccessTypeDef();
-		for (RangerAccessTypeDef access : accessTypes) {
+		for(int i = 0; i < accessTypes.size(); i++) {
+			RangerAccessTypeDef access = accessTypes.get(i);
 			boolean found = false;
 			for (XXAccessTypeDef xAccess : xxAccessTypes) {
 				if (access.getItemId() != null && access.getItemId().equals(xAccess.getItemId()))
{
 					found = true;
 					xAccess = serviceDefService.populateRangerAccessTypeDefToXX(access, xAccess, createdSvcDef,
 							RangerServiceDefService.OPERATION_UPDATE_CONTEXT);
+					xAccess.setOrder(i);
 					xAccess = xxATDDao.update(xAccess);
 
 					Collection<String> impliedGrants = access.getImpliedGrants();
@@ -572,6 +577,7 @@ public class ServiceDBStore implements ServiceStore {
 				XXAccessTypeDef xAccessType = new XXAccessTypeDef();
 				xAccessType = serviceDefService.populateRangerAccessTypeDefToXX(access, xAccessType,
createdSvcDef,
 						RangerServiceDefService.OPERATION_CREATE_CONTEXT);
+				xAccessType.setOrder(i);
 				xAccessType = xxATDDao.create(xAccessType);
 
 				Collection<String> impliedGrants = access.getImpliedGrants();
@@ -606,13 +612,15 @@ public class ServiceDBStore implements ServiceStore {
 		}
 
 		XXPolicyConditionDefDao xxPolCondDao = daoMgr.getXXPolicyConditionDef();
-		for (RangerPolicyConditionDef condition : policyConditions) {
+		for (int i = 0; i < policyConditions.size(); i++) {
+			RangerPolicyConditionDef condition = policyConditions.get(i);
 			boolean found = false;
 			for (XXPolicyConditionDef xCondition : xxPolicyConditions) {
 				if (condition.getItemId() != null && condition.getItemId().equals(xCondition.getItemId()))
{
 					found = true;
 					xCondition = serviceDefService.populateRangerPolicyConditionDefToXX(condition, xCondition,
 							createdSvcDef, RangerServiceDefService.OPERATION_UPDATE_CONTEXT);
+					xCondition.setOrder(i);
 					xCondition = xxPolCondDao.update(xCondition);
 					condition = serviceDefService.populateXXToRangerPolicyConditionDef(xCondition);
 					break;
@@ -622,6 +630,7 @@ public class ServiceDBStore implements ServiceStore {
 				XXPolicyConditionDef xCondition = new XXPolicyConditionDef();
 				xCondition = serviceDefService.populateRangerPolicyConditionDefToXX(condition, xCondition,
 						createdSvcDef, RangerServiceDefService.OPERATION_CREATE_CONTEXT);
+				xCondition.setOrder(i);
 				xCondition = xxPolCondDao.create(xCondition);
 				condition = serviceDefService.populateXXToRangerPolicyConditionDef(xCondition);
 			}
@@ -650,13 +659,15 @@ public class ServiceDBStore implements ServiceStore {
 		}
 
 		XXContextEnricherDefDao xxContextEnricherDao = daoMgr.getXXContextEnricherDef();
-		for (RangerContextEnricherDef context : contextEnrichers) {
+		for (int i = 0; i < contextEnrichers.size(); i++) {
+			RangerContextEnricherDef context = contextEnrichers.get(i);
 			boolean found = false;
 			for (XXContextEnricherDef xContext : xxContextEnrichers) {
 				if (context.getItemId() != null && context.getItemId().equals(xContext.getItemId()))
{
 					found = true;
 					xContext = serviceDefService.populateRangerContextEnricherDefToXX(context, xContext,
createdSvcDef,
 							RangerServiceDefService.OPERATION_UPDATE_CONTEXT);
+					xContext.setOrder(i);
 					xContext = xxContextEnricherDao.update(xContext);
 					context = serviceDefService.populateXXToRangerContextEnricherDef(xContext);
 					break;
@@ -666,6 +677,7 @@ public class ServiceDBStore implements ServiceStore {
 				XXContextEnricherDef xContext = new XXContextEnricherDef();
 				xContext = serviceDefService.populateRangerContextEnricherDefToXX(context, xContext,
createdSvcDef,
 						RangerServiceDefService.OPERATION_UPDATE_CONTEXT);
+				xContext.setOrder(i);
 				xContext = xxContextEnricherDao.create(xContext);
 				context = serviceDefService.populateXXToRangerContextEnricherDef(xContext);
 			}
@@ -697,13 +709,15 @@ public class ServiceDBStore implements ServiceStore {
 					List<XXEnumElementDef> xxEnumEleDefs = xEnumEleDao.findByEnumDefId(xEnumDef.getId());
 					List<RangerEnumElementDef> enumEleDefs = enumDef.getElements();
 
-					for (RangerEnumElementDef eleDef : enumEleDefs) {
+					for (int i = 0; i < enumEleDefs.size(); i++) {
+						RangerEnumElementDef eleDef = enumEleDefs.get(i);
 						boolean foundEle = false;
 						for (XXEnumElementDef xEleDef : xxEnumEleDefs) {
 							if (eleDef.getItemId() != null && eleDef.getItemId().equals(xEleDef.getItemId()))
{
 								foundEle = true;
 								xEleDef = serviceDefService.populateRangerEnumElementDefToXX(eleDef, xEleDef, xEnumDef,
 										RangerServiceDefService.OPERATION_UPDATE_CONTEXT);
+								xEleDef.setOrder(i);
 								xEleDef = xEnumEleDao.update(xEleDef);
 								break;
 							}
@@ -712,6 +726,7 @@ public class ServiceDBStore implements ServiceStore {
 							XXEnumElementDef xElement = new XXEnumElementDef();
 							xElement = serviceDefService.populateRangerEnumElementDefToXX(eleDef, xElement, xEnumDef,
 									RangerServiceDefService.OPERATION_CREATE_CONTEXT);
+							xElement.setOrder(i);
 							xElement = xEnumEleDao.create(xElement);
 						}
 					}

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/0fef5d86/security-admin/src/main/resources/META-INF/jpa_named_queries.xml
----------------------------------------------------------------------
diff --git a/security-admin/src/main/resources/META-INF/jpa_named_queries.xml b/security-admin/src/main/resources/META-INF/jpa_named_queries.xml
index 1e2bf9b..8df2505 100644
--- a/security-admin/src/main/resources/META-INF/jpa_named_queries.xml
+++ b/security-admin/src/main/resources/META-INF/jpa_named_queries.xml
@@ -321,7 +321,7 @@
 
 	<!-- XXAccessTypeDef -->
 	<named-query name="XXAccessTypeDef.findByServiceDefId">
-		<query>select obj from XXAccessTypeDef obj where obj.defId = :serviceDefId</query>
+		<query>select obj from XXAccessTypeDef obj where obj.defId = :serviceDefId order
by obj.order</query>
 	</named-query>
 
 	<named-query name="XXAccessTypeDef.findByNameAndServiceId">
@@ -331,7 +331,7 @@
 
 	<!-- XXPolicyConditionDef -->
 	<named-query name="XXPolicyConditionDef.findByServiceDefId">
-		<query>select obj from XXPolicyConditionDef obj where obj.defId = :serviceDefId</query>
+		<query>select obj from XXPolicyConditionDef obj where obj.defId = :serviceDefId order
by obj.order</query>
 	</named-query>
 
 	<named-query name="XXPolicyConditionDef.findByServiceDefIdAndName">
@@ -365,6 +365,7 @@
 		<query>select obj from XXEnumDef obj where obj.defId = :serviceDefId</query>
 	</named-query>
 
+
 	<!-- XXServiceConfigMap -->
 	<named-query name="XXServiceConfigMap.findByServiceId">
 		<query>select obj from XXServiceConfigMap obj where obj.serviceId = :serviceId</query>

http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/0fef5d86/security-admin/src/test/java/org/apache/ranger/biz/TestServiceDBStore.java
----------------------------------------------------------------------
diff --git a/security-admin/src/test/java/org/apache/ranger/biz/TestServiceDBStore.java b/security-admin/src/test/java/org/apache/ranger/biz/TestServiceDBStore.java
index cc4d5a0..56a39f0 100644
--- a/security-admin/src/test/java/org/apache/ranger/biz/TestServiceDBStore.java
+++ b/security-admin/src/test/java/org/apache/ranger/biz/TestServiceDBStore.java
@@ -498,6 +498,13 @@ public class TestServiceDBStore {
 		serviceConfigDefObj.setType("1");
 		svcConfDefList.add(serviceConfigDefObj);
 
+		Mockito.when(
+				serviceDefService.populateRangerServiceConfigDefToXX(
+						Mockito.any(RangerServiceConfigDef.class), Mockito.any(XXServiceConfigDef.class), Mockito.any(XXServiceDef.class),
+						Mockito.eq(RangerServiceDefService.OPERATION_CREATE_CONTEXT))).thenReturn(serviceConfigDefObj);
+		Mockito.when(xServiceConfigDefDao.create(serviceConfigDefObj))
+				.thenReturn(serviceConfigDefObj);
+
 		List<XXResourceDef> resDefList = new ArrayList<XXResourceDef>();
 		XXResourceDef resourceDef = new XXResourceDef();
 		resourceDef.setAddedByUserId(Id);


Mime
View raw message