RANGER-1185 : If cred.jceks is corrupted or zero length it should be rebuilt

Signed-off-by: Velmurugan Periasamy <v...@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/e0d24024
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ranger/tree/e0d24024
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ranger/diff/e0d24024

Branch: refs/heads/master
Commit: e0d2402468d782553745d2b781cc10de26fcb7d6
Parents: 10f1282
Author: pradeep agrawal <pradeep.agra...@freestoneinfotech.com>
Authored: Wed Oct 12 11:20:50 2016 +0530
Committer: Velmurugan Periasamy <v...@apache.org>
Committed: Wed Oct 12 22:40:10 2016 -0400

----------------------------------------------------------------------
 .../apache/ranger/credentialapi/buildks.java    | 25 +++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/e0d24024/credentialbuilder/src/main/java/org/apache/ranger/credentialapi/buildks.java
----------------------------------------------------------------------
diff --git 
a/credentialbuilder/src/main/java/org/apache/ranger/credentialapi/buildks.java 
b/credentialbuilder/src/main/java/org/apache/ranger/credentialapi/buildks.java
index e21d01e..01868ab 100644
--- 
a/credentialbuilder/src/main/java/org/apache/ranger/credentialapi/buildks.java
+++ 
b/credentialbuilder/src/main/java/org/apache/ranger/credentialapi/buildks.java
@@ -19,6 +19,7 @@
 
  package org.apache.ranger.credentialapi;
 import java.io.BufferedReader;
+import java.io.File;
 import java.io.IOException;
 import java.io.InputStreamReader;
 import java.lang.reflect.Field;
@@ -82,7 +83,8 @@ public class buildks {
                        providerPath=args[5];
                                
if(!isValidCreateCommand(command,alias,valueOption,credential,providerOption,providerPath)){
                                return returnCode;
-                       }                       
+                               }
+                               deleteInvalidKeystore(providerPath);
                        
tempCredential=CredentialReader.getDecryptedString(providerPath, alias);
                }else{
                        return returnCode;
@@ -520,4 +522,25 @@ public class buildks {
                return ret;
                
        }
+
+       public void deleteInvalidKeystore(String providerPath){
+               if(providerPath!=null){
+                       String keystore=null;
+                       if(providerPath.startsWith("jceks://file")){
+                               
keystore=providerPath.replace("jceks://file","");
+                       }else if(providerPath.startsWith("localjceks://file")){
+                               
keystore=providerPath.replace("jceks://file","");
+                       }else{
+                               keystore=providerPath;
+                       }
+                       if(keystore!=null && !keystore.isEmpty()){
+                               File file =new File(keystore);
+                               if(file!=null && file.length()==0){
+                                       System.out.println("Provider file 
'"+keystore+"' is in invalid state or corrupt!! will try to delete first.");
+                                       file.delete();
+                                       file=null;
+                               }
+                       }
+               }
+       }
 }

Reply via email to