ranger-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sneet...@apache.org
Subject git commit: ARGUS-93:Windows support in Credential Provider
Date Thu, 02 Oct 2014 20:49:38 GMT
Repository: incubator-argus
Updated Branches:
  refs/heads/master 91dbc72c3 -> d11f2ede5


ARGUS-93:Windows support in Credential Provider

Signed-off-by: sneethiraj <sneethir@apache.org>


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

Branch: refs/heads/master
Commit: d11f2ede5e4d857053d8f11cbffa51872279a7e7
Parents: 91dbc72
Author: vperiasamy <vperiasamy@hortonworks.com>
Authored: Thu Oct 2 10:16:03 2014 -0700
Committer: sneethiraj <sneethir@apache.org>
Committed: Thu Oct 2 13:49:21 2014 -0700

----------------------------------------------------------------------
 .../credentialapi/CredentialReader.java         |  14 +-
 .../hortonworks/credentialapi/Testbuildks.java  |  10 +-
 .../com/hortonworks/credentialapi/buildks.java  | 129 ++++++++++++++++---
 .../credentialapi/CredentialReader.java         |  12 +-
 4 files changed, 139 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-argus/blob/d11f2ede/credentialbuilder/src/main/java/com/hortonworks/credentialapi/CredentialReader.java
----------------------------------------------------------------------
diff --git a/credentialbuilder/src/main/java/com/hortonworks/credentialapi/CredentialReader.java
b/credentialbuilder/src/main/java/com/hortonworks/credentialapi/CredentialReader.java
index abbdaef..f0627ae 100644
--- a/credentialbuilder/src/main/java/com/hortonworks/credentialapi/CredentialReader.java
+++ b/credentialbuilder/src/main/java/com/hortonworks/credentialapi/CredentialReader.java
@@ -45,10 +45,16 @@ public class CredentialReader {
 					   //UserProvider.SCHEME_NAME + ":///," +
 			  CrendentialProviderPath);
 		  }else{
-			  conf.set(CredentialProviderFactory.CREDENTIAL_PROVIDER_PATH,
-					   //UserProvider.SCHEME_NAME + ":///," +
-			  JavaKeyStoreProvider.SCHEME_NAME + "://file" + CrendentialProviderPath);			  
-		  }	  
+			  if(CrendentialProviderPath.startsWith("/")){
+				  conf.set(CredentialProviderFactory.CREDENTIAL_PROVIDER_PATH,
+						   //UserProvider.SCHEME_NAME + ":///," +
+				  JavaKeyStoreProvider.SCHEME_NAME + "://file" + CrendentialProviderPath);
+			  }else{
+				  conf.set(CredentialProviderFactory.CREDENTIAL_PROVIDER_PATH,
+						   //UserProvider.SCHEME_NAME + ":///," +
+				  JavaKeyStoreProvider.SCHEME_NAME + "://file/" + CrendentialProviderPath);
+			  }
+		  }
 		  List<CredentialProvider> providers = CredentialProviderFactory.getProviders(conf);
 		  List<String> aliasesList=new ArrayList<String>();
 		  CredentialProvider.CredentialEntry credEntry=null;

