You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ranger.apache.org by ve...@apache.org on 2016/08/12 04:37:46 UTC

incubator-ranger git commit: RANGER-1147:Knox repository test connection is failing

Repository: incubator-ranger
Updated Branches:
  refs/heads/master cc1bb5a95 -> b0d21cffb


RANGER-1147:Knox repository test connection is failing

Signed-off-by: Velmurugan Periasamy <ve...@apache.org>


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

Branch: refs/heads/master
Commit: b0d21cffb94d50e6f5e2ea247a39d13fa33d52e4
Parents: cc1bb5a
Author: pradeep agrawal <pr...@freestoneinfotech.com>
Authored: Fri Aug 12 09:09:45 2016 +0530
Committer: Velmurugan Periasamy <ve...@apache.org>
Committed: Fri Aug 12 10:07:30 2016 +0530

----------------------------------------------------------------------
 .../ranger/services/knox/client/KnoxClient.java | 27 ++++++++++++++++++--
 1 file changed, 25 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/b0d21cff/knox-agent/src/main/java/org/apache/ranger/services/knox/client/KnoxClient.java
----------------------------------------------------------------------
diff --git a/knox-agent/src/main/java/org/apache/ranger/services/knox/client/KnoxClient.java b/knox-agent/src/main/java/org/apache/ranger/services/knox/client/KnoxClient.java
index 33ac863..42b1941 100644
--- a/knox-agent/src/main/java/org/apache/ranger/services/knox/client/KnoxClient.java
+++ b/knox-agent/src/main/java/org/apache/ranger/services/knox/client/KnoxClient.java
@@ -30,6 +30,7 @@ import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.ranger.plugin.client.BaseClient;
 import org.apache.ranger.plugin.client.HadoopException;
+import org.apache.ranger.plugin.util.PasswordUtils;
 import org.codehaus.jackson.JsonNode;
 import org.codehaus.jackson.map.ObjectMapper;
 
@@ -73,6 +74,17 @@ public class KnoxClient {
 		if ( topologyNameMatching == null ||  topologyNameMatching.trim().isEmpty()) {
 			topologyNameMatching = "";
 		}
+		String decryptedPwd=null;
+		try{
+			decryptedPwd=PasswordUtils.decryptPassword(password);
+		}catch(Exception ex){
+			LOG.info("Password decryption failed; trying knox connection with received password string");
+			decryptedPwd=null;
+		}finally{
+			if(decryptedPwd==null){
+				decryptedPwd=password;
+			}
+		}
 		try {
 
 			Client client = null;
@@ -81,7 +93,7 @@ public class KnoxClient {
 			try {
 				client = Client.create();;
 				
-				client.addFilter(new HTTPBasicAuthFilter(userName, password));
+				client.addFilter(new HTTPBasicAuthFilter(userName, decryptedPwd));
 				WebResource webResource = client.resource(knoxUrl);
 				response = webResource.accept(EXPECTED_MIME_TYPE)
 					    .get(ClientResponse.class);
@@ -164,6 +176,17 @@ public class KnoxClient {
 		if ( serviceNameMatching == null ||  serviceNameMatching.trim().isEmpty()) {
 			serviceNameMatching = "";
 		}
+		String decryptedPwd=null;
+		try{
+			decryptedPwd=PasswordUtils.decryptPassword(password);
+		}catch(Exception ex){
+			LOG.info("Password decryption failed; trying knox connection with received password string");
+			decryptedPwd=null;
+		}finally{
+			if(decryptedPwd==null){
+				decryptedPwd=password;
+			}
+		}
 		try {
 
 			Client client = null;
@@ -172,7 +195,7 @@ public class KnoxClient {
 			try {
 				client = Client.create();;
 				
-				client.addFilter(new HTTPBasicAuthFilter(userName, password));
+				client.addFilter(new HTTPBasicAuthFilter(userName, decryptedPwd));
 				
 				WebResource webResource = client.resource(knoxUrl + "/" + topologyName);