Browse Source

单独写一个 DefaultLoginKeys

release/11.0
Lanlan 2 years ago
parent
commit
2076a9d77b
  1. 48
      designer-base/src/main/java/com/fr/design/login/config/DefaultLoginKeys.java
  2. 25
      designer-base/src/main/java/com/fr/design/login/utils/DesignerLoginUtils.java

48
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<String, String> keys = new HashMap<>();
private DefaultLoginKeys() {
Properties properties = load();
for (Map.Entry<Object, Object> 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;
}
}

25
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;
}
}

Loading…
Cancel
Save