提交 92e7d568 编写于 作者: O o2null

codeSafe 安全扫描更新

上级 83a86925
...@@ -109,20 +109,16 @@ public class ActionCommand extends BaseAction { ...@@ -109,20 +109,16 @@ public class ActionCommand extends BaseAction {
private boolean executeSyncFile(String syncFilePath, String nodeName, int nodePort) { private boolean executeSyncFile(String syncFilePath, String nodeName, int nodePort) {
boolean syncFileFlag = false; boolean syncFileFlag = false;
File syncFile; File syncFile;
InputStream fileInputStream = null;
try (Socket socket = new Socket(nodeName, nodePort)) { try (Socket socket = new Socket(nodeName, nodePort)) {
syncFile = new File(Config.base(), syncFilePath); syncFile = new File(Config.base(), syncFilePath);
fileInputStream = new FileInputStream(syncFile);
socket.setKeepAlive(true); socket.setKeepAlive(true);
socket.setSoTimeout(5000); socket.setSoTimeout(5000);
DataOutputStream dos = null; try (InputStream fileInputStream = new FileInputStream(syncFile);
DataInputStream dis = null; DataOutputStream dos = new DataOutputStream(socket.getOutputStream());
try { DataInputStream dis = new DataInputStream(socket.getInputStream());) {
dos = new DataOutputStream(socket.getOutputStream());
dis = new DataInputStream(socket.getInputStream());
Map<String, Object> commandObject = new HashMap<>(); Map<String, Object> commandObject = new HashMap<>();
commandObject.put("command", "syncFile:" + syncFilePath); commandObject.put("command", "syncFile:" + syncFilePath);
...@@ -142,11 +138,6 @@ public class ActionCommand extends BaseAction { ...@@ -142,11 +138,6 @@ public class ActionCommand extends BaseAction {
} }
logger.info("同步文件end......."); logger.info("同步文件end.......");
} finally {
dos.close();
dis.close();
socket.close();
fileInputStream.close();
} }
syncFileFlag = true; syncFileFlag = true;
......
package com.x.program.center.jaxrs.config; package com.x.program.center.jaxrs.config;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.net.Socket;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.BooleanUtils;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import com.google.gson.JsonSyntaxException;
import com.x.base.core.project.annotation.FieldDescribe; import com.x.base.core.project.annotation.FieldDescribe;
import com.x.base.core.project.config.Config; import com.x.base.core.project.config.Config;
import com.x.base.core.project.config.Nodes; import com.x.base.core.project.config.Nodes;
...@@ -14,26 +29,19 @@ import com.x.base.core.project.logger.Logger; ...@@ -14,26 +29,19 @@ import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory; import com.x.base.core.project.logger.LoggerFactory;
import com.x.base.core.project.tools.Crypto; import com.x.base.core.project.tools.Crypto;
import com.x.base.core.project.tools.DefaultCharset; import com.x.base.core.project.tools.DefaultCharset;
import org.apache.commons.io.FileUtils;
import javax.servlet.http.HttpServletRequest;
import java.io.*;
import java.net.Socket;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
public class ActionSave extends BaseAction { public class ActionSave extends BaseAction {
private static Logger logger = LoggerFactory.getLogger(ActionSave.class); private static Logger logger = LoggerFactory.getLogger(ActionSave.class);
ActionResult<Wo> execute(HttpServletRequest request, EffectivePerson effectivePerson,JsonElement jsonElement) throws Exception {
ActionResult<Wo> execute(HttpServletRequest request, EffectivePerson effectivePerson, JsonElement jsonElement)
throws Exception {
ActionResult<Wo> result = new ActionResult<>(); ActionResult<Wo> result = new ActionResult<>();
Wi wi = this.convertToWrapIn(jsonElement, Wi.class); Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
Wo wo = new Wo(); Wo wo = new Wo();
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String fileName = wi.getFileName(); String fileName = wi.getFileName();
if(fileName == null) { if (fileName == null) {
throw new ExceptionNameEmpty(); throw new ExceptionNameEmpty();
} }
...@@ -49,37 +57,40 @@ public class ActionSave extends BaseAction { ...@@ -49,37 +57,40 @@ public class ActionSave extends BaseAction {
throw new ExceptionJsonError(); throw new ExceptionJsonError();
} }
if(!Config.nodes().centerServers().first().getValue().getConfigApiEnable()) { if (BooleanUtils.isNotTrue(Config.nodes().centerServers().first().getValue().getConfigApiEnable())) {
throw new ExceptionModifyConfig(); throw new ExceptionModifyConfig();
} }
File configFold = new File(Config.base(),Config.DIR_CONFIG); File configFold = new File(Config.base(), Config.DIR_CONFIG);
if(!configFold.exists()){ if (!configFold.exists()) {
configFold.mkdir(); configFold.mkdir();
} }
File file = new File(Config.base(),Config.DIR_CONFIG+"/"+fileName); File file = new File(Config.base(), Config.DIR_CONFIG + "/" + fileName);
if(!file.exists()) { if (!file.exists()) {
file.createNewFile(); file.createNewFile();
} }
if(file.exists()) { if (file.exists()) {
if(file.isFile()) { if (file.isFile()) {
FileUtils.writeStringToFile(file, data, DefaultCharset.charset); FileUtils.writeStringToFile(file, data, DefaultCharset.charset);
} }
} }
Nodes nodes = Config.nodes(); Nodes nodes = Config.nodes();
//同步config文件 // 同步config文件
for (String node : nodes.keySet()){ for (String node : nodes.keySet()) {
if(nodes.get(node).getApplication().getEnable() || nodes.get(node).getCenter().getEnable()){ if (nodes.get(node).getApplication().getEnable() || nodes.get(node).getCenter().getEnable()) {
boolean Syncflag = executeSyncFile(Config.DIR_CONFIG+"/"+fileName , node ,nodes.get(node).nodeAgentPort()); // boolean Syncflag = executeSyncFile(Config.DIR_CONFIG + "/" + fileName, node,
// nodes.get(node).nodeAgentPort());
executeSyncFile(Config.DIR_CONFIG + "/" + fileName, node, nodes.get(node).nodeAgentPort());
} }
} }
try { try {
Thread.sleep(1000); Thread.sleep(1000);
} catch (InterruptedException e) { } catch (InterruptedException e) {
logger.error(e);
} }
this.configFlush(effectivePerson); this.configFlush(effectivePerson);
...@@ -90,29 +101,19 @@ public class ActionSave extends BaseAction { ...@@ -90,29 +101,19 @@ public class ActionSave extends BaseAction {
return result; return result;
} }
private boolean executeSyncFile(String syncFilePath, String nodeName, int nodePort) {
boolean syncFileFlag = false;
File syncFile;
private boolean executeSyncFile(String syncFilePath , String nodeName ,int nodePort){
boolean syncFileFlag = false;
File syncFile;
InputStream fileInputStream = null;
try (Socket socket = new Socket(nodeName, nodePort)) { try (Socket socket = new Socket(nodeName, nodePort)) {
syncFile = new File(Config.base(), syncFilePath); syncFile = new File(Config.base(), syncFilePath);
fileInputStream= new FileInputStream(syncFile);
socket.setKeepAlive(true); socket.setKeepAlive(true);
socket.setSoTimeout(5000); socket.setSoTimeout(5000);
DataOutputStream dos = null; try (DataOutputStream dos = new DataOutputStream(socket.getOutputStream());
DataInputStream dis = null; DataInputStream dis = new DataInputStream(socket.getInputStream());
try { InputStream fileInputStream = new FileInputStream(syncFile)) {
dos = new DataOutputStream(socket.getOutputStream());
dis = new DataInputStream(socket.getInputStream());
Map<String, Object> commandObject = new HashMap<>(); Map<String, Object> commandObject = new HashMap<>();
commandObject.put("command", "syncFile:"+ syncFilePath); commandObject.put("command", "syncFile:" + syncFilePath);
commandObject.put("credential", Crypto.rsaEncrypt("o2@", Config.publicKey())); commandObject.put("credential", Crypto.rsaEncrypt("o2@", Config.publicKey()));
dos.writeUTF(XGsonBuilder.toJson(commandObject)); dos.writeUTF(XGsonBuilder.toJson(commandObject));
dos.flush(); dos.flush();
...@@ -120,23 +121,15 @@ public class ActionSave extends BaseAction { ...@@ -120,23 +121,15 @@ public class ActionSave extends BaseAction {
dos.writeUTF(syncFilePath); dos.writeUTF(syncFilePath);
dos.flush(); dos.flush();
logger.info("同步文件starting......."); logger.info("同步文件starting.......");
byte[] bytes = new byte[1024]; byte[] bytes = new byte[1024];
int length =0; int length = 0;
while((length = fileInputStream.read(bytes, 0, bytes.length)) != -1) { while ((length = fileInputStream.read(bytes, 0, bytes.length)) != -1) {
dos.write(bytes, 0, length); dos.write(bytes, 0, length);
dos.flush(); dos.flush();
} }
logger.info("同步文件end......."); logger.info("同步文件end.......");
}finally {
dos.close();
dis.close();
socket.close();
fileInputStream.close();
} }
syncFileFlag = true; syncFileFlag = true;
} catch (Exception ex) { } catch (Exception ex) {
logger.error(ex); logger.error(ex);
...@@ -145,7 +138,7 @@ public class ActionSave extends BaseAction { ...@@ -145,7 +138,7 @@ public class ActionSave extends BaseAction {
return syncFileFlag; return syncFileFlag;
} }
public static class Wi extends GsonPropertyObject{ public static class Wi extends GsonPropertyObject {
@FieldDescribe("服务器地址(*代表多台应用服务器)") @FieldDescribe("服务器地址(*代表多台应用服务器)")
private String nodeName; private String nodeName;
...@@ -162,30 +155,35 @@ public class ActionSave extends BaseAction { ...@@ -162,30 +155,35 @@ public class ActionSave extends BaseAction {
public String getNodeName() { public String getNodeName() {
return nodeName; return nodeName;
} }
public void setNodeName(String nodeName) { public void setNodeName(String nodeName) {
this.nodeName = nodeName; this.nodeName = nodeName;
} }
public String getNodePort() { public String getNodePort() {
return nodePort; return nodePort;
} }
public void setNodePort(String nodePort) { public void setNodePort(String nodePort) {
this.nodePort = nodePort; this.nodePort = nodePort;
} }
public String getFileName() { public String getFileName() {
return fileName; return fileName;
} }
public void setFileName(String fileName) { public void setFileName(String fileName) {
this.fileName = fileName; this.fileName = fileName;
} }
public String getFileContent() { public String getFileContent() {
return fileContent; return fileContent;
} }
public void setFileContent(String fileContent) { public void setFileContent(String fileContent) {
this.fileContent = fileContent; this.fileContent = fileContent;
} }
} }
public static class Wo extends GsonPropertyObject { public static class Wo extends GsonPropertyObject {
...@@ -236,6 +234,7 @@ public class ActionSave extends BaseAction { ...@@ -236,6 +234,7 @@ public class ActionSave extends BaseAction {
public void setSample(boolean isSample) { public void setSample(boolean isSample) {
this.isSample = isSample; this.isSample = isSample;
} }
public String getMessage() { public String getMessage() {
return message; return message;
} }
......
package com.x.program.center.jaxrs.dingding.encrypt; package com.x.program.center.jaxrs.dingding.encrypt;
import org.apache.commons.codec.binary.Base64; import org.apache.commons.codec.binary.Base64;
import javax.crypto.Cipher; import javax.crypto.Cipher;
...@@ -18,202 +17,210 @@ import java.util.HashMap; ...@@ -18,202 +17,210 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
/** /**
* Created by fancyLou on 2020-10-26. * Created by fancyLou on 2020-10-26. Copyright © 2020 O2. All rights reserved.
* Copyright © 2020 O2. All rights reserved.
*/ */
public class DingTalkEncryptor { public class DingTalkEncryptor {
private static final Charset CHARSET = Charset.forName("utf-8"); private static final Charset CHARSET = Charset.forName("utf-8");
private static final Base64 base64 = new Base64(); private static final Base64 base64 = new Base64();
private byte[] aesKey; private byte[] aesKey;
private String token; private String token;
private String corpId; private String corpId;
private static final Integer AES_ENCODE_KEY_LENGTH = 43; private static final Integer AES_ENCODE_KEY_LENGTH = 43;
private static final Integer RANDOM_LENGTH = 16; private static final Integer RANDOM_LENGTH = 16;
public DingTalkEncryptor(String token, String encodingAesKey, String corpIdOrSuiteKey) throws DingTalkEncryptException { public DingTalkEncryptor(String token, String encodingAesKey, String corpIdOrSuiteKey)
if (null != encodingAesKey && encodingAesKey.length() == AES_ENCODE_KEY_LENGTH) { throws DingTalkEncryptException {
this.token = token; if (null != encodingAesKey && encodingAesKey.length() == AES_ENCODE_KEY_LENGTH) {
this.corpId = corpIdOrSuiteKey; this.token = token;
this.aesKey = Base64.decodeBase64(encodingAesKey + "="); this.corpId = corpIdOrSuiteKey;
} else { this.aesKey = Base64.decodeBase64(encodingAesKey + "=");
throw new DingTalkEncryptException(900004); } else {
} throw new DingTalkEncryptException(900004);
} }
}
public Map<String, String> getEncryptedMap(String plaintext, Long timeStamp, String nonce) throws DingTalkEncryptException {
if (null == plaintext) { public Map<String, String> getEncryptedMap(String plaintext, Long timeStamp, String nonce)
throw new DingTalkEncryptException(900001); throws DingTalkEncryptException {
} else if (null == timeStamp) { if (null == plaintext) {
throw new DingTalkEncryptException(900002); throw new DingTalkEncryptException(900001);
} else if (null == nonce) { } else if (null == timeStamp) {
throw new DingTalkEncryptException(900003); throw new DingTalkEncryptException(900002);
} else { } else if (null == nonce) {
String encrypt = this.encrypt(Utils.getRandomStr(RANDOM_LENGTH), plaintext); throw new DingTalkEncryptException(900003);
String signature = this.getSignature(this.token, String.valueOf(timeStamp), nonce, encrypt); } else {
Map<String, String> resultMap = new HashMap(); String encrypt = this.encrypt(Utils.getRandomStr(RANDOM_LENGTH), plaintext);
resultMap.put("msg_signature", signature); String signature = this.getSignature(this.token, String.valueOf(timeStamp), nonce, encrypt);
resultMap.put("encrypt", encrypt); Map<String, String> resultMap = new HashMap();
resultMap.put("timeStamp", String.valueOf(timeStamp)); resultMap.put("msg_signature", signature);
resultMap.put("nonce", nonce); resultMap.put("encrypt", encrypt);
return resultMap; resultMap.put("timeStamp", String.valueOf(timeStamp));
} resultMap.put("nonce", nonce);
} return resultMap;
}
public String getDecryptMsg(String msgSignature, String timeStamp, String nonce, String encryptMsg) throws DingTalkEncryptException { }
String signature = this.getSignature(this.token, timeStamp, nonce, encryptMsg);
if (!signature.equals(msgSignature)) { public String getDecryptMsg(String msgSignature, String timeStamp, String nonce, String encryptMsg)
throw new DingTalkEncryptException(900006); throws DingTalkEncryptException {
} else { String signature = this.getSignature(this.token, timeStamp, nonce, encryptMsg);
String result = this.decrypt(encryptMsg); if (!signature.equals(msgSignature)) {
return result; throw new DingTalkEncryptException(900006);
} } else {
} String result = this.decrypt(encryptMsg);
return result;
private String encrypt(String random, String plaintext) throws DingTalkEncryptException { }
try { }
byte[] randomBytes = random.getBytes(CHARSET);
byte[] plainTextBytes = plaintext.getBytes(CHARSET); private String encrypt(String random, String plaintext) throws DingTalkEncryptException {
byte[] lengthByte = Utils.int2Bytes(plainTextBytes.length); try {
byte[] corpidBytes = this.corpId.getBytes(CHARSET); byte[] randomBytes = random.getBytes(CHARSET);
ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); byte[] plainTextBytes = plaintext.getBytes(CHARSET);
byteStream.write(randomBytes); byte[] lengthByte = Utils.int2Bytes(plainTextBytes.length);
byteStream.write(lengthByte); byte[] corpidBytes = this.corpId.getBytes(CHARSET);
byteStream.write(plainTextBytes); ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
byteStream.write(corpidBytes); byteStream.write(randomBytes);
byte[] padBytes = PKCS7Padding.getPaddingBytes(byteStream.size()); byteStream.write(lengthByte);
byteStream.write(padBytes); byteStream.write(plainTextBytes);
byte[] unencrypted = byteStream.toByteArray(); byteStream.write(corpidBytes);
byteStream.close(); byte[] padBytes = PKCS7Padding.getPaddingBytes(byteStream.size());
Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding"); byteStream.write(padBytes);
SecretKeySpec keySpec = new SecretKeySpec(this.aesKey, "AES"); byte[] unencrypted = byteStream.toByteArray();
IvParameterSpec iv = new IvParameterSpec(this.aesKey, 0, 16); byteStream.close();
cipher.init(Cipher.ENCRYPT_MODE, keySpec, iv); Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding");
byte[] encrypted = cipher.doFinal(unencrypted); SecretKeySpec keySpec = new SecretKeySpec(this.aesKey, "AES");
String result = base64.encodeToString(encrypted); IvParameterSpec iv = new IvParameterSpec(this.aesKey, 0, 16);
return result; cipher.init(Cipher.ENCRYPT_MODE, keySpec, iv);
byte[] encrypted = cipher.doFinal(unencrypted);
} catch (Exception var15) { String result = base64.encodeToString(encrypted);
throw new DingTalkEncryptException(900007); return result;
}
} } catch (Exception var15) {
throw new DingTalkEncryptException(900007);
private String decrypt(String text) throws DingTalkEncryptException { }
byte[] originalArr; }
byte[] networkOrder;
try { private String decrypt(String text) throws DingTalkEncryptException {
Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding"); byte[] originalArr;
SecretKeySpec keySpec = new SecretKeySpec(this.aesKey, "AES"); byte[] networkOrder;
IvParameterSpec iv = new IvParameterSpec(Arrays.copyOfRange(this.aesKey, 0, 16)); try {
cipher.init(2, keySpec, iv); Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding");
networkOrder = Base64.decodeBase64(text); SecretKeySpec keySpec = new SecretKeySpec(this.aesKey, "AES");
originalArr = cipher.doFinal(networkOrder); IvParameterSpec iv = new IvParameterSpec(Arrays.copyOfRange(this.aesKey, 0, 16));
} catch (Exception var9) { cipher.init(2, keySpec, iv);
throw new DingTalkEncryptException(900008); networkOrder = Base64.decodeBase64(text);
} originalArr = cipher.doFinal(networkOrder);
} catch (Exception var9) {
String plainText; throw new DingTalkEncryptException(900008);
String fromCorpid; }
try {
byte[] bytes = PKCS7Padding.removePaddingBytes(originalArr); String plainText;
networkOrder = Arrays.copyOfRange(bytes, 16, 20); String fromCorpid;
int plainTextLegth = Utils.bytes2int(networkOrder); try {
plainText = new String(Arrays.copyOfRange(bytes, 20, 20 + plainTextLegth), CHARSET); byte[] bytes = PKCS7Padding.removePaddingBytes(originalArr);
fromCorpid = new String(Arrays.copyOfRange(bytes, 20 + plainTextLegth, bytes.length), CHARSET); networkOrder = Arrays.copyOfRange(bytes, 16, 20);
} catch (Exception var8) { int plainTextLegth = Utils.bytes2int(networkOrder);
throw new DingTalkEncryptException(900009); plainText = new String(Arrays.copyOfRange(bytes, 20, 20 + plainTextLegth), CHARSET);
} fromCorpid = new String(Arrays.copyOfRange(bytes, 20 + plainTextLegth, bytes.length), CHARSET);
} catch (Exception var8) {
if (!fromCorpid.equals(this.corpId)) { throw new DingTalkEncryptException(900009);
throw new DingTalkEncryptException(900010); }
} else {
return plainText; if (!fromCorpid.equals(this.corpId)) {
} throw new DingTalkEncryptException(900010);
} } else {
return plainText;
public String getSignature(String token, String timestamp, String nonce, String encrypt) throws DingTalkEncryptException { }
try { }
String[] array = new String[]{token, timestamp, nonce, encrypt};
Arrays.sort(array); public String getSignature(String token, String timestamp, String nonce, String encrypt)
StringBuffer sb = new StringBuffer(); throws DingTalkEncryptException {
try {
for(int i = 0; i < 4; ++i) { String[] array = new String[] { token, timestamp, nonce, encrypt };
sb.append(array[i]); Arrays.sort(array);
} StringBuffer sb = new StringBuffer();
String str = sb.toString(); for (int i = 0; i < 4; ++i) {
MessageDigest md = MessageDigest.getInstance("SHA-1"); sb.append(array[i]);
md.update(str.getBytes()); }
byte[] digest = md.digest();
StringBuffer hexstr = new StringBuffer(); String str = sb.toString();
String shaHex = ""; MessageDigest md = MessageDigest.getInstance("SHA-1");
md.update(str.getBytes());
for(int i = 0; i < digest.length; ++i) { byte[] digest = md.digest();
shaHex = Integer.toHexString(digest[i] & 255); StringBuffer hexstr = new StringBuffer();
if (shaHex.length() < 2) { String shaHex = "";
hexstr.append(0);
} for (int i = 0; i < digest.length; ++i) {
shaHex = Integer.toHexString(digest[i] & 255);
hexstr.append(shaHex); if (shaHex.length() < 2) {
} hexstr.append(0);
}
return hexstr.toString();
} catch (Exception var13) { hexstr.append(shaHex);
throw new DingTalkEncryptException(900006); }
}
} return hexstr.toString();
} catch (Exception var13) {
private static void RemoveCryptographyRestrictions() throws Exception { throw new DingTalkEncryptException(900006);
Class<?> jceSecurity = getClazz("javax.crypto.JceSecurity"); }
Class<?> cryptoPermissions = getClazz("javax.crypto.CryptoPermissions"); }
Class<?> cryptoAllPermission = getClazz("javax.crypto.CryptoAllPermission");
if (jceSecurity != null) { private static void RemoveCryptographyRestrictions() throws Exception {
setFinalStaticValue(jceSecurity, "isRestricted", false); Class<?> jceSecurity = getClazz("javax.crypto.JceSecurity");
PermissionCollection defaultPolicy = (PermissionCollection)getFieldValue(jceSecurity, "defaultPolicy", (Object)null, PermissionCollection.class); Class<?> cryptoPermissions = getClazz("javax.crypto.CryptoPermissions");
if (cryptoPermissions != null) { Class<?> cryptoAllPermission = getClazz("javax.crypto.CryptoAllPermission");
Map<?, ?> map = (Map)getFieldValue(cryptoPermissions, "perms", defaultPolicy, Map.class); if (jceSecurity != null) {
map.clear(); setFinalStaticValue(jceSecurity, "isRestricted", false);
} PermissionCollection defaultPolicy = (PermissionCollection) getFieldValue(jceSecurity, "defaultPolicy",
(Object) null, PermissionCollection.class);
if (cryptoAllPermission != null) { if (cryptoPermissions != null) {
Permission permission = (Permission)getFieldValue(cryptoAllPermission, "INSTANCE", (Object)null, Permission.class); Map<?, ?> map = (Map) getFieldValue(cryptoPermissions, "perms", defaultPolicy, Map.class);
defaultPolicy.add(permission); map.clear();
} }
}
if (cryptoAllPermission != null) {
} Permission permission = (Permission) getFieldValue(cryptoAllPermission, "INSTANCE", (Object) null,
Permission.class);
private static Class<?> getClazz(String className) { defaultPolicy.add(permission);
Class clazz = null; }
}
try {
clazz = Class.forName(className); }
} catch (Exception var3) {
} private static Class<?> getClazz(String className) {
Class clazz = null;
return clazz;
} try {
clazz = Class.forName(className);
private static void setFinalStaticValue(Class<?> srcClazz, String fieldName, Object newValue) throws Exception { } catch (Exception var3) {
Field field = srcClazz.getDeclaredField(fieldName); var3.printStackTrace(System.out);
field.setAccessible(true); }
Field modifiersField = Field.class.getDeclaredField("modifiers");
modifiersField.setAccessible(true); return clazz;
modifiersField.setInt(field, field.getModifiers() & -17); }
field.set((Object)null, newValue);
} private static void setFinalStaticValue(Class<?> srcClazz, String fieldName, Object newValue) throws Exception {
Field field = srcClazz.getDeclaredField(fieldName);
private static <T> T getFieldValue(Class<?> srcClazz, String fieldName, Object owner, Class<T> dstClazz) throws Exception { field.setAccessible(true);
Field field = srcClazz.getDeclaredField(fieldName); Field modifiersField = Field.class.getDeclaredField("modifiers");
field.setAccessible(true); modifiersField.setAccessible(true);
return dstClazz.cast(field.get(owner)); modifiersField.setInt(field, field.getModifiers() & -17);
} field.set((Object) null, newValue);
}
static {
try { private static <T> T getFieldValue(Class<?> srcClazz, String fieldName, Object owner, Class<T> dstClazz)
Security.setProperty("crypto.policy", "limited"); throws Exception {
RemoveCryptographyRestrictions(); Field field = srcClazz.getDeclaredField(fieldName);
} catch (Exception var1) { field.setAccessible(true);
} return dstClazz.cast(field.get(owner));
}
}
static {
try {
Security.setProperty("crypto.policy", "limited");
RemoveCryptographyRestrictions();
} catch (Exception var1) {
var1.printStackTrace(System.out);
}
}
} }
...@@ -37,11 +37,10 @@ abstract class BaseAction extends StandardJaxrsAction { ...@@ -37,11 +37,10 @@ abstract class BaseAction extends StandardJaxrsAction {
private static CopyOnWriteArrayList<Class<?>> assembles; private static CopyOnWriteArrayList<Class<?>> assembles;
private static String HOST_LOCALHOST = "localhost"; private static final String HOST_LOCALHOST = "localhost";
protected String getHost(HttpServletRequest request) throws Exception { protected String getHost(HttpServletRequest request) throws Exception {
URL url = new URL(request.getRequestURL().toString()); return new URL(request.getRequestURL().toString()).getHost();
return url.getHost();
} }
protected boolean isUndefindHost(String host) { protected boolean isUndefindHost(String host) {
......
...@@ -143,7 +143,7 @@ public class SyncOrganization { ...@@ -143,7 +143,7 @@ public class SyncOrganization {
unit = this.createUnit(business, result, sup, org); unit = this.createUnit(business, result, sup, org);
} else { } else {
if (!StringUtils.equals(unit.getQiyeweixinHash(), DigestUtils.sha256Hex(XGsonBuilder.toJson(org)))) { if (!StringUtils.equals(unit.getQiyeweixinHash(), DigestUtils.sha256Hex(XGsonBuilder.toJson(org)))) {
logger.print("组织【{}】的hash值变化,更新组织====",org.getName()); logger.print("组织【{}】的hash值变化,更新组织====", org.getName());
unit = this.updateUnit(business, result, unit, org); unit = this.updateUnit(business, result, unit, org);
} }
} }
...@@ -203,17 +203,17 @@ public class SyncOrganization { ...@@ -203,17 +203,17 @@ public class SyncOrganization {
logger.print("正在检查下级组织{},如果存在下级组织,则先删除下级组织.", unit.getDistinguishedName()); logger.print("正在检查下级组织{},如果存在下级组织,则先删除下级组织.", unit.getDistinguishedName());
List<Unit> subUnits = business.unit().listSubNestedObject(unit); List<Unit> subUnits = business.unit().listSubNestedObject(unit);
if( ListTools.isNotEmpty( subUnits )){ if (ListTools.isNotEmpty(subUnits)) {
for( Unit subUnit : subUnits ){ for (Unit subUnit : subUnits) {
removeSingleUnit( business, result, subUnit ); removeSingleUnit(business, result, subUnit);
} }
} }
logger.print("正在尝试删除单个组织{}.", unit.getDistinguishedName()); logger.print("正在尝试删除单个组织{}.", unit.getDistinguishedName());
EntityManagerContainer emc = business.entityManagerContainer(); EntityManagerContainer emc = business.entityManagerContainer();
//检查一下,该组织是否已经被删除过了 // 检查一下,该组织是否已经被删除过了
unit = emc.find( unit.getId(), Unit.class ); unit = emc.find(unit.getId(), Unit.class);
if( unit != null ){ if (unit != null) {
emc.beginTransaction(UnitAttribute.class); emc.beginTransaction(UnitAttribute.class);
emc.beginTransaction(UnitDuty.class); emc.beginTransaction(UnitDuty.class);
emc.beginTransaction(Identity.class); emc.beginTransaction(Identity.class);
...@@ -246,11 +246,11 @@ public class SyncOrganization { ...@@ -246,11 +246,11 @@ public class SyncOrganization {
person = this.createOrLinkPerson(business, result, user); person = this.createOrLinkPerson(business, result, user);
} }
} else { } else {
if ((StringUtils.isNotEmpty(user.getMobile())) && StringUtils.isNotEmpty(user.getName())) { if ((StringUtils.isNotEmpty(user.getMobile())) && StringUtils.isNotEmpty(user.getName())) {
if (!StringUtils.equals(DigestUtils.sha256Hex(XGsonBuilder.toJson(user)), person.getQiyeweixinHash())) { if (!StringUtils.equals(DigestUtils.sha256Hex(XGsonBuilder.toJson(user)), person.getQiyeweixinHash())) {
person = this.updatePerson(business, result, person, user); person = this.updatePerson(business, result, person, user);
} }
} }
} }
return person; return person;
} }
...@@ -290,19 +290,6 @@ public class SyncOrganization { ...@@ -290,19 +290,6 @@ public class SyncOrganization {
return person; return person;
} }
// private String getPassword(ScriptEngine engine, Pattern pattern, Person person) throws Exception {
// String str = Config.person().getPassword();
// Matcher matcher = pattern.matcher(str);
// if (matcher.matches()) {
// String eval = matcher.group(1);
// engine.put("person", person);
// String pass = engine.eval(eval).toString();
// return pass;
// } else {
// return str;
// }
// }
private String initPassword(Business business, Person person) throws Exception { private String initPassword(Business business, Person person) throws Exception {
String str = Config.person().getPassword(); String str = Config.person().getPassword();
Pattern pattern = Pattern.compile(com.x.base.core.project.config.Person.REGULAREXPRESSION_SCRIPT); Pattern pattern = Pattern.compile(com.x.base.core.project.config.Person.REGULAREXPRESSION_SCRIPT);
...@@ -521,7 +508,7 @@ public class SyncOrganization { ...@@ -521,7 +508,7 @@ public class SyncOrganization {
List<Person> allPeople = this.listPerson(business); List<Person> allPeople = this.listPerson(business);
/* 删除个人 */ /* 删除个人 */
for (Person person : ListUtils.subtract(allPeople, people)) { for (Person person : ListUtils.subtract(allPeople, people)) {
logger.print("删除用户:{}",person.getDistinguishedName()); logger.print("删除用户:{}", person.getDistinguishedName());
this.removePerson(business, result, person); this.removePerson(business, result, person);
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册