From 2076a9d77be281e99ff51b7346d176168b806ea3 Mon Sep 17 00:00:00 2001 From: Lanlan Date: Mon, 20 Jun 2022 15:10:08 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=95=E7=8B=AC=E5=86=99=E4=B8=80=E4=B8=AA?= =?UTF-8?q?=20DefaultLoginKeys?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../design/login/config/DefaultLoginKeys.java | 48 +++++++++++++++++++ .../login/utils/DesignerLoginUtils.java | 25 +++------- 2 files changed, 54 insertions(+), 19 deletions(-) create mode 100644 designer-base/src/main/java/com/fr/design/login/config/DefaultLoginKeys.java diff --git a/designer-base/src/main/java/com/fr/design/login/config/DefaultLoginKeys.java b/designer-base/src/main/java/com/fr/design/login/config/DefaultLoginKeys.java new file mode 100644 index 0000000000..36988aa5ca --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/login/config/DefaultLoginKeys.java @@ -0,0 +1,48 @@ +package com.fr.design.login.config; + +import com.fr.log.FineLoggerFactory; +import java.io.IOException; +import java.io.InputStream; +import java.util.HashMap; +import java.util.Map; +import java.util.Properties; + +/** + * @author Lanlan + * @version 10.0 + * Created by Lanlan on 2022/6/20 + */ +public class DefaultLoginKeys { + + private static final String FILENAME = "com/fr/design/config/default"; + + private static final DefaultLoginKeys INSTANCE = new DefaultLoginKeys(); + + public static DefaultLoginKeys getInstance() { + return INSTANCE; + } + + private final Map keys = new HashMap<>(); + + private DefaultLoginKeys() { + Properties properties = load(); + for (Map.Entry entry : properties.entrySet()) { + String name = entry.getKey().toString(); + keys.put(name, entry.getValue().toString()); + } + } + + public String getKey(String name) { + return keys.get(name); + } + + private Properties load() { + Properties properties = new Properties(); + try (InputStream inputStream = DefaultLoginKeys.class.getClassLoader().getResourceAsStream(FILENAME)) { + properties.load(inputStream); + } catch (IOException e) { + FineLoggerFactory.getLogger().error(e.getMessage(), e); + } + return properties; + } +} diff --git a/designer-base/src/main/java/com/fr/design/login/utils/DesignerLoginUtils.java b/designer-base/src/main/java/com/fr/design/login/utils/DesignerLoginUtils.java index ca238d1544..8845f00e1f 100644 --- a/designer-base/src/main/java/com/fr/design/login/utils/DesignerLoginUtils.java +++ b/designer-base/src/main/java/com/fr/design/login/utils/DesignerLoginUtils.java @@ -1,6 +1,7 @@ package com.fr.design.login.utils; import com.fr.design.DesignerEnvManager; +import com.fr.design.login.config.DefaultLoginKeys; import com.fr.design.mainframe.toast.DesignerToastMsgUtil; import com.fr.general.CloudCenter; import com.fr.general.CloudCenterConfig; @@ -9,16 +10,12 @@ import com.fr.general.http.HttpToolbox; import com.fr.general.log.MessageFormatter; import com.fr.json.JSONObject; import com.fr.log.FineLoggerFactory; -import com.fr.security.encryption.storage.keys.DefaultKeys; import com.fr.stable.StringUtils; import com.fr.third.org.bouncycastle.util.encoders.Hex; import java.awt.Window; -import java.io.IOException; -import java.io.InputStream; import java.security.SecureRandom; import java.util.HashMap; import java.util.Map; -import java.util.Properties; import javax.crypto.Cipher; import javax.crypto.spec.IvParameterSpec; import javax.crypto.spec.SecretKeySpec; @@ -87,11 +84,12 @@ public class DesignerLoginUtils { jo.put("uid", manager.getDesignerLoginUid()); jo.put("username", manager.getDesignerLoginUsername()); jo.put("source", PRODUCT_FINEREPORT); - - Properties properties = read("/default"); - byte[] iv = randomIv(); - return new String(Hex.encode(iv)) + encrypt(jo.toString(), properties.getProperty("Fine-Designer_Login").getBytes(), iv); + return new String(Hex.encode(iv)) + encrypt( + jo.toString(), + DefaultLoginKeys.getInstance().getKey("Fine-Designer_Login").getBytes(), + iv + ); } private static byte[] randomIv() { @@ -110,15 +108,4 @@ public class DesignerLoginUtils { byte[] resultBytes = cipher.doFinal(content.getBytes()); return new String(Hex.encode(resultBytes)); } - - private static Properties read(String fileName) { - fileName = "com/fr/design/config" + fileName; - Properties properties = new Properties(); - try (InputStream inputStream = DefaultKeys.class.getClassLoader().getResourceAsStream(fileName)){ - properties.load(inputStream); - } catch (IOException e) { - FineLoggerFactory.getLogger().error(e.getMessage(), e); - } - return properties; - } }