http://git-wip-us.apache.org/repos/asf/incubator-argus/blob/d11f2ede/credentialbuilder/src/main/java/com/hortonworks/credentialapi/Testbuildks.java
----------------------------------------------------------------------
diff --git a/credentialbuilder/src/main/java/com/hortonworks/credentialapi/Testbuildks.java
b/credentialbuilder/src/main/java/com/hortonworks/credentialapi/Testbuildks.java
index 2524f3f..e4acf89 100644
--- a/credentialbuilder/src/main/java/com/hortonworks/credentialapi/Testbuildks.java
+++ b/credentialbuilder/src/main/java/com/hortonworks/credentialapi/Testbuildks.java
@@ -36,13 +36,19 @@ public class Testbuildks {
     int rc2=buildksOBJ.listCredential(argsListCommand);
     assertEquals(0, rc2);
     assertTrue(rc2==0);
-
+    
+    String[] argsGetCommand = {"get", "TestCredential1", "-provider", "jceks://file" +keystoreFile
};
+    String pw=buildksOBJ.getCredential(argsGetCommand);
+    assertEquals("PassworD123", pw);
+    assertTrue(pw.equals("PassworD123"));
+    boolean getCredentialPassed = pw.equals("PassworD123");
+    
     String[] argsDeleteCommand = {"delete", "TestCredential1", "-provider", "jceks://file"
+keystoreFile };
     int rc3=buildksOBJ.deleteCredential(argsDeleteCommand);
     assertEquals(0, rc3);
     assertTrue(rc3==0);
    
-    if(rc1==rc2 && rc2==rc3 && rc3==0){
+    if(rc1==rc2 && rc2==rc3 && rc3==0 && getCredentialPassed){
     	System.out.println("Test Case has been completed successfully..");    	
     }
   }

http://git-wip-us.apache.org/repos/asf/incubator-argus/blob/d11f2ede/credentialbuilder/src/main/java/com/hortonworks/credentialapi/buildks.java
----------------------------------------------------------------------
diff --git a/credentialbuilder/src/main/java/com/hortonworks/credentialapi/buildks.java b/credentialbuilder/src/main/java/com/hortonworks/credentialapi/buildks.java
index 257e311..149eb3b 100644
--- a/credentialbuilder/src/main/java/com/hortonworks/credentialapi/buildks.java
+++ b/credentialbuilder/src/main/java/com/hortonworks/credentialapi/buildks.java
@@ -29,7 +29,34 @@ import org.apache.hadoop.util.GenericOptionsParser;
 public class buildks {
 	public static void main(String[] args) {
 		buildks buildksOBJ=new buildks();
-		buildksOBJ.createCredential(args);
+		String command=null;
+		try{
+			if(args!=null && args.length>=3){
+				command=args[0];
+				if(command!=null && !command.trim().isEmpty()){
+					if(command.equalsIgnoreCase("create")){
+						buildksOBJ.createCredential(args);
+					}else if(command.equalsIgnoreCase("list")){
+						buildksOBJ.listCredential(args);
+					}else if(command.equalsIgnoreCase("get")){
+						String credential=buildksOBJ.getCredential(args);
+						if(credential!=null){
+							System.out.println(credential);
+							System.exit(0);
+						}
+					}else{
+						System.out.println(command +" is not supported in current version of CredentialBuilder
API.");
+						System.exit(1);
+					}
+				}
+			}else{
+				System.out.println("Invalid Command line argument.");
+				System.exit(1);
+			}
+		}catch(Exception ex){
+			ex.printStackTrace();
+			System.exit(1);
+		}
 	}
 	
 	public int createCredential(String args[]){
@@ -50,7 +77,7 @@ public class buildks {
 	    		credential=args[3];
 	    		providerOption=args[4];
 	    		providerPath=args[5];
-	    		if(!isValidInput(command,alias,valueOption,credential,providerOption,providerPath)){
+				if(!isValidCreateCommand(command,alias,valueOption,credential,providerOption,providerPath)){
 	    			return returnCode;
 	    		}	    		
 	    		tempCredential=CredentialReader.getDecryptedString(providerPath, alias);
@@ -99,7 +126,7 @@ public class buildks {
 	    		credential=args[3];
 	    		providerOption=args[4];
 	    		providerPath=args[5];
-	    		if(!isValidInput(command,alias,valueOption,credential,providerOption,providerPath)){
+				if(!isValidCreateCommand(command,alias,valueOption,credential,providerOption,providerPath)){
 	    			return returnCode;
 	    		}	    		
 		    	displayCommand(args);
@@ -160,7 +187,7 @@ public class buildks {
     		command="create";
     		valueOption="-value";
     		providerOption="-provider";
-    		if(!isValidInput(command,alias,valueOption,credential,providerOption,providerPath)){
+			if(!isValidCreateCommand(command,alias,valueOption,credential,providerOption,providerPath)){
     			return returnCode;
     		}
     		args=new String[6];
@@ -250,7 +277,7 @@ public class buildks {
 		return returnCode;
 	}	
 	
-	public static boolean isValidInput(String command,String alias,String valueOption,String
credential,String providerOption,String providerPath)
+	public static boolean isValidCreateCommand(String command,String alias,String valueOption,String
credential,String providerOption,String providerPath)
     {
 		boolean isValid=true;
 		try{
@@ -258,55 +285,55 @@ public class buildks {
         	{
         		System.out.println("Invalid create phrase in credential creation command!!");
         		System.out.println("Expected:'create' Found:'"+command+"'");
-        		displaySyntax();
+				displaySyntax("create");
         		return false;
         	}
         	if(alias==null || "".equalsIgnoreCase(alias.trim()))
         	{
         		System.out.println("Invalid alias name phrase in credential creation command!!");
         		System.out.println("Found:'"+alias+"'");
-        		displaySyntax();
+				displaySyntax("create");
         		return false;
         	}
         	if(valueOption==null || !"-value".equalsIgnoreCase(valueOption.trim()))
         	{
         		System.out.println("Invalid value option switch in credential creation command!!");
         		System.out.println("Expected:'-value' Found:'"+valueOption+"'");
-        		displaySyntax();
+				displaySyntax("create");
         		return false;
         	}
         	if(valueOption==null || !"-value".equalsIgnoreCase(valueOption.trim()))
         	{
         		System.out.println("Invalid value option in credential creation command!!");
         		System.out.println("Expected:'-value' Found:'"+valueOption+"'");
-        		displaySyntax();
+				displaySyntax("create");
         		return false;
         	}
         	if(credential==null)
         	{
         		System.out.println("Invalid credential value in credential creation command!!");
         		System.out.println("Found:"+credential);
-        		displaySyntax();
+				displaySyntax("create");
         		return false;
         	}
         	if(providerOption==null || !"-provider".equalsIgnoreCase(providerOption.trim()))
         	{
         		System.out.println("Invalid provider option in credential creation command!!");
         		System.out.println("Expected:'-provider' Found:'"+providerOption+"'");
-        		displaySyntax();
+				displaySyntax("create");
         		return false;
         	}
         	if(providerPath==null || "".equalsIgnoreCase(providerPath.trim()) || !providerPath.startsWith("jceks://"))
         	{
         		System.out.println("Invalid provider option in credential creation command!!");
         		System.out.println("Found:'"+providerPath+"'");
-        		displaySyntax();
+				displaySyntax("create");
         		return false;
         	}
     	}catch(Exception ex){    	
     		System.out.println("Invalid input or runtime error! Please try again.");
     		System.out.println("Input:"+command+" "+alias+" "+valueOption+" "+credential+" "+providerOption+"
"+providerPath);
-    		displaySyntax();
+			displaySyntax("create");
     		ex.printStackTrace();
     		return false;
     	}            	
@@ -327,10 +354,78 @@ public class buildks {
 		}
     }
 	
-	public static void displaySyntax()
-    {
-		System.out.println("Correct syntax is:create <aliasname> -value <password>
-provider <jceks://file/filepath>");
-		System.out.println("sample command is:create myalias -value password123 -provider jceks://file/tmp/ks/myks.jceks");
            		 
+	public static void displaySyntax(String command){
+		if(command!=null && command.trim().equalsIgnoreCase("create")){
+			System.out.println("Correct syntax is:create <aliasname> -value <password>
-provider <jceks://file/filepath>");
+			System.out.println("sample command is:create myalias -value password123 -provider jceks://file/tmp/ks/myks.jceks");
+		}
+	}
+	public String getCredential(String args[]){
+		String command=null;
+		String alias=null;
+		String providerOption=null;
+		String providerPath=null;
+		String tempCredential=null;
+		try{
+			if(args!=null && args.length==4){
+				command=args[0];
+				alias=args[1];
+				providerOption=args[2];
+				providerPath=args[3];
+				if(!isValidGetCommand(command,alias,providerOption,providerPath)){
+					displaySyntax("get");
+				}else{
+					tempCredential=CredentialReader.getDecryptedString(providerPath, alias);
+				}
+			}else{
+				displaySyntax("get");
+			}
+			if(tempCredential==null){
+				System.out.println("Alias"+ alias +" does not exist!!");
+			}
+			}catch(Exception ex){
+				ex.printStackTrace();
+			}
+			return tempCredential;
 	}
 
+	public static boolean isValidGetCommand(String command,String alias,String providerOption,String
providerPath){
+		boolean isValid=true;
+		try{
+			if(command==null || !"get".equalsIgnoreCase(command.trim())){
+				System.out.println("Invalid get phrase in credential get command!!");
+				System.out.println("Expected:'get' Found:'"+command+"'");
+				displaySyntax("get");
+				return false;
+			}
+			if(alias==null || "".equalsIgnoreCase(alias.trim()))
+			{
+				System.out.println("Invalid alias name phrase in credential get command!!");
+				System.out.println("Found:'"+alias+"'");
+				displaySyntax("get");
+				return false;
+			}
+			if(providerOption==null || !"-provider".equalsIgnoreCase(providerOption.trim()))
+			{
+				System.out.println("Invalid provider option in credential get command!!");
+				System.out.println("Expected:'-provider' Found:'"+providerOption+"'");
+				displaySyntax("get");
+				return false;
+			}
+			if(providerPath==null || "".equalsIgnoreCase(providerPath.trim()) || !providerPath.startsWith("jceks://"))
+			{
+				System.out.println("Invalid provider option in credential get command!!");
+				System.out.println("Found:'"+providerPath+"'");
+				displaySyntax("get");
+				return false;
+			}
+		}catch(Exception ex){
+			System.out.println("Invalid input or runtime error! Please try again.");
+			System.out.println("Input:"+command+" "+alias+" "+providerOption+" "+providerPath);
+			displaySyntax("get");
+			ex.printStackTrace();
+			return false;
+		}
+		return isValid;
+	}
 }

http://git-wip-us.apache.org/repos/asf/incubator-argus/blob/d11f2ede/security-admin/src/main/java/com/xasecure/credentialapi/CredentialReader.java
----------------------------------------------------------------------
diff --git a/security-admin/src/main/java/com/xasecure/credentialapi/CredentialReader.java
b/security-admin/src/main/java/com/xasecure/credentialapi/CredentialReader.java
index 5be7ae3..dccf8a1 100644
--- a/security-admin/src/main/java/com/xasecure/credentialapi/CredentialReader.java
+++ b/security-admin/src/main/java/com/xasecure/credentialapi/CredentialReader.java
@@ -45,9 +45,15 @@ public class CredentialReader {
 						   //UserProvider.SCHEME_NAME + ":///," +
 				  CrendentialProviderPath);
 			  }else{
-				  conf.set(CredentialProviderFactory.CREDENTIAL_PROVIDER_PATH,
-						   //UserProvider.SCHEME_NAME + ":///," +
-				  JavaKeyStoreProvider.SCHEME_NAME + "://file" + CrendentialProviderPath);			  
+				  if(CrendentialProviderPath.startsWith("/")){
+					  conf.set(CredentialProviderFactory.CREDENTIAL_PROVIDER_PATH,
+							   //UserProvider.SCHEME_NAME + ":///," +
+					  JavaKeyStoreProvider.SCHEME_NAME + "://file" + CrendentialProviderPath);
+				  }else{
+					  conf.set(CredentialProviderFactory.CREDENTIAL_PROVIDER_PATH,
+							   //UserProvider.SCHEME_NAME + ":///," +
+					  JavaKeyStoreProvider.SCHEME_NAME + "://file/" + CrendentialProviderPath);
+				  }
 			  }	 	  
 			  List<CredentialProvider> providers = CredentialProviderFactory.getProviders(conf);
 			  List<String> aliasesList=new ArrayList<String>();


Mime
View raw message