kylin-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From shaofeng...@apache.org
Subject kylin git commit: KYLIN-1962: minor, fix Spring Security read Kylin properties
Date Tue, 06 Sep 2016 01:17:42 GMT
Repository: kylin
Updated Branches:
  refs/heads/1.5.4-rc1 602e71902 -> ced72d5a6


KYLIN-1962: minor, fix Spring Security read Kylin properties

Signed-off-by: shaofengshi <shaofengshi@apache.org>


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

Branch: refs/heads/1.5.4-rc1
Commit: ced72d5a6612bd969f4f88fa454e02b5ec63460b
Parents: 602e719
Author: Yiming Liu <liuyiming.vip@gmail.com>
Authored: Tue Sep 6 00:57:19 2016 +0800
Committer: shaofengshi <shaofengshi@apache.org>
Committed: Tue Sep 6 09:15:38 2016 +0800

----------------------------------------------------------------------
 .../org/apache/kylin/common/KylinConfig.java    | 38 ++++++++++----------
 .../security/PasswordPlaceholderConfigurer.java | 20 +++++++++++
 .../org/apache/kylin/tool/DiagnosisInfoCLI.java |  2 +-
 3 files changed, 40 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kylin/blob/ced72d5a/core-common/src/main/java/org/apache/kylin/common/KylinConfig.java
