Commit f5f1108e by WeiCong

调通e结算第一版

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