From 065e5abb095d2df427720ee44c99dd1a4aee6492 Mon Sep 17 00:00:00 2001 From: wanglihui <949764788@qq.com> Date: Mon, 20 Dec 2021 13:50:18 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0jasypt=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E5=8A=A0=E5=AF=86=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 7 ++++++ .../java/com/zdjizhi/common/CommonConfig.java | 22 ++++++++++++++++++- src/main/resources/common.properties | 4 +++- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index f238d08..c3f797d 100644 --- a/pom.xml +++ b/pom.xml @@ -102,6 +102,13 @@ + + + org.jasypt + jasypt + 1.9.3 + + org.slf4j slf4j-api diff --git a/src/main/java/com/zdjizhi/common/CommonConfig.java b/src/main/java/com/zdjizhi/common/CommonConfig.java index 4d099fe..325bc29 100644 --- a/src/main/java/com/zdjizhi/common/CommonConfig.java +++ b/src/main/java/com/zdjizhi/common/CommonConfig.java @@ -1,6 +1,7 @@ package com.zdjizhi.common; import com.zdjizhi.utils.CommonConfigurations; +import org.jasypt.encryption.pbe.StandardPBEStringEncryptor; /** * @author wlh @@ -8,6 +9,12 @@ import com.zdjizhi.utils.CommonConfigurations; */ public class CommonConfig { + private static StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor(); + + static { + encryptor.setPassword("galaxy"); + } + public static final int STREAM_EXECUTION_ENVIRONMENT_PARALLELISM = CommonConfigurations.getIntProperty("stream.execution.environment.parallelism"); public static final String STREAM_EXECUTION_JOB_NAME = CommonConfigurations.getStringProperty("stream.execution.job.name"); @@ -66,7 +73,20 @@ public class CommonConfig { public static final int BASELINE_THRESHOLD_SCHEDULE_DAYS = CommonConfigurations.getIntProperty("baseline.threshold.schedule.days"); public static final String SASL_JAAS_CONFIG_USER = CommonConfigurations.getStringProperty("sasl.jaas.config.user"); - public static final String SASL_JAAS_CONFIG_PASSWORD = CommonConfigurations.getStringProperty("sasl.jaas.config.password"); + public static final String SASL_JAAS_CONFIG_PASSWORD = encryptor.decrypt(CommonConfigurations.getStringProperty("sasl.jaas.config.password")); public static final int SASL_JAAS_CONFIG_FLAG = CommonConfigurations.getIntProperty("sasl.jaas.config.flag"); + + public static void main(String[] args) { + StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor(); + // 配置加密解密的密码/salt值 + encryptor.setPassword("galaxy"); + // 对"raw_password"进行加密:S5kR+Y7CI8k7MaecZpde25yK8NKUnd6p + String password = "galaxy2019"; + String encPwd = encryptor.encrypt(password); + System.out.println(encPwd); + // 再进行解密:raw_password + String rawPwd = encryptor.decrypt(encPwd); + System.out.println(rawPwd); + } } diff --git a/src/main/resources/common.properties b/src/main/resources/common.properties index 098b0b4..1331475 100644 --- a/src/main/resources/common.properties +++ b/src/main/resources/common.properties @@ -131,7 +131,9 @@ baseline.threshold.schedule.days=1 #kafka用户认证配置参数 sasl.jaas.config.user=admin -sasl.jaas.config.password=galaxy2019 +#sasl.jaas.config.password=galaxy2019 +#sasl.jaas.config.password=ENC(6MleDyA3Z73HSaXiKsDJ2k7Ys8YWLhEJ) +sasl.jaas.config.password=6MleDyA3Z73HSaXiKsDJ2k7Ys8YWLhEJ #是否开启kafka用户认证配置,1:是;0:否 sasl.jaas.config.flag=1 \ No newline at end of file