Commit f5f1108e by WeiCong

调通e结算第一版

parent df85524c
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
</repositories> </repositories>
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>GBK</project.build.sourceEncoding>
<maven-dependency-plugin.version>3.2.0</maven-dependency-plugin.version> <maven-dependency-plugin.version>3.2.0</maven-dependency-plugin.version>
<spring.version>5.1.3.RELEASE</spring.version> <spring.version>5.1.3.RELEASE</spring.version>
<slf4j-api_version>1.7.25</slf4j-api_version> <slf4j-api_version>1.7.25</slf4j-api_version>
......
package cn.com.brilliance.eibs.auth; package cn.com.brilliance.eibs.auth;
import java.sql.Connection; import org.sss.common.impl.AbstractLoginContext;
import java.util.Map; import org.sss.common.model.IMenuItem;
import org.sss.common.impl.AbstractLoginContext; import java.sql.Connection;
import org.sss.common.model.IMenuItem; import java.util.Map;
public class EmptyLoginContext extends AbstractLoginContext { public class EmptyLoginContext extends AbstractLoginContext {
private String userId; private String userId;
public EmptyLoginContext(String userId) { public EmptyLoginContext(String userId) {
this.userId = userId; this.userId = userId;
} }
@Override @Override
public String getLoginUser() { public String getLoginUser() {
return this.userId; return this.userId;
} }
@Override @Override
public boolean auth(Connection arg0, Map arg1) { public boolean auth(Connection arg0, Map arg1) {
return true; return true;
} }
@Override @Override
public IMenuItem getMenu() { public IMenuItem getMenu() {
return null; return null;
} }
@Override @Override
protected String getParameter(Map arg0, String arg1) { protected String getParameter(Map map, String key) {
return null; if (map == null){
} return null;
}
@Override Object o = map.get(key);
public Object getValue(String arg0) { if (o == null){
return null; return null;
} }
else if (o instanceof String){
@Override return (String) o;
public boolean login(Connection arg0, Map arg1) { }
return true; else if (o instanceof String[]){
} return ((String[]) o)[0];
}
} else{
return o.toString();
}
}
@Override
public Object getValue(String key) {
if ("usrinr".equals(key)){
return userId;
}
return null;
}
@Override
public boolean login(Connection arg0, Map arg1) {
return true;
}
}
...@@ -34,11 +34,6 @@ public class EhcacheCacheEventListener implements CacheEventListener { ...@@ -34,11 +34,6 @@ public class EhcacheCacheEventListener implements CacheEventListener {
@Override @Override
public void notifyElementExpired(Ehcache ehcache, Element element) { public void notifyElementExpired(Ehcache ehcache, Element element) {
System.out.println("销毁" + element.getObjectKey() + ":" + element.getObjectValue());
}
@Override
public void notifyElementEvicted(Ehcache ehcache, Element element) {
//获取过期的key //获取过期的key
String expireKey = String.valueOf(element.getObjectKey()); String expireKey = String.valueOf(element.getObjectKey());
log.debug("expireKey is:" + expireKey); log.debug("expireKey is:" + expireKey);
...@@ -57,6 +52,11 @@ public class EhcacheCacheEventListener implements CacheEventListener { ...@@ -57,6 +52,11 @@ public class EhcacheCacheEventListener implements CacheEventListener {
} }
@Override @Override
public void notifyElementEvicted(Ehcache ehcache, Element element) {
}
@Override
public void notifyRemoveAll(Ehcache ehcache) { public void notifyRemoveAll(Ehcache ehcache) {
} }
......
package org.sss.presentation.noui.common; package org.sss.presentation.noui.common;
import java.nio.charset.Charset;
public class Constants { public class Constants {
public final static String PARAMS = "params"; public final static String PARAMS = "params";
public final static String DATA = "data"; public final static String DATA = "data";
public final static String DISPLAY = "display"; public final static String DISPLAY = "display";
public final static String ENCODING = "UTF-8"; public final static String ENCODING = "UTF-8";
public static final Charset ENCODING_CHARSET = Charset.forName(ENCODING);
public final static String USERNAME = "username"; public final static String USERNAME = "username";
public final static String PASSWORD = "password"; public final static String PASSWORD = "password";
public final static String DNCODE = "dncode"; public final static String DNCODE = "dncode";
......
...@@ -50,7 +50,6 @@ public abstract class AbstractCommonController { ...@@ -50,7 +50,6 @@ public abstract class AbstractCommonController {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public Object event(String mappingUrl, String eventType, Map<String, Object> dataMap, MultipartFile file, HttpServletRequest request, HttpServletResponse response) { public Object event(String mappingUrl, String eventType, Map<String, Object> dataMap, MultipartFile file, HttpServletRequest request, HttpServletResponse response) {
NoUiContext context = null; NoUiContext context = null;
Result ret = null; Result ret = null;
String serverEnc = null; String serverEnc = null;
...@@ -295,12 +294,9 @@ public abstract class AbstractCommonController { ...@@ -295,12 +294,9 @@ public abstract class AbstractCommonController {
// 不能修改 // 不能修改
for (String key : modifyMap.keySet()) { for (String key : modifyMap.keySet()) {
if (!containsKeys.contains(key)) { if (!containsKeys.contains(key)) {
System.out.println("modify test:" + modifyMap.get(key).getClass()); if (key == null){
System.out.println("modify datafield:" + (modifyMap.get(key) instanceof IDatafield));
System.out.println("modify module:" + (modifyMap.get(key) instanceof IModule));
System.out.println("modify moduleList:" + (modifyMap.get(key) instanceof IModuleList));
if (key == null)
continue; continue;
}
Object baseObject = modifyMap.get(key); Object baseObject = modifyMap.get(key);
if( baseObject instanceof IModuleList) if( baseObject instanceof IModuleList)
{ {
......
package org.sss.presentation.noui.filter; package org.sss.presentation.noui.filter;
import com.google.gson.Gson; import com.google.gson.Gson;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest; import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
import org.sss.presentation.noui.api.response.ErrorCodes; import org.sss.presentation.noui.api.response.ErrorCodes;
import org.sss.presentation.noui.api.response.NoUiVersion; import org.sss.presentation.noui.api.response.NoUiVersion;
import org.sss.presentation.noui.api.response.Result; import org.sss.presentation.noui.api.response.Result;
import org.sss.presentation.noui.common.Constants;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletRequest;
import java.io.PrintWriter; import javax.servlet.http.HttpServletResponse;
import java.util.Iterator; import java.io.PrintWriter;
import java.util.Map; import java.util.Iterator;
import java.util.Map;
/**
* 全局文件类型拦截器 /**
*/ * 全局文件类型拦截器
public class FileTypeInterceptor extends HandlerInterceptorAdapter { */
public class FileTypeInterceptor extends HandlerInterceptorAdapter {
@Autowired
private NoUiVersion noUiVersion; @Autowired
private NoUiVersion noUiVersion;
private String type_list;
private String type_list;
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { @Override
boolean flag = true; public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
// 判断是否为文件上传请求 boolean flag = true;
if (request instanceof MultipartHttpServletRequest) { // 判断是否为文件上传请求
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; if (request instanceof MultipartHttpServletRequest) {
Map<String, MultipartFile> files = multipartRequest.getFileMap(); MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
Iterator<String> iterator = files.keySet().iterator(); Map<String, MultipartFile> files = multipartRequest.getFileMap();
//对多部件请求资源进行遍历 Iterator<String> iterator = files.keySet().iterator();
while (iterator.hasNext()) { //对多部件请求资源进行遍历
String formKey = (String) iterator.next(); while (iterator.hasNext()) {
MultipartFile multipartFile = multipartRequest.getFile(formKey); String formKey = (String) iterator.next();
String filename = multipartFile.getOriginalFilename(); MultipartFile multipartFile = multipartRequest.getFile(formKey);
//判断是否为限制文件类型 String filename = multipartFile.getOriginalFilename();
if (checkLimitFile(filename)) { //判断是否为限制文件类型
//限制文件类型,请求转发到原始请求页面,并携带错误提示信息 if (checkLimitFile(filename)) {
flag = false; //限制文件类型,请求转发到原始请求页面,并携带错误提示信息
response.setContentType("application/json; charset=utf-8"); flag = false;
Result result = new Result(ErrorCodes.ERROR, "不支持的文件类型!", null, noUiVersion.getVersion()); response.setContentType("application/json; charset="+ Constants.ENCODING);
PrintWriter out = response.getWriter(); Result result = new Result(ErrorCodes.ERROR, "不支持的文件类型!", null, noUiVersion.getVersion());
String json = new Gson().toJson(result); PrintWriter out = response.getWriter();
out.print(json); String json = new Gson().toJson(result);
out.flush(); out.print(json);
out.close(); out.flush();
} out.close();
} }
} }
return flag; }
} return flag;
}
/**
* 判断是否为允许的上传文件类型,true表示允许 /**
*/ * 判断是否为允许的上传文件类型,true表示允许
private boolean checkLimitFile(String fileName) { */
//设置允许上传文件类型 private boolean checkLimitFile(String fileName) {
// String suffixList = "jpg,gif,png,ico,bmp,jpeg"; //设置允许上传文件类型
String suffixList = type_list; // String suffixList = "jpg,gif,png,ico,bmp,jpeg";
// 获取文件后缀 String suffixList = type_list;
String suffix = fileName.substring(fileName.lastIndexOf(".") + 1, fileName.length()); // 获取文件后缀
if (suffixList.contains(suffix.trim().toLowerCase())) { String suffix = fileName.substring(fileName.lastIndexOf(".") + 1, fileName.length());
return true; if (suffixList.contains(suffix.trim().toLowerCase())) {
} return true;
return false; }
} return false;
}
public void setType_list(String type_list) {
this.type_list = type_list; public void setType_list(String type_list) {
} this.type_list = type_list;
}
} }
\ No newline at end of file
/* /*
* Create on 2007-11-15 * Create on 2007-11-15
*/ */
package org.sss.presentation.noui.filter; package org.sss.presentation.noui.filter;
import cfca.sadk.util.HashUtil; import cfca.sadk.util.HashUtil;
import log.Log; import log.Log;
import log.LogFactory; import log.LogFactory;
import org.sss.common.model.IFilter; import org.sss.common.model.IFilter;
import org.sss.util.ContainerUtils; import org.sss.presentation.noui.common.Constants;
import org.sss.util.ContainerUtils;
import java.nio.charset.StandardCharsets;
/**
/** * 密码过滤器实现(国密)
* 密码过滤器实现(国密) *
* * @author Jason.Hoo (latest modification by $Author: hujianxin $)
* @author Jason.Hoo (latest modification by $Author: hujianxin $) * @version $Revision: 1014 $ $Date: 2019-01-03 18:23:23 +0800 (Thu, 03 Jan 2019) $
* @version $Revision: 1014 $ $Date: 2019-01-03 18:23:23 +0800 (Thu, 03 Jan 2019) $ */
*/ public class PasswordSM2Filter
public class PasswordSM2Filter implements IFilter {
implements IFilter { static final Log log = LogFactory.getLog(PasswordSM2Filter.class);
static final Log log = LogFactory.getLog(PasswordSM2Filter.class);
public String decode(String encodedValue) {
public String decode(String encodedValue) { if (ContainerUtils.isEmpty(encodedValue))
if (ContainerUtils.isEmpty(encodedValue)) return null;
return null; return "**********";
return "**********"; }
}
public String encode(String value) {
public String encode(String value) { if (ContainerUtils.isEmpty(value))
if (ContainerUtils.isEmpty(value)) return value;
return value; byte[] encodedPassword = null;
byte[] encodedPassword = null; try {
try { encodedPassword = HashUtil.SM2HashMessageByBCWithoutZValue(value.getBytes(Constants.ENCODING));
encodedPassword = HashUtil.SM2HashMessageByBCWithoutZValue(value.getBytes(StandardCharsets.UTF_8)); StringBuffer buf = new StringBuffer();
StringBuffer buf = new StringBuffer(); for (int i = 0; i < encodedPassword.length; i++) {
for (int i = 0; i < encodedPassword.length; i++) { if ((encodedPassword[i] & 0xff) < 0x10) {
if ((encodedPassword[i] & 0xff) < 0x10) { buf.append("0");
buf.append("0"); }
} buf.append(Long.toString(encodedPassword[i] & 0xff, 16));
buf.append(Long.toString(encodedPassword[i] & 0xff, 16)); }
} return buf.toString();
return buf.toString(); } catch (Exception e) {
} catch (Exception e) { log.error("encode SM2 error.", e);
log.error("encode SM2 error.", e); return "";
return ""; }
} }
}
public String encode(String value, String salt) {
public String encode(String value, String salt) { return encode(salt+value);
return encode(salt+value); }
}
} }
\ No newline at end of file
...@@ -4,6 +4,7 @@ import log.Log; ...@@ -4,6 +4,7 @@ import log.Log;
import log.LogFactory; import log.LogFactory;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.sss.presentation.noui.common.Constants;
import org.sss.presentation.noui.util.NoUiUtils; import org.sss.presentation.noui.util.NoUiUtils;
import org.sss.presentation.noui.util.ResourceAcccessEncryptUtil; import org.sss.presentation.noui.util.ResourceAcccessEncryptUtil;
import org.sss.presentation.noui.util.StringUtil; import org.sss.presentation.noui.util.StringUtil;
...@@ -14,14 +15,13 @@ import javax.servlet.http.HttpServletResponse; ...@@ -14,14 +15,13 @@ import javax.servlet.http.HttpServletResponse;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.nio.charset.StandardCharsets;
public class ResourceAccessFilter implements Filter { public class ResourceAccessFilter implements Filter {
public static final String NO_FOUND_PDF = "/WEB-INF/classes/forbidden.pdf"; public static final String NO_FOUND_PDF = "/WEB-INF/classes/forbidden.pdf";
protected static final Log log = LogFactory.getLog(ResourceAccessFilter.class); protected static final Log log = LogFactory.getLog(ResourceAccessFilter.class);
private static final String _JSON_CONTENT = "application/json; charset=UTF-8"; private static final String _JSON_CONTENT = "application/json; charset="+Constants.ENCODING;
private static final String _HTML_CONTENT = "text/html; charset=UTF-8"; private static final String _HTML_CONTENT = "text/html; charset="+ Constants.ENCODING;
private static final String _403_JSON = "{\"code\": \"403\", \"msg\": \"Access Forbidden, Unauthorized!\"}"; private static final String _403_JSON = "{\"code\": \"403\", \"msg\": \"Access Forbidden, Unauthorized!\"}";
private static final String _403_HTML = "<html><body><div style='text-align:center'><h1 style='margin-top: 10px;'>Access Forbidden, Unauthorized!</h1></div></body></html>"; private static final String _403_HTML = "<html><body><div style='text-align:center'><h1 style='margin-top: 10px;'>Access Forbidden, Unauthorized!</h1></div></body></html>";
private static final String DSPPTH = "/data/dsp/"; private static final String DSPPTH = "/data/dsp/";
...@@ -77,7 +77,7 @@ public class ResourceAccessFilter implements Filter { ...@@ -77,7 +77,7 @@ public class ResourceAccessFilter implements Filter {
File file = new File(sb.toString()); File file = new File(sb.toString());
if (file.exists()) { if (file.exists()) {
response.setContentType(_JSON_CONTENT); response.setContentType(_JSON_CONTENT);
response.getWriter().print(FileUtils.readFileToString(file, StandardCharsets.UTF_8)); response.getWriter().print(FileUtils.readFileToString(file, Constants.ENCODING));
return; return;
} else { } else {
log.warn("Dsp Is Not Exists"); log.warn("Dsp Is Not Exists");
......
...@@ -36,7 +36,7 @@ public class OpenTransInterceptor implements HandlerInterceptor { ...@@ -36,7 +36,7 @@ public class OpenTransInterceptor implements HandlerInterceptor {
// 拦截每个请求 // 拦截每个请求
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
response.setCharacterEncoding("utf-8"); response.setCharacterEncoding(Constants.ENCODING);
NoUiRequest noUiRequest = new NoUiRequest(request, "", null); NoUiRequest noUiRequest = new NoUiRequest(request, "", null);
String token = noUiRequest.getToken(); String token = noUiRequest.getToken();
String userId = noUiRequest.getUserId(); String userId = noUiRequest.getUserId();
...@@ -79,7 +79,7 @@ public class OpenTransInterceptor implements HandlerInterceptor { ...@@ -79,7 +79,7 @@ public class OpenTransInterceptor implements HandlerInterceptor {
// 请求不通过,返回错误信息给客户端 // 请求不通过,返回错误信息给客户端
private void responseMessage(HttpServletResponse response, PrintWriter out, Result result) { private void responseMessage(HttpServletResponse response, PrintWriter out, Result result) {
response.setContentType("application/json; charset=utf-8"); response.setContentType("application/json; charset="+Constants.ENCODING);
String json = new Gson().toJson(result); String json = new Gson().toJson(result);
out.print(json); out.print(json);
out.flush(); out.flush();
......
...@@ -28,7 +28,7 @@ public class TokenInterceptor implements HandlerInterceptor { ...@@ -28,7 +28,7 @@ public class TokenInterceptor implements HandlerInterceptor {
// 拦截每个请求 // 拦截每个请求
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
response.setCharacterEncoding("utf-8"); response.setCharacterEncoding(Constants.ENCODING);
NoUiRequest noUiRequest = new NoUiRequest(request, "", null); NoUiRequest noUiRequest = new NoUiRequest(request, "", null);
String token = noUiRequest.getToken(); String token = noUiRequest.getToken();
String userId = noUiRequest.getUserId(); String userId = noUiRequest.getUserId();
...@@ -96,7 +96,7 @@ public class TokenInterceptor implements HandlerInterceptor { ...@@ -96,7 +96,7 @@ public class TokenInterceptor implements HandlerInterceptor {
// 请求不通过,返回错误信息给客户端 // 请求不通过,返回错误信息给客户端
private void responseMessage(HttpServletResponse response, PrintWriter out, Result result) { private void responseMessage(HttpServletResponse response, PrintWriter out, Result result) {
response.setContentType("application/json; charset=utf-8"); response.setContentType("application/json; charset="+Constants.ENCODING);
String json = new Gson().toJson(result); String json = new Gson().toJson(result);
out.print(json); out.print(json);
out.flush(); out.flush();
......
package org.sss.presentation.noui.util; package org.sss.presentation.noui.util;
import com.auth0.jwt.internal.org.apache.commons.codec.binary.Hex; import com.auth0.jwt.internal.org.apache.commons.codec.binary.Hex;
import log.Log; import log.Log;
import log.LogFactory; import log.LogFactory;
import sun.misc.BASE64Decoder; import org.sss.presentation.noui.common.Constants;
import sun.misc.BASE64Decoder;
import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec; import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec; import javax.crypto.spec.IvParameterSpec;
import java.nio.charset.StandardCharsets; import javax.crypto.spec.SecretKeySpec;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
public class AESUtil { public class AESUtil {
private static final Log log = LogFactory.getLog(NoUiUtils.class); private static final Log log = LogFactory.getLog(NoUiUtils.class);
private final static String password = "1qaz@Wsx#eDC";//目前使用 private final static String password = "1qaz@Wsx#eDC";//目前使用
private final static String IV = "#EdcxSW@1qaz3rfv";//目前使用 private final static String IV = "#EdcxSW@1qaz3rfv";//目前使用
private final static String patten = "^[0-9]+$"; private final static String patten = "^[0-9]+$";
private static final String KEY_ALGORITHM = "AES"; private static final String KEY_ALGORITHM = "AES";
private static final String DEFAULT_CIPHER_ALGORITHM = "AES/CBC/PKCS5Padding";//默认的加密算法 private static final String DEFAULT_CIPHER_ALGORITHM = "AES/CBC/PKCS5Padding";//默认的加密算法
public static String decryptAES(String content, String code) throws Exception { public static String decryptAES(String content, String code) throws Exception {
//int len=content.length()-1; //int len=content.length()-1;
SecretKeySpec skeySpec = new SecretKeySpec(getKey(code).getBytes(StandardCharsets.UTF_8), KEY_ALGORITHM); SecretKeySpec skeySpec = new SecretKeySpec(getKey(code).getBytes(Constants.ENCODING), KEY_ALGORITHM);
Cipher cipher = Cipher.getInstance(DEFAULT_CIPHER_ALGORITHM); Cipher cipher = Cipher.getInstance(DEFAULT_CIPHER_ALGORITHM);
IvParameterSpec iv = new IvParameterSpec(IV.getBytes()); IvParameterSpec iv = new IvParameterSpec(IV.getBytes());
cipher.init(Cipher.DECRYPT_MODE, skeySpec, iv); cipher.init(Cipher.DECRYPT_MODE, skeySpec, iv);
/*if(content.substring(len,len+1).matches("^[0-9]+$")){ /*if(content.substring(len,len+1).matches("^[0-9]+$")){
int cnt=Integer.parseInt(content.substring(len,len+1)); int cnt=Integer.parseInt(content.substring(len,len+1));
content=content.substring(0,len); content=content.substring(0,len);
for(int i=0;i<cnt;i++){ for(int i=0;i<cnt;i++){
content+="="; content+="=";
} }
}*/ }*/
byte[] encrypted1 = new BASE64Decoder().decodeBuffer(content);// 先用bAES64解密 byte[] encrypted1 = new BASE64Decoder().decodeBuffer(content);// 先用bAES64解密
return new String(cipher.doFinal(encrypted1), StandardCharsets.UTF_8); return new String(cipher.doFinal(encrypted1), Constants.ENCODING);
} }
public static String getKey(String code) { public static String getKey(String code) {
String key = password; String key = password;
for (int i = 0; i < code.length(); i++) { for (int i = 0; i < code.length(); i++) {
String subStr = code.substring(i, i + 1); String subStr = code.substring(i, i + 1);
if (subStr.matches(patten)) { if (subStr.matches(patten)) {
key = subStr + key; key = subStr + key;
} else { } else {
key = key + subStr; key = key + subStr;
} }
} }
return key; return key;
} }
/** /**
* @param content 待加签串 * @param content 待加签串
* @param password 动态密码 * @param password 动态密码
* @param iv 动态向量iv * @param iv 动态向量iv
* @return aes加密后的16进制字符串 * @return aes加密后的16进制字符串
*/ */
public static String encrypt(String content, String password, String iv) { public static String encrypt(String content, String password, String iv) {
if (unsatisfied(content, password, iv)) { if (unsatisfied(content, password, iv)) {
return null; return null;
} }
try { try {
Cipher cipher = Cipher.getInstance(DEFAULT_CIPHER_ALGORITHM); Cipher cipher = Cipher.getInstance(DEFAULT_CIPHER_ALGORITHM);
SecretKeySpec keySpec = new SecretKeySpec(password.getBytes(StandardCharsets.UTF_8), KEY_ALGORITHM); SecretKeySpec keySpec = new SecretKeySpec(password.getBytes(Constants.ENCODING), KEY_ALGORITHM);
IvParameterSpec ivParameterSpec = new IvParameterSpec(iv.getBytes(StandardCharsets.UTF_8)); IvParameterSpec ivParameterSpec = new IvParameterSpec(iv.getBytes(Constants.ENCODING));
cipher.init(Cipher.ENCRYPT_MODE, keySpec, ivParameterSpec); cipher.init(Cipher.ENCRYPT_MODE, keySpec, ivParameterSpec);
byte[] byteContent = content.getBytes(StandardCharsets.UTF_8); byte[] byteContent = content.getBytes(Constants.ENCODING);
byte[] result = cipher.doFinal(byteContent); byte[] result = cipher.doFinal(byteContent);
return Hex.encodeHexString(result); return Hex.encodeHexString(result);
// return Base64.getEncoder().encodeToString(result); // return Base64.getEncoder().encodeToString(result);
} catch (Exception ex) { } catch (Exception ex) {
log.warn("对数据进行aes加密异常:" + ex.getMessage(), ex); log.warn("对数据进行aes加密异常:" + ex.getMessage(), ex);
} }
return null; return null;
} }
/** /**
* @param content 待解签的16进制字符串 * @param content 待解签的16进制字符串
* @param password 动态密码 * @param password 动态密码
* @param iv 动态向量iv * @param iv 动态向量iv
* @return aes解密后的原始串 * @return aes解密后的原始串
*/ */
public static String decrypt(String content, String password, String iv) { public static String decrypt(String content, String password, String iv) {
if (unsatisfied(content, password, iv)) { if (unsatisfied(content, password, iv)) {
return null; return null;
} }
try { try {
Cipher cipher = Cipher.getInstance(DEFAULT_CIPHER_ALGORITHM); Cipher cipher = Cipher.getInstance(DEFAULT_CIPHER_ALGORITHM);
SecretKeySpec keySpec = new SecretKeySpec(password.getBytes(StandardCharsets.UTF_8), KEY_ALGORITHM); SecretKeySpec keySpec = new SecretKeySpec(password.getBytes(Constants.ENCODING), KEY_ALGORITHM);
IvParameterSpec ivParameterSpec = new IvParameterSpec(iv.getBytes(StandardCharsets.UTF_8)); IvParameterSpec ivParameterSpec = new IvParameterSpec(iv.getBytes(Constants.ENCODING));
cipher.init(Cipher.DECRYPT_MODE, keySpec, ivParameterSpec); cipher.init(Cipher.DECRYPT_MODE, keySpec, ivParameterSpec);
// byte[] result = cipher.doFinal(Base64.getDecoder().decode(content)); // byte[] result = cipher.doFinal(Base64.getDecoder().decode(content));
byte[] result = cipher.doFinal(Hex.decodeHex(content.toCharArray())); byte[] result = cipher.doFinal(Hex.decodeHex(content.toCharArray()));
return new String(result, StandardCharsets.UTF_8); return new String(result, Constants.ENCODING);
} catch (Exception ex) { } catch (Exception ex) {
log.warn("对数据进行aes加密异常:" + ex.getMessage(), ex); log.warn("对数据进行aes加密异常:" + ex.getMessage(), ex);
} }
return null; return null;
} }
private static boolean unsatisfied(String content, String password, String iv) { private static boolean unsatisfied(String content, String password, String iv) {
if (StringUtil.isEmpty(content)) { if (StringUtil.isEmpty(content)) {
return true; return true;
} }
if (StringUtil.isEmpty(password) || password.length() != 16) { if (StringUtil.isEmpty(password) || password.length() != 16) {
return true; return true;
} }
if (StringUtil.isEmpty(iv) || iv.length() != 16) { if (StringUtil.isEmpty(iv) || iv.length() != 16) {
return true; return true;
} }
return false; return false;
} }
public static void main(String[] args) { public static void main(String[] args) {
try { try {
//测登陆密码解密 //测登陆密码解密
// System.out.println(decryptAES("L2eRe4wOLeyqvUIayLs1NA==","7d9t")); // System.out.println(decryptAES("L2eRe4wOLeyqvUIayLs1NA==","7d9t"));
//测数据安全性加解密和相关性能 //测数据安全性加解密和相关性能
/*long beg=System.currentTimeMillis(); /*long beg=System.currentTimeMillis();
for(int i=0;i<1000;i++){ for(int i=0;i<1000;i++){
String enc=encrypt("hello 中国,13232",password+"0000",IV); String enc=encrypt("hello 中国,13232",password+"0000",IV);
System.out.println("encrypt:"+enc); System.out.println("encrypt:"+enc);
String dec=decrypt(enc,password+"0000",IV); String dec=decrypt(enc,password+"0000",IV);
System.out.println("decrypt:"+dec); System.out.println("decrypt:"+dec);
} }
long end=System.currentTimeMillis(); long end=System.currentTimeMillis();
System.out.println(end-beg);*/ System.out.println(end-beg);*/
//数据安全加解密逻辑验证 //数据安全加解密逻辑验证
String[] str=new String[]{"hello中国","13232"}; String[] str=new String[]{"hello中国","13232"};
List<String> lst = Arrays.asList(str); List<String> lst = Arrays.asList(str);
String md5=String.join("`wD4+-@hh", lst); String md5=String.join("`wD4+-@hh", lst);
System.out.println("md5前=="+md5); System.out.println("md5前=="+md5);
md5=StringUtil.encryptMD5(md5); md5=StringUtil.encryptMD5(md5);
System.out.println("md5后=="+md5); System.out.println("md5后=="+md5);
String enc=encrypt(md5,password+"0000",IV); String enc=encrypt(md5,password+"0000",IV);
System.out.println("encrypt:"+enc); System.out.println("encrypt:"+enc);
String dec=decrypt(enc,password+"0000",IV); String dec=decrypt(enc,password+"0000",IV);
System.out.println("decrypt:"+dec); System.out.println("decrypt:"+dec);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
} }
...@@ -8,8 +8,8 @@ import org.springframework.http.client.SimpleClientHttpRequestFactory; ...@@ -8,8 +8,8 @@ import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.http.converter.StringHttpMessageConverter; import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.web.client.RestClientException; import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
import org.sss.presentation.noui.common.Constants;
import java.nio.charset.StandardCharsets;
import java.util.Map; import java.util.Map;
public class HttpClientUtil { public class HttpClientUtil {
...@@ -20,7 +20,7 @@ public class HttpClientUtil { ...@@ -20,7 +20,7 @@ public class HttpClientUtil {
factory.setConnectTimeout(15000); factory.setConnectTimeout(15000);
factory.setReadTimeout(30000); factory.setReadTimeout(30000);
restTemplate = new RestTemplate(factory); restTemplate = new RestTemplate(factory);
restTemplate.getMessageConverters().set(1, new StringHttpMessageConverter(StandardCharsets.UTF_8)); restTemplate.getMessageConverters().set(1, new StringHttpMessageConverter(Constants.ENCODING_CHARSET));
} }
/** /**
......
...@@ -40,7 +40,6 @@ public class NoUiPresentationUtil { ...@@ -40,7 +40,6 @@ public class NoUiPresentationUtil {
IBaseObject baseObject = null; IBaseObject baseObject = null;
try { try {
System.out.println("url=" + url);
baseObject = context.getSession().getBaseObject(context.getRoot(), url); baseObject = context.getSession().getBaseObject(context.getRoot(), url);
if (null == baseObject) { if (null == baseObject) {
throw new NoUiException("not found url :" + url + " ,alias name is:" + aliasKey); throw new NoUiException("not found url :" + url + " ,alias name is:" + aliasKey);
...@@ -84,7 +83,6 @@ public class NoUiPresentationUtil { ...@@ -84,7 +83,6 @@ public class NoUiPresentationUtil {
IBaseObject baseObject = null; IBaseObject baseObject = null;
try { try {
System.out.println("url=" + url);
baseObject = context.getSession().getBaseObject(context.getRoot(), url); baseObject = context.getSession().getBaseObject(context.getRoot(), url);
if (null == baseObject) { if (null == baseObject) {
throw new NoUiException("not found url :" + url + " ,alias name is:" + aliasKey); throw new NoUiException("not found url :" + url + " ,alias name is:" + aliasKey);
......
package org.sss.presentation.noui.util; package org.sss.presentation.noui.util;
import java.io.File; import org.apache.commons.io.IOUtils;
import java.io.FileInputStream; import org.sss.presentation.noui.common.Constants;
import java.io.FileOutputStream;
import java.io.IOException; import java.io.*;
import java.io.InputStream; import java.util.HashMap;
import java.io.InputStreamReader; import java.util.Map;
import java.io.OutputStream; import java.util.Properties;
import java.util.HashMap;
import java.util.Map; /**
import java.util.Properties; * Properties文件工具
*
import org.apache.commons.io.IOUtils; * @author xiaoyuanzhen
*
/** */
* Properties文件工具 public class PropertyUtil {
* /**
* @author xiaoyuanzhen * 从properties文件中获取指定属性名对应的值
* *
*/ * @param propertyFile
public class PropertyUtil { * @param propertyName
/** * @return
* 从properties文件中获取指定属性名对应的值 */
* private static Map<String, Properties> map = new HashMap<String, Properties>();
* @param propertyFile
* @param propertyName public static String getProperty(String propertyFile, String propertyName) {
* @return String propertyValue = "";
*/ InputStream is = null;
private static Map<String, Properties> map = new HashMap<String, Properties>(); try {
Properties propertie = new Properties();
public static String getProperty(String propertyFile, String propertyName) { if (!map.containsKey(propertyFile)) {
String propertyValue = ""; is = Thread.currentThread().getContextClassLoader().getResourceAsStream(propertyFile);
InputStream is = null; propertie.load(is);
try { map.put(propertyFile, propertie);
Properties propertie = new Properties(); }
if (!map.containsKey(propertyFile)) { propertyValue = map.get(propertyFile).getProperty(propertyName);
is = Thread.currentThread().getContextClassLoader().getResourceAsStream(propertyFile); } catch (Exception e) {
propertie.load(is); e.printStackTrace();
map.put(propertyFile, propertie); propertyValue = "";
} } finally {
propertyValue = map.get(propertyFile).getProperty(propertyName); try {
} catch (Exception e) { IOUtils.closeQuietly(is);
e.printStackTrace(); } catch (Exception e) {
propertyValue = ""; e.printStackTrace();
} finally { }
try { }
IOUtils.closeQuietly(is);
} catch (Exception e) { return propertyValue;
e.printStackTrace(); }
}
} /**
* 设置properties文件的某个属性值
return propertyValue; *
} * @param propertyFile
* @param propertyName
/** * @param propertyValue
* 设置properties文件的某个属性值 * @return
* */
* @param propertyFile public synchronized static boolean setProperty(String propertyFile, String propertyName, String propertyValue) {
* @param propertyName boolean sav = false;
* @param propertyValue InputStream is = null;
* @return OutputStream os = null;
*/ try {
public synchronized static boolean setProperty(String propertyFile, String propertyName, String propertyValue) { Properties propertie = new Properties();
boolean sav = false; is = Thread.currentThread().getContextClassLoader().getResourceAsStream(propertyFile);
InputStream is = null; propertie.load(is);
OutputStream os = null; propertie.setProperty(propertyName, propertyValue);
try { String path = Thread.currentThread().getContextClassLoader().getResource(propertyFile).getPath();
Properties propertie = new Properties(); os = new FileOutputStream(new File(path));
is = Thread.currentThread().getContextClassLoader().getResourceAsStream(propertyFile); propertie.store(os, "");
propertie.load(is); os.flush();
propertie.setProperty(propertyName, propertyValue); sav = true;
String path = Thread.currentThread().getContextClassLoader().getResource(propertyFile).getPath(); } catch (Exception e) {
os = new FileOutputStream(new File(path)); e.printStackTrace();
propertie.store(os, ""); sav = false;
os.flush(); } finally {
sav = true; try {
} catch (Exception e) { is.close();
e.printStackTrace(); os.close();
sav = false; } catch (Exception e) {
} finally { e.printStackTrace();
try { }
is.close(); }
os.close(); return sav;
} catch (Exception e) { }
e.printStackTrace();
} public synchronized static boolean setPropertyValue(String propertyFile, String propertyName, String propertyValue) {
} boolean sav = false;
return sav; OutputStream os = null;
} InputStream is = null;
try {
public synchronized static boolean setPropertyValue(String propertyFile, String propertyName, String propertyValue) { Properties propertie = new Properties();
boolean sav = false; is = new FileInputStream(new File(propertyFile));
OutputStream os = null; propertie.load(is);
InputStream is = null; propertie.setProperty(propertyName, propertyValue);
try { os = new FileOutputStream(new File(propertyFile));
Properties propertie = new Properties(); propertie.store(os, "");
is = new FileInputStream(new File(propertyFile)); os.flush();
propertie.load(is); sav = true;
propertie.setProperty(propertyName, propertyValue); } catch (Exception e) {
os = new FileOutputStream(new File(propertyFile)); e.printStackTrace();
propertie.store(os, ""); propertyValue = "";
os.flush(); } finally {
sav = true; try {
} catch (Exception e) { is.close();
e.printStackTrace(); } catch (Exception e) {
propertyValue = ""; e.printStackTrace();
} finally { }
try { }
is.close(); return sav;
} catch (Exception e) { }
e.printStackTrace();
} private static Properties load(File f, String encoding) throws IOException {
} Properties propertie = new Properties();
return sav; InputStreamReader is = new InputStreamReader(new FileInputStream(f), encoding);
} propertie.load(is);
is.close();
private static Properties load(File f, String encoding) throws IOException { return propertie;
Properties propertie = new Properties(); }
InputStreamReader is = new InputStreamReader(new FileInputStream(f), encoding);
propertie.load(is); private static Properties load(File f) throws IOException {
is.close(); return load(f, Constants.ENCODING);
return propertie; }
}
public static Properties load(String name) throws IOException {
private static Properties load(File f) throws IOException { InputStream is = null;
return load(f, "GBK"); Properties propertie = new Properties();
} try {
if (!map.containsKey(name)) {
public static Properties load(String name) throws IOException { is = Thread.currentThread().getContextClassLoader().getResourceAsStream(name);
InputStream is = null; propertie.load(is);
Properties propertie = new Properties(); map.put(name, propertie);
try { } else {
if (!map.containsKey(name)) { return map.get(name);
is = Thread.currentThread().getContextClassLoader().getResourceAsStream(name); }
propertie.load(is); } catch (Exception e) {
map.put(name, propertie); e.printStackTrace();
} else { } finally {
return map.get(name); try {
} IOUtils.closeQuietly(is);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} finally { }
try { }
IOUtils.closeQuietly(is); return propertie;
} catch (Exception e) { }
e.printStackTrace();
} public static Properties getProperties(String propertyFile) throws IOException {
} return getProperties(propertyFile, Constants.ENCODING);
return propertie; }
}
public static Properties getProperties(String propertyFile, String encoding) throws IOException {
public static Properties getProperties(String propertyFile) throws IOException { return load(new File(propertyFile), encoding);
return getProperties(propertyFile, "GBK"); }
}
public static String getPropertyValue(String propertyFile, String propertyName) {
public static Properties getProperties(String propertyFile, String encoding) throws IOException { String propertyValue = "";
return load(new File(propertyFile), encoding); // InputStream is = null;
} try {
Properties propertie = load(new File(propertyFile));
public static String getPropertyValue(String propertyFile, String propertyName) { propertyValue = propertie.getProperty(propertyName);
String propertyValue = ""; } catch (Exception e) {
// InputStream is = null; e.printStackTrace();
try { propertyValue = "";
Properties propertie = load(new File(propertyFile)); }
propertyValue = propertie.getProperty(propertyName); return propertyValue;
} catch (Exception e) { }
e.printStackTrace(); }
propertyValue = "";
}
return propertyValue;
}
}
package org.sss.presentation.noui.util; package org.sss.presentation.noui.util;
import cfca.sadk.algorithm.sm2.SM3Digest; import cfca.sadk.algorithm.sm2.SM3Digest;
import org.sss.presentation.noui.common.Constants;
import org.sss.presentation.noui.jwt.RedisLoginInfo; import org.sss.presentation.noui.jwt.RedisLoginInfo;
import java.nio.charset.StandardCharsets;
public class ResourceAcccessEncryptUtil { public class ResourceAcccessEncryptUtil {
private static final String KEY = "session.##.WEB"; private static final String KEY = "session.##.WEB";
private static final String SALT = "1314520@Brilliance;"; private static final String SALT = "1314520@Brilliance;";
...@@ -39,7 +38,7 @@ public class ResourceAcccessEncryptUtil { ...@@ -39,7 +38,7 @@ public class ResourceAcccessEncryptUtil {
} }
private static String sm3(String msg) { private static String sm3(String msg) {
byte[] z = msg.getBytes(StandardCharsets.UTF_8); byte[] z = msg.getBytes(Constants.ENCODING_CHARSET);
SM3Digest sm3 = new SM3Digest(); SM3Digest sm3 = new SM3Digest();
sm3.update(z, 0, z.length); sm3.update(z, 0, z.length);
byte[] hash = new byte[32]; byte[] hash = new byte[32];
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
<service class="org.sss.presentation.noui.util.NoUiUtils" <service class="org.sss.presentation.noui.util.NoUiUtils"
initMethodName="init" deinitMethodName="deinit"> initMethodName="init" deinitMethodName="deinit">
<property name="datapath" value="D:/"/> <property name="datapath" value="D:/"/>
<property name="fieldencode" value="true" class="boolean"/> <property name="fieldencode" value="false" class="boolean"/>
<property name="connectKeeped" value="true" class="boolean"/> <property name="connectKeeped" value="true" class="boolean"/>
<property name="debugMode" value="false" class="boolean"/> <property name="debugMode" value="false" class="boolean"/>
<!-- WAR包本身的目录为变量$ROOT,WAR/WEB-INF/classes目录为变量$HOME --> <!-- WAR包本身的目录为变量$ROOT,WAR/WEB-INF/classes目录为变量$HOME -->
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment