You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kylin.apache.org by sh...@apache.org on 2016/02/25 04:20:39 UTC

kylin git commit: KYLIN-1442 make PasswordPlaceholderConfigurer work for both AES and BCrypt

Repository: kylin
Updated Branches:
  refs/heads/1.x-staging e366291c7 -> cb9782d04


KYLIN-1442 make PasswordPlaceholderConfigurer work for both AES and BCrypt


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

Branch: refs/heads/1.x-staging
Commit: cb9782d047033fb381c9c6c810849a8ea276a1d3
Parents: e366291
Author: shaofengshi <sh...@apache.org>
Authored: Thu Feb 25 11:18:35 2016 +0800
Committer: shaofengshi <sh...@apache.org>
Committed: Thu Feb 25 11:19:21 2016 +0800

----------------------------------------------------------------------
 .../security/PasswordPlaceholderConfigurer.java | 36 ++++++++++++++------
 1 file changed, 25 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kylin/blob/cb9782d0/server/src/main/java/org/apache/kylin/rest/security/PasswordPlaceholderConfigurer.java
----------------------------------------------------------------------
diff --git a/server/src/main/java/org/apache/kylin/rest/security/PasswordPlaceholderConfigurer.java b/server/src/main/java/org/apache/kylin/rest/security/PasswordPlaceholderConfigurer.java
index 36b498c..3a6898f 100644
--- a/server/src/main/java/org/apache/kylin/rest/security/PasswordPlaceholderConfigurer.java
+++ b/server/src/main/java/org/apache/kylin/rest/security/PasswordPlaceholderConfigurer.java
@@ -18,11 +18,6 @@
 
 package org.apache.kylin.rest.security;
 
-import java.util.Properties;
-
-import javax.crypto.Cipher;
-import javax.crypto.spec.SecretKeySpec;
-
 import org.apache.commons.codec.binary.Base64;
 import org.apache.kylin.common.KylinConfig;
 import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
@@ -30,6 +25,10 @@ import org.springframework.core.io.InputStreamResource;
 import org.springframework.core.io.Resource;
 import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
 
+import javax.crypto.Cipher;
+import javax.crypto.spec.SecretKeySpec;
+import java.util.Properties;
+
 /**
  * @author xduo
  * 
@@ -75,15 +74,30 @@ public class PasswordPlaceholderConfigurer extends PropertyPlaceholderConfigurer
             return props.getProperty(placeholder);
         }
     }
+    
+    private static void printUsage() {
+        System.out.println("Usage: java org.apache.kylin.rest.security.PasswordPlaceholderConfigurer <EncryptMethod> <your_password>");
+        System.out.println("EncryptMethod: AES or BCrypt");
+    }
 
     public static void main(String[] args) {
-        if (args.length != 1) {
-            System.out.println("Usage: java org.apache.kylin.rest.security.PasswordPlaceholderConfigurer <your_password>");
+        if (args.length != 2) {
+            printUsage();
+            System.exit(1);
+        }
+
+        String encryptMethod = args[0];
+        String passwordTxt = args[1];
+        if ("AES".equalsIgnoreCase(encryptMethod)) {
+            System.out.println(encryptMethod + " encrypted password is: ");
+            System.out.println(encrypt(passwordTxt));
+        } else if ("BCrypt".equalsIgnoreCase(encryptMethod)) {
+            BCryptPasswordEncoder bCryptPasswordEncoder = new BCryptPasswordEncoder();
+            System.out.println(encryptMethod + " encrypted password is: ");
+            System.out.println(bCryptPasswordEncoder.encode(passwordTxt));
+        } else {
+            printUsage();
             System.exit(1);
         }
-        
-        BCryptPasswordEncoder bCryptPasswordEncoder = new BCryptPasswordEncoder();
-        System.out.println("The hash of your password is: ");
-        System.out.println(bCryptPasswordEncoder.encode(args[0]));
     }
 }