You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ranger.apache.org by ma...@apache.org on 2015/07/30 23:39:34 UTC
[5/7] incubator-ranger git commit: RANGER-590: Escape spaces in the
user and group names which are part of rest call uri in UserSync process
RANGER-590: Escape spaces in the user and group names which are part of rest call uri in UserSync process
Project: http://git-wip-us.apache.org/repos/asf/incubator-ranger/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ranger/commit/39fc361f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ranger/tree/39fc361f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ranger/diff/39fc361f
Branch: refs/heads/tag-policy
Commit: 39fc361f817da1cfaca1d21ed679134414bfda93
Parents: dcd3ea0
Author: rmani <rm...@hortonworks.com>
Authored: Thu Jul 30 14:20:29 2015 -0700
Committer: rmani <rm...@hortonworks.com>
Committed: Thu Jul 30 14:20:29 2015 -0700
----------------------------------------------------------------------
.../process/PolicyMgrUserGroupBuilder.java | 45 +++++++++++++-------
.../ranger/usersync/util/UserSyncUtil.java | 39 +++++++++++++++++
2 files changed, 68 insertions(+), 16 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/39fc361f/ugsync/src/main/java/org/apache/ranger/unixusersync/process/PolicyMgrUserGroupBuilder.java
----------------------------------------------------------------------
diff --git a/ugsync/src/main/java/org/apache/ranger/unixusersync/process/PolicyMgrUserGroupBuilder.java b/ugsync/src/main/java/org/apache/ranger/unixusersync/process/PolicyMgrUserGroupBuilder.java
index 5768f55..78e3e72 100644
--- a/ugsync/src/main/java/org/apache/ranger/unixusersync/process/PolicyMgrUserGroupBuilder.java
+++ b/ugsync/src/main/java/org/apache/ranger/unixusersync/process/PolicyMgrUserGroupBuilder.java
@@ -63,7 +63,7 @@ import org.apache.ranger.unixusersync.model.XUserGroupInfo;
import org.apache.ranger.unixusersync.model.XUserInfo;
import org.apache.ranger.unixusersync.model.UserGroupInfo;
import org.apache.ranger.usergroupsync.UserGroupSink;
-import org.mortbay.log.Log;
+import org.apache.ranger.usersync.util.UserSyncUtil;
public class PolicyMgrUserGroupBuilder implements UserGroupSink {
@@ -603,25 +603,38 @@ public class PolicyMgrUserGroupBuilder implements UserGroupSink {
}
private void delXUserGroupInfo(XUserInfo aUserInfo, XGroupInfo aGroupInfo) {
-
- Client c = getClient() ;
-
- String uri = PM_DEL_USER_GROUP_LINK_URI.replaceAll(Pattern.quote("${groupName}"), aGroupInfo.getName()).replaceAll(Pattern.quote("${userName}"), aUserInfo.getName()) ;
-
- WebResource r = c.resource(getURL(uri)) ;
-
- ClientResponse response = r.delete(ClientResponse.class) ;
-
- LOG.debug("RESPONSE: [" + response.toString() + "]") ;
+
+ String groupName = aGroupInfo.getName();
-
- if (response.getStatus() == 200) {
- delUserGroupFromList(aUserInfo, aGroupInfo) ;
- }
+ String userName = aUserInfo.getName();
+ try {
+
+ Client c = getClient() ;
+
+ String uri = PM_DEL_USER_GROUP_LINK_URI.replaceAll(Pattern.quote("${groupName}"),
+ UserSyncUtil.encodeURIParam(groupName)).replaceAll(Pattern.quote("${userName}"), UserSyncUtil.encodeURIParam(userName));
+
+ WebResource r = c.resource(getURL(uri)) ;
+
+ ClientResponse response = r.delete(ClientResponse.class) ;
+
+ if ( LOG.isDebugEnabled() ) {
+ LOG.debug("RESPONSE: [" + response.toString() + "]") ;
+ }
+
+ if (response.getStatus() == 200) {
+ delUserGroupFromList(aUserInfo, aGroupInfo) ;
+ }
+
+ } catch (Exception e) {
+
+ LOG.warn( "ERROR: Unable to delete GROUP: " + groupName + " from USER:" + userName , e) ;
+ }
+
}
-
+
private MUserInfo addMUser(String aUserName) {
MUserInfo ret = null ;
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/39fc361f/ugsync/src/main/java/org/apache/ranger/usersync/util/UserSyncUtil.java
----------------------------------------------------------------------
diff --git a/ugsync/src/main/java/org/apache/ranger/usersync/util/UserSyncUtil.java b/ugsync/src/main/java/org/apache/ranger/usersync/util/UserSyncUtil.java
new file mode 100644
index 0000000..050419d
--- /dev/null
+++ b/ugsync/src/main/java/org/apache/ranger/usersync/util/UserSyncUtil.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.ranger.usersync.util;
+
+import org.apache.commons.httpclient.URIException;
+import org.apache.commons.httpclient.util.URIUtil;
+
+public class UserSyncUtil {
+
+ public static String encodeURIParam(String s) throws URIException {
+
+ String ret = null;
+
+ try {
+ ret = URIUtil.encodeQuery(s);
+ } catch (URIException e) {
+ throw e;
+ }
+
+ return ret;
+ }
+}