----------------------------------------------------------------------
diff --git a/core-common/src/main/java/org/apache/kylin/common/KylinConfig.java b/core-common/src/main/java/org/apache/kylin/common/KylinConfig.java
index 241170a..f134ad4 100644
--- a/core-common/src/main/java/org/apache/kylin/common/KylinConfig.java
+++ b/core-common/src/main/java/org/apache/kylin/common/KylinConfig.java
@@ -47,7 +47,7 @@ public class KylinConfig extends KylinConfigBase {
 
     /** Kylin properties file name */
     public static final String KYLIN_CONF_PROPERTIES_FILE = "kylin.properties";
-    public static final String KYLIN_SECURITY_CONF_PROPERTIES_FILE = "kylin_account.properties";
+    public static final String KYLIN_ACCOUNT_CONF_PROPERTIES_FILE = "kylin_account.properties";
     public static final String KYLIN_CONF = "KYLIN_CONF";
 
     // static cached instances
@@ -205,11 +205,11 @@ public class KylinConfig extends KylinConfigBase {
         return getKylinPropertiesFile(path);
     }
 
-    static File getKylinSecurityPropertiesFile() {
+    static File getKylinAccountPropertiesFile() {
         String kylinConfHome = System.getProperty(KYLIN_CONF);
         if (!StringUtils.isEmpty(kylinConfHome)) {
             logger.info("Use KYLIN_CONF=" + kylinConfHome);
-            return getKylinSecurityPropertiesFile(kylinConfHome);
+            return getKylinAccountPropertiesFile(kylinConfHome);
         }
 
         logger.warn("KYLIN_CONF property was not set, will seek KYLIN_HOME env variable");
@@ -219,10 +219,10 @@ public class KylinConfig extends KylinConfigBase {
             throw new KylinConfigCannotInitException("Didn't find KYLIN_CONF or KYLIN_HOME,
please set one of them");
 
         String path = kylinHome + File.separator + "conf";
-        return getKylinSecurityPropertiesFile(path);
+        return getKylinAccountPropertiesFile(path);
     }
 
-    private static Properties getKylinProperties() {
+    public static Properties getKylinProperties() {
         File propFile = getKylinPropertiesFile();
         if (propFile == null || !propFile.exists()) {
             logger.error("fail to locate " + KYLIN_CONF_PROPERTIES_FILE);
@@ -243,22 +243,22 @@ public class KylinConfig extends KylinConfigBase {
                 conf.putAll(propOverride);
             }
 
-            File securityPropFile = getKylinSecurityPropertiesFile();
-            if (securityPropFile.exists()) {
-                FileInputStream ois = new FileInputStream(securityPropFile);
-                Properties propSecurity = new Properties();
-                propSecurity.load(ois);
+            File accountPropFile = getKylinAccountPropertiesFile();
+            if (accountPropFile.exists()) {
+                FileInputStream ois = new FileInputStream(accountPropFile);
+                Properties propAccount = new Properties();
+                propAccount.load(ois);
                 IOUtils.closeQuietly(ois);
-                conf.putAll(propSecurity);
+                conf.putAll(propAccount);
             }
 
-            File securityPropOverrideFile = new File(securityPropFile.getParentFile(), securityPropFile.getName()
+ ".override");
-            if (securityPropOverrideFile.exists()) {
-                FileInputStream ois = new FileInputStream(securityPropOverrideFile);
-                Properties propSecurityOverride = new Properties();
-                propSecurityOverride.load(ois);
+            File accountPropOverrideFile = new File(accountPropFile.getParentFile(), accountPropFile.getName()
+ ".override");
+            if (accountPropOverrideFile.exists()) {
+                FileInputStream ois = new FileInputStream(accountPropOverrideFile);
+                Properties propAccountOverride = new Properties();
+                propAccountOverride.load(ois);
                 IOUtils.closeQuietly(ois);
-                conf.putAll(propSecurityOverride);
+                conf.putAll(propAccountOverride);
             }
 
         } catch (IOException e) {
@@ -282,12 +282,12 @@ public class KylinConfig extends KylinConfigBase {
         return new File(path, KYLIN_CONF_PROPERTIES_FILE);
     }
 
-    private static File getKylinSecurityPropertiesFile(String path) {
+    private static File getKylinAccountPropertiesFile(String path) {
         if (path == null) {
             return null;
         }
 
-        return new File(path, KYLIN_SECURITY_CONF_PROPERTIES_FILE);
+        return new File(path, KYLIN_ACCOUNT_CONF_PROPERTIES_FILE);
     }
 
     public static void setSandboxEnvIfPossible() {

http://git-wip-us.apache.org/repos/asf/kylin/blob/ced72d5a/server-base/src/main/java/org/apache/kylin/rest/security/PasswordPlaceholderConfigurer.java
----------------------------------------------------------------------
diff --git a/server-base/src/main/java/org/apache/kylin/rest/security/PasswordPlaceholderConfigurer.java
b/server-base/src/main/java/org/apache/kylin/rest/security/PasswordPlaceholderConfigurer.java
index 5381b14..092d73a 100644
--- a/server-base/src/main/java/org/apache/kylin/rest/security/PasswordPlaceholderConfigurer.java
+++ b/server-base/src/main/java/org/apache/kylin/rest/security/PasswordPlaceholderConfigurer.java
@@ -18,13 +18,21 @@
 
 package org.apache.kylin.rest.security;
 
+import java.io.InputStream;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.nio.charset.Charset;
 import java.util.Properties;
 
 import javax.crypto.Cipher;
 import javax.crypto.spec.SecretKeySpec;
 
 import org.apache.commons.codec.binary.Base64;
+import org.apache.commons.io.IOUtils;
+import org.apache.kylin.common.KylinConfig;
 import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
+import org.springframework.core.io.InputStreamResource;
+import org.springframework.core.io.Resource;
 import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
 
 /**
@@ -38,7 +46,19 @@ public class PasswordPlaceholderConfigurer extends PropertyPlaceholderConfigurer
      */
     private static byte[] key = { 0x74, 0x68, 0x69, 0x73, 0x49, 0x73, 0x41, 0x53, 0x65, 0x63,
0x72, 0x65, 0x74, 0x4b, 0x65, 0x79 };
 
+    /**
+     * The PasswordPlaceholderConfigurer will read Kylin properties as the Spring resource
+     */
     public PasswordPlaceholderConfigurer() {
+        Resource[] resources = new Resource[1];
+        Properties prop = KylinConfig.getKylinProperties();
+        StringWriter writer = new StringWriter();
+        prop.list(new PrintWriter(writer));
+        String propString = writer.getBuffer().toString();
+        IOUtils.closeQuietly(writer);
+        InputStream is = IOUtils.toInputStream(propString, Charset.defaultCharset());
+        resources[0] = new InputStreamResource(is);
+        this.setLocations(resources);
     }
 
     public static String encrypt(String strToEncrypt) {

http://git-wip-us.apache.org/repos/asf/kylin/blob/ced72d5a/tool/src/main/java/org/apache/kylin/tool/DiagnosisInfoCLI.java
----------------------------------------------------------------------
diff --git a/tool/src/main/java/org/apache/kylin/tool/DiagnosisInfoCLI.java b/tool/src/main/java/org/apache/kylin/tool/DiagnosisInfoCLI.java
index e77ac3b..f93aaf2 100644
--- a/tool/src/main/java/org/apache/kylin/tool/DiagnosisInfoCLI.java
+++ b/tool/src/main/java/org/apache/kylin/tool/DiagnosisInfoCLI.java
@@ -184,7 +184,7 @@ public class DiagnosisInfoCLI extends AbstractInfoExtractor {
                         File[] confFiles = srcConfDir.listFiles();
                         if (confFiles != null) {
                             for (File confFile : confFiles) {
-                                if (!KylinConfig.KYLIN_SECURITY_CONF_PROPERTIES_FILE.equals(confFile.getName()))
{
+                                if (!KylinConfig.KYLIN_ACCOUNT_CONF_PROPERTIES_FILE.equals(confFile.getName()))
{
                                     FileUtils.copyFileToDirectory(confFile, destConfDir);
                                 }
                             }


Mime
View raw message