You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ranger.apache.org by me...@apache.org on 2017/08/24 05:52:13 UTC
[2/2] ranger git commit: RANGER-1748 : User is unable to update
existing policy while importing policy from file
RANGER-1748 : User is unable to update existing policy while importing policy from file
Project: http://git-wip-us.apache.org/repos/asf/ranger/repo
Commit: http://git-wip-us.apache.org/repos/asf/ranger/commit/053cdd7b
Tree: http://git-wip-us.apache.org/repos/asf/ranger/tree/053cdd7b
Diff: http://git-wip-us.apache.org/repos/asf/ranger/diff/053cdd7b
Branch: refs/heads/master
Commit: 053cdd7b7e367aef09ab9d6b862f86fad35de811
Parents: b9cdb0b
Author: Bhavik Patel <bh...@gmail.com>
Authored: Wed Aug 23 17:21:44 2017 +0530
Committer: Mehul Parikh <me...@apache.org>
Committed: Thu Aug 24 11:21:22 2017 +0530
----------------------------------------------------------------------
.../org/apache/ranger/rest/ServiceREST.java | 32 ++++++++++++++++----
1 file changed, 26 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ranger/blob/053cdd7b/security-admin/src/main/java/org/apache/ranger/rest/ServiceREST.java
----------------------------------------------------------------------
diff --git a/security-admin/src/main/java/org/apache/ranger/rest/ServiceREST.java b/security-admin/src/main/java/org/apache/ranger/rest/ServiceREST.java
index 38fde8a..6de8a14 100644
--- a/security-admin/src/main/java/org/apache/ranger/rest/ServiceREST.java
+++ b/security-admin/src/main/java/org/apache/ranger/rest/ServiceREST.java
@@ -1410,6 +1410,11 @@ public class ServiceREST {
String serviceName = request.getParameter(PARAM_SERVICE_NAME);
String policyName = request.getParameter(PARAM_POLICY_NAME);
String updateIfExists = request.getParameter(PARAM_UPDATE_IF_EXISTS);
+
+ if (serviceName == null && policyName == null && updateIfExists != null && updateIfExists.equalsIgnoreCase("true")){
+ serviceName = (String) request.getAttribute(PARAM_SERVICE_NAME);
+ policyName = (String) request.getAttribute(PARAM_POLICY_NAME);
+ }
if(StringUtils.isNotEmpty(serviceName)) {
policy.setService(serviceName);
@@ -1430,7 +1435,8 @@ public class ServiceREST {
existingPolicy = getPolicyByName(policy.getService(), policy.getName());
}
- if(existingPolicy != null) {
+ if (existingPolicy != null) {
+ policy.setId(existingPolicy.getId());
ret = updatePolicy(policy);
}
} catch(Exception excp) {
@@ -2010,7 +2016,13 @@ public class ServiceREST {
}
}
}
- if (isOverride){
+ String updateIfExists = request.getParameter(PARAM_UPDATE_IF_EXISTS);
+ if (updateIfExists == null || updateIfExists.isEmpty()) {
+ updateIfExists = "false";
+ } else if (updateIfExists.equalsIgnoreCase("true")) {
+ isOverride = false;
+ }
+ if (isOverride && updateIfExists.equalsIgnoreCase("false")){
if (LOG.isDebugEnabled()) {
LOG.debug("Deleting Policy from provided services in servicesMapJson file...");
}
@@ -2034,20 +2046,28 @@ public class ServiceREST {
for (String service : serviceNameList) {
if (StringUtils.isNotEmpty(service.trim()) && StringUtils.isNotEmpty(policy.getService().trim())){
if (policy.getService().trim().equalsIgnoreCase(service.trim())) {
- createPolicy(policy, null);
+ if (updateIfExists != null && !updateIfExists.isEmpty()){
+ request.setAttribute(PARAM_SERVICE_NAME, policy.getService());
+ request.setAttribute(PARAM_POLICY_NAME, policy.getName());
+ }
+ createPolicy(policy, request);
totalPolicyCreate = totalPolicyCreate + 1;
if (LOG.isDebugEnabled()) {
LOG.debug("Policy " + policy.getName() + " created successfully.");
}
break;
}
- }else{
+ } else {
LOG.error("Service Name or Policy Name is not provided!!");
throw restErrorUtil.createRESTException("Service Name or Policy Name is not provided!!");
}
}
- }else{
- createPolicy(policy, null);
+ } else {
+ if (updateIfExists != null && !updateIfExists.isEmpty()){
+ request.setAttribute(PARAM_SERVICE_NAME, policy.getService());
+ request.setAttribute(PARAM_POLICY_NAME, policy.getName());
+ }
+ createPolicy(policy, request);
totalPolicyCreate = totalPolicyCreate + 1;
if (LOG.isDebugEnabled()) {
LOG.debug("Policy " + policy.getName() + " created successfully.");