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-687: Service update should ignore user provided values for internal fields - like policyVersion
Date Fri, 16 Oct 2015 15:52:55 GMT
Repository: incubator-ranger
Updated Branches:
  refs/heads/tag-policy d734a2116 -> be03c44b6


RANGER-687: Service update should ignore user provided values for internal fields - like policyVersion


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

Branch: refs/heads/tag-policy
Commit: be03c44b6e978dea70cac629566c3826a835db6a
Parents: d734a21
Author: Madhan Neethiraj <madhan@apache.org>
Authored: Wed Oct 14 23:39:45 2015 -0700
Committer: Madhan Neethiraj <madhan@apache.org>
Committed: Fri Oct 16 08:50:34 2015 -0700

----------------------------------------------------------------------
 .../org/apache/ranger/biz/ServiceDBStore.java   | 56 ++++++++++++++++----
 1 file changed, 45 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/be03c44b/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 99e58fe..30c0897 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
@@ -1141,9 +1141,19 @@ public class ServiceDBStore extends AbstractServiceStore {
 		List<XXTrxLog> trxLogList = svcService.getTransactionLog(service, existing, RangerServiceService.OPERATION_UPDATE_CONTEXT);
 
 		boolean hasTagServiceValueChanged = false;
-		Long existingTagServiceValue = existing.getTagService();
-		String newTagServiceName = service.getTagService();
-		Long newTagServiceValue = null;
+		Long    existingTagServiceId      = existing.getTagService();
+		String  newTagServiceName         = service.getTagService(); // null for old clients; empty
string to remove existing association
+		Long    newTagServiceId           = null;
+
+		if(newTagServiceName == null) { // old client; don't update existing tagService
+			if(existingTagServiceId != null) {
+				newTagServiceName = getServiceName(existingTagServiceId);
+
+				service.setTagService(newTagServiceName);
+
+				LOG.info("ServiceDBStore.updateService(id=" + service.getId() + "; name=" + service.getName()
+ "): tagService is null; using existing tagService '" + newTagServiceName + "'");
+			}
+		}
 
 		if (StringUtils.isNotBlank(newTagServiceName)) {
 			RangerService tmp = getServiceByName(newTagServiceName);
@@ -1155,27 +1165,36 @@ public class ServiceDBStore extends AbstractServiceStore {
 				throw restErrorUtil.createRESTException("Invalid tag service name " + newTagServiceName,
MessageEnums.ERROR_CREATING_OBJECT);
 
 			} else {
-				newTagServiceValue = tmp.getId();
+				newTagServiceId = tmp.getId();
 			}
 		}
 
-		if (existingTagServiceValue == null) {
-			if (newTagServiceValue != null) {
+		if (existingTagServiceId == null) {
+			if (newTagServiceId != null) {
 				hasTagServiceValueChanged = true;
 			}
-		} else if (!existingTagServiceValue.equals(newTagServiceValue)) {
+		} else if (!existingTagServiceId.equals(newTagServiceId)) {
 			hasTagServiceValueChanged = true;
 		}
 
-		if (hasTagServiceValueChanged) {
-			service.setPolicyVersion(getNextVersion(service.getPolicyVersion()));
-		}
-
 		if(populateExistingBaseFields) {
 			svcServiceWithAssignedId.setPopulateExistingBaseFields(true);
 			service = svcServiceWithAssignedId.update(service);
 			svcServiceWithAssignedId.setPopulateExistingBaseFields(false);
 		} else {
+			service.setCreateTime(existing.getCreateTime());
+			service.setGuid(existing.getGuid());
+			service.setVersion(existing.getVersion());
+			service.setPolicyUpdateTime(existing.getPolicyUpdateTime());
+			service.setPolicyVersion(existing.getPolicyVersion());
+			service.setTagVersion(existing.getTagVersion());
+			service.setTagUpdateTime(existing.getTagUpdateTime());
+
+			if (hasTagServiceValueChanged) {
+				service.setPolicyVersion(getNextVersion(service.getPolicyVersion()));
+			}
+
+
 			service = svcService.update(service);
 		}
 
@@ -2286,4 +2305,19 @@ public class ServiceDBStore extends AbstractServiceStore {
 			}
 		}
 	}
+
+
+	private String getServiceName(Long serviceId) {
+		String ret = null;
+
+		if(serviceId != null) {
+			XXService service = daoMgr.getXXService().getById(serviceId);
+
+			if(service != null) {
+				ret = service.getName();
+			}
+		}
+
+		return ret;
+	}
 }


Mime
View raw message