提交 3fa03e7a 编写于 作者: Z zhourui

enable encrypt password

上级 f54eb811
......@@ -31,6 +31,7 @@ import com.x.base.core.project.config.HuaweiPushConfig;
import com.x.base.core.project.config.JpushConfig;
import com.x.base.core.project.config.MPweixin;
import com.x.base.core.project.config.Messages;
import com.x.base.core.project.config.Miscellaneous;
import com.x.base.core.project.config.Node;
import com.x.base.core.project.config.Person;
import com.x.base.core.project.config.Portal;
......@@ -88,6 +89,7 @@ public class CreateConfigSample {
classes.add(WeLink.class);
classes.add(WorkTime.class);
classes.add(ZhengwuDingding.class);
classes.add(Miscellaneous.class);
Collections.sort(classes, (c1, c2) -> c1.getCanonicalName().compareTo(c2.getCanonicalName()));
for (Class<?> cls : classes) {
......
......@@ -22,7 +22,6 @@ public class DumpRestoreData extends ConfigObject {
public static final String RESTOREOVERRIDE_CLEAN = "clean";
public static final String RESTOREOVERRIDE_SKIPEXISTED = "skipExisted";
public static final Boolean DEFAULT_PARALLEL = true;
public static final Boolean DEFAULT_REDISTRIBUTE = true;
public static final Boolean DEFAULT_EXCEPTIONINVALIDSTORAGE = true;
public static final Boolean DEFAULT_ATTACHSTORAGE = true;
......@@ -32,7 +31,6 @@ public class DumpRestoreData extends ConfigObject {
this.includes = new ArrayList<>();
this.excludes = new ArrayList<>();
this.mode = MODE_LITE;
this.parallel = DEFAULT_PARALLEL;
this.attachStorage = DEFAULT_ATTACHSTORAGE;
this.exceptionInvalidStorage = DEFAULT_EXCEPTIONINVALIDSTORAGE;
this.itemCategory = DEFAULT_ITEMCATEGORY;
......@@ -47,9 +45,6 @@ public class DumpRestoreData extends ConfigObject {
@FieldDescribe("导出数据模式,lite|full,默认使用lite")
private String mode;
@FieldDescribe("使用并行导出,默认true")
private Boolean parallel;
@FieldDescribe("无法获取storage是否升起错误.")
private Boolean exceptionInvalidStorage;
......@@ -89,10 +84,6 @@ public class DumpRestoreData extends ConfigObject {
return BooleanUtils.isNotFalse(exceptionInvalidStorage);
}
public Boolean getParallel() {
return BooleanUtils.isNotFalse(parallel);
}
public String getMode() {
return StringUtils.equals(MODE_FULL, mode) ? MODE_FULL : MODE_LITE;
}
......@@ -121,10 +112,6 @@ public class DumpRestoreData extends ConfigObject {
this.excludes = excludes;
}
public void setParallel(Boolean parallel) {
this.parallel = parallel;
}
public void setExceptionInvalidStorage(Boolean exceptionInvalidStorage) {
this.exceptionInvalidStorage = exceptionInvalidStorage;
}
......
package com.x.base.core.project.config;
import java.io.File;
import java.io.UnsupportedEncodingException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.spec.InvalidKeySpecException;
import java.util.ArrayList;
import java.util.List;
import javax.crypto.BadPaddingException;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
......@@ -326,8 +334,8 @@ public class TernaryManagement extends ConfigObject {
return this._systemManagerPassword;
}
public void setSystemManagerPassword(String systemManagerPassword) {
this.systemManagerPassword = systemManagerPassword;
public void setSystemManagerPassword(String systemManagerPassword) throws InvalidKeyException, NoSuchAlgorithmException, InvalidKeySpecException, NoSuchPaddingException, IllegalBlockSizeException, BadPaddingException, UnsupportedEncodingException {
this.systemManagerPassword = Crypto.formattedDefaultEncrypt(systemManagerPassword);
}
public String getSecurityManagerPassword() {
......@@ -339,8 +347,8 @@ public class TernaryManagement extends ConfigObject {
return this._securityManagerPassword;
}
public void setSecurityManagerPassword(String securityManagerPassword) {
this.securityManagerPassword = securityManagerPassword;
public void setSecurityManagerPassword(String securityManagerPassword) throws InvalidKeyException, NoSuchAlgorithmException, InvalidKeySpecException, NoSuchPaddingException, IllegalBlockSizeException, BadPaddingException, UnsupportedEncodingException {
this.securityManagerPassword = Crypto.formattedDefaultEncrypt(securityManagerPassword);
}
public String getAuditManagerPassword() {
......@@ -351,7 +359,7 @@ public class TernaryManagement extends ConfigObject {
return this._auditManagerPassword;
}
public void setAuditManagerPassword(String auditManagerPassword) {
this.auditManagerPassword = auditManagerPassword;
public void setAuditManagerPassword(String auditManagerPassword) throws InvalidKeyException, NoSuchAlgorithmException, InvalidKeySpecException, NoSuchPaddingException, IllegalBlockSizeException, BadPaddingException, UnsupportedEncodingException {
this.auditManagerPassword = Crypto.formattedDefaultEncrypt(auditManagerPassword);
}
}
package com.x.base.core.project.config;
import java.io.File;
import java.io.UnsupportedEncodingException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.spec.InvalidKeySpecException;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import javax.crypto.BadPaddingException;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.BooleanUtils;
......@@ -115,11 +123,13 @@ public class Token extends ConfigObject {
return this._password;
}
public void setPassword(String password) {
public void setPassword(String password)
throws InvalidKeyException, NoSuchAlgorithmException, InvalidKeySpecException, NoSuchPaddingException,
IllegalBlockSizeException, BadPaddingException, UnsupportedEncodingException {
if (StringUtils.equals(password, initPassword)) {
this.password = null;
} else {
this.password = password;
this.password = Crypto.formattedDefaultEncrypt(password);
}
}
......
......@@ -17,6 +17,7 @@ import java.security.spec.InvalidKeySpecException;
import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.X509EncodedKeySpec;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
......@@ -54,6 +55,11 @@ public class Crypto {
private static final String TYPE_SM4 = "sm4";
private static final Pattern PLAINTEXT_TRANSFORM_REGEX = Pattern.compile("^\\((ENCRYPT:|SCRIPT:)(.+?)\\)$");
private static final String ENCRYPT_PREFIX = "ENCRYPT:";
private static final String SCRIPT_PREFIX = "SCRIPT:";
public static String encrypt(String data, String key) throws Exception {
return encrypt(data, key, Config.person().getEncryptType());
}
......@@ -193,24 +199,24 @@ public class Crypto {
if (StringUtils.isEmpty(text)) {
return text;
}
try {
Matcher matcher = StringTools.SCRIPTTEXT_REGEX.matcher(text);
if (matcher.matches()) {
String value = StringEscapeUtils.unescapeJson(matcher.group(1));
if (StringUtils.startsWithIgnoreCase(value, "ENCRYPT:")) {
String de = StringUtils.substringAfter(value, ":");
return decrypt(de, NEVERCHANGEKEY, null);
} else {
CompiledScript cs = ScriptingFactory.functionalizationCompile(text);
Matcher matcher = PLAINTEXT_TRANSFORM_REGEX.matcher(text);
if (matcher.matches()) {
try {
if (StringUtils.startsWithIgnoreCase(matcher.group(1), ENCRYPT_PREFIX)) {
return decrypt(matcher.group(2), NEVERCHANGEKEY, null);
} else if (StringUtils.startsWithIgnoreCase(matcher.group(1), SCRIPT_PREFIX)) {
CompiledScript cs = ScriptingFactory
.functionalizationCompile(StringEscapeUtils.unescapeJson(matcher.group(2)));
ScriptContext scriptContext = new SimpleScriptContext();
return JsonScriptingExecutor.evalString(cs, scriptContext);
}
} else {
return text;
} catch (Exception e) {
e.printStackTrace();
}
} catch (Exception e) {
e.printStackTrace();
} else {
return text;
}
return null;
}
......@@ -221,4 +227,10 @@ public class Crypto {
String str = Base64.encodeBase64URLSafeString(bt);
return URLEncoder.encode(str, StandardCharsets.UTF_8.name());
}
public static String formattedDefaultEncrypt(String data)
throws InvalidKeyException, NoSuchAlgorithmException, InvalidKeySpecException, NoSuchPaddingException,
IllegalBlockSizeException, BadPaddingException, UnsupportedEncodingException {
return "(" + ENCRYPT_PREFIX + defaultEncrypt(data) + ")";
}
}
......@@ -96,11 +96,8 @@ public class DumpData {
DateTools.compact(start) + "_dump.xml");
PersistenceXmlHelper.write(xml.toString(), classNames, true, classLoader);
StorageMappings storageMappings = Config.storageMappings();
Stream<String> stream = BooleanUtils.isTrue(Config.dumpRestoreData().getParallel())
? classNames.parallelStream()
: classNames.stream();
AtomicInteger idx = new AtomicInteger(1);
stream.forEach(className -> {
classNames.stream().forEach(className -> {
Thread.currentThread().setContextClassLoader(classLoader);
String nameOfThread = Thread.currentThread().getName();
Thread.currentThread().setName(DumpData.class.getName() + ":" + className);
......
......@@ -111,12 +111,9 @@ public class RestoreData {
Path xml = Paths.get(Config.dir_local_temp_classes().getAbsolutePath(),
DateTools.compact(start) + "_restore.xml");
PersistenceXmlHelper.write(xml.toString(), classNames, true, classLoader);
Stream<String> stream = BooleanUtils.isTrue(Config.dumpRestoreData().getParallel())
? classNames.parallelStream()
: classNames.stream();
AtomicInteger idx = new AtomicInteger(1);
AtomicLong total = new AtomicLong(0);
stream.forEach(className -> {
classNames.stream().forEach(className -> {
Thread.currentThread().setContextClassLoader(classLoader);
try {
@SuppressWarnings("unchecked")
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册