提交 72351661 编写于 作者: O o2null

Merge branch 'feature/index' into 'develop'

enable encrypt password

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