This is an automated email from the ASF dual-hosted git repository.
vel pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ranger.git
The following commit(s) were added to refs/heads/master by this push:
new d65abd8 RANGER-2772 : Adding the functionality of merging the policy
d65abd8 is described below
commit d65abd8c4f7a5297f376c167f5f31b57e68bf601
Author: Dineshkumar Yadav <[email protected]>
AuthorDate: Wed Apr 1 13:39:16 2020 +0530
RANGER-2772 : Adding the functionality of merging the policy
Signed-off-by: Velmurugan Periasamy <[email protected]>
---
.../main/java/org/apache/ranger/rest/ServiceREST.java | 18 ++++++++++++++----
1 file changed, 14 insertions(+), 4 deletions(-)
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 8618f32..38b4982 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
@@ -1660,7 +1660,8 @@ public class ServiceREST {
deleteExactMatchPolicyForResource(policies, request.getRemoteUser(), null);
}
boolean
updateIfExists=("true".equalsIgnoreCase(StringUtils.trimToEmpty(request.getParameter(PARAM_UPDATE_IF_EXISTS))))
? true : false ;
- if(updateIfExists) {
+ boolean mergeIfExists =
"true".equalsIgnoreCase(StringUtils.trimToEmpty(request.getParameter(PARAM_MERGE_IF_EXISTS)))
? true : false;
+ if(updateIfExists || mergeIfExists) {
RangerPolicy existingPolicy = null;
String serviceName =
request.getParameter(PARAM_SERVICE_NAME);
if (serviceName == null) {
@@ -1698,11 +1699,20 @@ public class ServiceREST {
}
try {
if (existingPolicy != null) {
-
policy.setId(existingPolicy.getId());
- ret =
updatePolicy(policy);
+ if (updateIfExists) {
+
policy.setId(existingPolicy.getId());
+ ret =
updatePolicy(policy);
+ } else
if(mergeIfExists){
+
ServiceRESTUtil.mergeExactMatchPolicyForResource(existingPolicy, policy);
+ ret =
updatePolicy(existingPolicy);
+ }
}
} catch (Exception excp){
- LOG.error("updatePolicy(" +
policy + ") failed", excp);
+ if(updateIfExists) {
+
LOG.error("updatePolicy(" + policy + ") failed", excp);
+ }else if(mergeIfExists) {
+ LOG.error("updatePolicy
for merge (" + existingPolicy + ") failed", excp);
+ }
throw
restErrorUtil.createRESTException(excp.getMessage());
}
}