Commit a5f78102 by WeiCong

1.整理用户信息

2.完善打包插件
parent f5f1108e
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
<properties> <properties>
<project.build.sourceEncoding>GBK</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>
<maven-jar-plugin_version>3.2.0</maven-jar-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>
<jul-to-slf4j_version>1.7.30</jul-to-slf4j_version> <jul-to-slf4j_version>1.7.30</jul-to-slf4j_version>
...@@ -349,6 +350,30 @@ ...@@ -349,6 +350,30 @@
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>${maven-jar-plugin_version}</version>
<configuration>
<includes>
<include>**/*.class</include>
<include>**/META-INF/*</include>
</includes>
<archive>
<manifest>
<!-- 配置加入依赖包 -->
<addClasspath>true</addClasspath>
<useUniqueVersions>false</useUniqueVersions>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
<!-- 启动类,子类配置 -->
<!-- <mainClass>com.brilliance.esb.main.Starter</mainClass>-->
</manifest>
<!-- 生成的jar中,不要包含pom.xml和pom.properties这两个文件 -->
<addMavenDescriptor>false</addMavenDescriptor>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId> <artifactId>maven-dependency-plugin</artifactId>
<version>${maven-dependency-plugin.version}</version> <version>${maven-dependency-plugin.version}</version>
<!-- 复制依赖 --> <!-- 复制依赖 -->
......
...@@ -20,7 +20,6 @@ public class Constants { ...@@ -20,7 +20,6 @@ public class Constants {
public final static String SESSION = "session"; public final static String SESSION = "session";
public final static String BACKGROUND_FLAG = "BackGroundRequest-";
public final static String APP_FLAG = "AppRequest-"; public final static String APP_FLAG = "AppRequest-";
public static final String PAGINATION = "pagination"; public static final String PAGINATION = "pagination";
public static final String PAGINATION_INDEX = "index"; public static final String PAGINATION_INDEX = "index";
......
package org.sss.presentation.noui.context; package org.sss.presentation.noui.context;
import log.Log; import log.Log;
import log.LogFactory; import log.LogFactory;
import org.sss.common.impl.AbstractContext; import org.sss.common.impl.AbstractContext;
import org.sss.presentation.noui.jwt.RedisLoginInfo; import org.sss.presentation.noui.jwt.LoginInfo;
import org.sss.presentation.noui.util.NoUiUtils; import org.sss.presentation.noui.util.NoUiUtils;
public class NoUiContext extends AbstractContext { public class NoUiContext extends AbstractContext {
private static final Log log = LogFactory.getLog(NoUiContext.class); private static final Log log = LogFactory.getLog(NoUiContext.class);
@Override @Override
public void logout() { public void logout() {
} }
@Override @Override
public void logout(DataType arg0, String arg1) { public void logout(DataType arg0, String arg1) {
// if(redisLoginInfo != null){ log.info("logout start:datatype["+arg0+"],userid["+arg1+"]");
// NoUiUtils.logout(redisLoginInfo.getUserId(),redisLoginInfo.getTerminalType()); if(arg0.equals(DataType.USER_NAME)){
// } NoUiUtils.logout(arg1,"*");
log.info("logout start:datatype["+arg0+"],userid["+arg1+"]"); }
if(arg0.equals(DataType.USER_NAME)){ }
NoUiUtils.logout(arg1,"*");
} @Override
} public String getServerName() {
// TODO Auto-generated method stub
@Override return null;
public String getServerName() { }
// TODO Auto-generated method stub
return null; private LoginInfo loginInfo;
}
public LoginInfo getLoginInfo()
private RedisLoginInfo redisLoginInfo; {
return this.loginInfo;
public RedisLoginInfo getRedisLoginInfo() }
{ public void setLoginInfo(LoginInfo loginInfo)
return this.redisLoginInfo; {
} this.loginInfo = loginInfo;
public void setRedisLoginInfo(RedisLoginInfo redisLoginInfo) }
{ }
this.redisLoginInfo = redisLoginInfo;
}
}
...@@ -81,7 +81,7 @@ public class NoUiPresentation extends AbstractNullPresentation { ...@@ -81,7 +81,7 @@ public class NoUiPresentation extends AbstractNullPresentation {
@Override @Override
public Object readFromSession(String name) { public Object readFromSession(String name) {
return ((NoUiContext) this.ctx).getRedisLoginInfo().getContextMap().get(name); return ((NoUiContext) this.ctx).getLoginInfo().getContextMap().get(name);
} }
@Override @Override
...@@ -96,7 +96,7 @@ public class NoUiPresentation extends AbstractNullPresentation { ...@@ -96,7 +96,7 @@ public class NoUiPresentation extends AbstractNullPresentation {
@Override @Override
public void writeToSession(String name, Object value) { public void writeToSession(String name, Object value) {
((NoUiContext) this.ctx).getRedisLoginInfo().getContextMap().put(name, value); ((NoUiContext) this.ctx).getLoginInfo().getContextMap().put(name, value);
} }
public String getMessageCode() { public String getMessageCode() {
......
...@@ -22,8 +22,11 @@ import org.sss.presentation.noui.context.NoUiContext; ...@@ -22,8 +22,11 @@ import org.sss.presentation.noui.context.NoUiContext;
import org.sss.presentation.noui.context.NoUiContextManager; import org.sss.presentation.noui.context.NoUiContextManager;
import org.sss.presentation.noui.context.NoUiPresentation; import org.sss.presentation.noui.context.NoUiPresentation;
import org.sss.presentation.noui.context.TxInfo; import org.sss.presentation.noui.context.TxInfo;
import org.sss.presentation.noui.jwt.RedisLoginInfo; import org.sss.presentation.noui.jwt.LoginInfo;
import org.sss.presentation.noui.util.*; import org.sss.presentation.noui.util.DataSecurityUtil;
import org.sss.presentation.noui.util.EhcacheUtils;
import org.sss.presentation.noui.util.NoUiPresentationUtil;
import org.sss.presentation.noui.util.StringUtil;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
...@@ -70,14 +73,15 @@ public abstract class AbstractCommonController { ...@@ -70,14 +73,15 @@ public abstract class AbstractCommonController {
context.getSession().storeData(key, paramsMap.get(key)); context.getSession().storeData(key, paramsMap.get(key));
} }
// 设置old sysmod // 设置old sysmod
RedisLoginInfo redisLoginInfo = null; LoginInfo loginInfo = null;
if (!StringUtils.isEmpty(noUiRequest.getUserId())){ if (!StringUtils.isEmpty(noUiRequest.getUserId())){
//开放模式下 loginInfo = (LoginInfo) EhcacheUtils.get(StringUtil.userUniqueId(noUiRequest));
redisLoginInfo = (RedisLoginInfo) EhcacheUtils.get(StringUtil.userUniqueId(noUiRequest)); if (loginInfo != null) {
} if(loginInfo.getSysmod()!=null){
if (redisLoginInfo != null) { NoUiPresentationUtil.setSysmod(context, (byte[]) loginInfo.getSysmod());
NoUiPresentationUtil.setSysmod(context, (byte[]) redisLoginInfo.getSysmod()); }
context.setRedisLoginInfo(redisLoginInfo); context.setLoginInfo(loginInfo);
}
} }
// 交易跳转 // 交易跳转
...@@ -161,12 +165,12 @@ public abstract class AbstractCommonController { ...@@ -161,12 +165,12 @@ public abstract class AbstractCommonController {
IOUtils.write(data, response.getOutputStream()); IOUtils.write(data, response.getOutputStream());
} }
// 保存新的RedisLoginInfo // 保存新的LoginInfo
if (redisLoginInfo != null) //当为开放模式下,redisLoginInfo 为空 if (loginInfo != null) //当为开放模式下
{ {
byte[] sysmodBytes = NoUiPresentationUtil.sysmodToBytes(context); byte[] sysmodBytes = NoUiPresentationUtil.sysmodToBytes(context);
redisLoginInfo.setSysmod(sysmodBytes); loginInfo.setSysmod(sysmodBytes);
EhcacheUtils.set(StringUtil.userUniqueId(noUiRequest), redisLoginInfo); EhcacheUtils.set(StringUtil.userUniqueId(noUiRequest), loginInfo);
} }
Map<String, Object> paginationData = new HashMap<>(); Map<String, Object> paginationData = new HashMap<>();
Map<String, Object> afterReturnData = handleReturnData(eventType, context, noUiRequest, alias,paginationData); Map<String, Object> afterReturnData = handleReturnData(eventType, context, noUiRequest, alias,paginationData);
......
...@@ -13,7 +13,7 @@ import org.springframework.web.bind.annotation.RequestMapping; ...@@ -13,7 +13,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
import org.sss.presentation.noui.api.response.NoUiVersion; import org.sss.presentation.noui.api.response.NoUiVersion;
import org.sss.presentation.noui.common.Constants; import org.sss.presentation.noui.common.Constants;
import org.sss.presentation.noui.jwt.RedisLoginInfo; import org.sss.presentation.noui.jwt.LoginInfo;
import org.sss.presentation.noui.util.EhcacheUtils; import org.sss.presentation.noui.util.EhcacheUtils;
import org.sss.presentation.noui.util.StringUtil; import org.sss.presentation.noui.util.StringUtil;
...@@ -53,7 +53,7 @@ public class FileBrowserController { ...@@ -53,7 +53,7 @@ public class FileBrowserController {
//redis获取token //redis获取token
Set<String> keys = EhcacheUtils.keys(Constants.SESSION + "." + usrName); Set<String> keys = EhcacheUtils.keys(Constants.SESSION + "." + usrName);
if (!keys.isEmpty()) { if (!keys.isEmpty()) {
token = ((RedisLoginInfo) keys.toArray()[0]).getToken(); token = ((LoginInfo) keys.toArray()[0]).getToken();
} else } else
return false; return false;
StringBuilder sb = new StringBuilder(usrName); StringBuilder sb = new StringBuilder(usrName);
......
...@@ -23,7 +23,7 @@ import org.sss.presentation.noui.context.NoUiContextManager; ...@@ -23,7 +23,7 @@ import org.sss.presentation.noui.context.NoUiContextManager;
import org.sss.presentation.noui.context.TxInfo; import org.sss.presentation.noui.context.TxInfo;
import org.sss.presentation.noui.jwt.JWT; import org.sss.presentation.noui.jwt.JWT;
import org.sss.presentation.noui.jwt.JwtLogin; import org.sss.presentation.noui.jwt.JwtLogin;
import org.sss.presentation.noui.jwt.RedisLoginInfo; import org.sss.presentation.noui.jwt.LoginInfo;
import org.sss.presentation.noui.util.*; import org.sss.presentation.noui.util.*;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
...@@ -110,14 +110,14 @@ public class LoginController { ...@@ -110,14 +110,14 @@ public class LoginController {
// redis中存储用户相关信息 // redis中存储用户相关信息
IDatafield inridf = (IDatafield) context.getSession().getBaseObject(context.getRoot(), "sysmod\\usr\\inr"); IDatafield inridf = (IDatafield) context.getSession().getBaseObject(context.getRoot(), "sysmod\\usr\\inr");
RedisLoginInfo redisLoginInfo = new RedisLoginInfo(userId, token, NumericUtil.sessionTimeOut(), sysmodBytes, noUiRequest.getTerminalType()); LoginInfo loginInfo = new LoginInfo(userId, token, NumericUtil.sessionTimeOut(), sysmodBytes, noUiRequest.getTerminalType());
redisLoginInfo.setUserInr((String) inridf.getValue()); //设置当前用户主键 loginInfo.setUserInr((String) inridf.getValue()); //设置当前用户主键
request.getSession().setAttribute("token", token); request.getSession().setAttribute("token", token);
NoUiUtils.logout(userId, "*"); //清理可能存在的历史缓存 NoUiUtils.logout(userId, "*"); //清理可能存在的历史缓存
EhcacheUtils.set(StringUtil.userUniqueId(noUiRequest), redisLoginInfo); EhcacheUtils.set(StringUtil.userUniqueId(noUiRequest), loginInfo);
EhcacheUtils.set(StringUtil.getCacheSessionId(noUiRequest.getUserId()), request.getSession().getId()); EhcacheUtils.set(StringUtil.getCacheSessionId(noUiRequest.getUserId()), request.getSession().getId());
//解决初次登陆,超期限登陆 //解决初次登陆,超期限登陆
......
package org.sss.presentation.noui.jwt; package org.sss.presentation.noui.jwt;
import java.io.Serializable; import java.io.Serializable;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
public class RedisLoginInfo implements Serializable { public class LoginInfo implements Serializable {
/** /**
* *
*/ */
private static final long serialVersionUID = 8116817810829835862L; private static final long serialVersionUID = 8116817810829835862L;
private String userInr; private String userInr;
/** /**
* 用户id * 用户id
*/ */
private String userId; private String userId;
/** /**
* jwt生成的token信息 * jwt生成的token信息
*/ */
private String token; private String token;
/** /**
* 登录或刷新应用的时间 * 登录或刷新应用的时间
*/ */
private long expiredTime; private long expiredTime;
//终端类型 //终端类型
private String terminalType; private String terminalType;
private Object sysmod; private Object sysmod;
private Map<String,Object> contextMap = new HashMap<String,Object>(); private Map<String,Object> contextMap = new HashMap<String,Object>();
public Map<String, Object> getContextMap() { public Map<String, Object> getContextMap() {
return contextMap; return contextMap;
} }
public void setContextMap(Map<String, Object> contextMap) { public void setContextMap(Map<String, Object> contextMap) {
this.contextMap = contextMap; this.contextMap = contextMap;
} }
public RedisLoginInfo() { public LoginInfo() {
} }
public RedisLoginInfo(String userId, String token, long expiredTime, Object sysmod,String terminalType) { public LoginInfo(String userId, String token, long expiredTime, Object sysmod, String terminalType) {
this.userId = userId; this.userId = userId;
this.token = token; this.token = token;
this.expiredTime = expiredTime; this.expiredTime = expiredTime;
this.sysmod = sysmod; this.sysmod = sysmod;
this.terminalType = terminalType; this.terminalType = terminalType;
} }
public String getToken() { public String getToken() {
return token; return token;
} }
public void setToken(String token) { public void setToken(String token) {
this.token = token; this.token = token;
} }
public String getUserId() { public String getUserId() {
return userId; return userId;
} }
public long getExpiredTime() { public long getExpiredTime() {
return expiredTime; return expiredTime;
} }
public void setUserId(String userId) { public void setUserId(String userId) {
this.userId = userId; this.userId = userId;
} }
public void setExpiredTime(long expiredTime) { public void setExpiredTime(long expiredTime) {
this.expiredTime = expiredTime; this.expiredTime = expiredTime;
} }
public Object getSysmod() { public Object getSysmod() {
return sysmod; return sysmod;
} }
public void setSysmod(Object sysmod) { public void setSysmod(Object sysmod) {
this.sysmod = sysmod; this.sysmod = sysmod;
} }
public String getTerminalType() { public String getTerminalType() {
return terminalType; return terminalType;
} }
public void setTerminalType(String terminalType) { public void setTerminalType(String terminalType) {
this.terminalType = terminalType; this.terminalType = terminalType;
} }
public void setUserInr(String value) { public void setUserInr(String value) {
this.userInr = value; this.userInr = value;
} }
public String getUserInr() { public String getUserInr() {
return userInr; return userInr;
} }
} }
\ No newline at end of file
package org.sss.presentation.noui.jwt;
import com.google.gson.Gson;
import log.Log;
import log.LogFactory;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;
import org.sss.presentation.noui.api.request.NoUiRequest;
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 org.sss.presentation.noui.context.NoUiContextManager;
import org.sss.presentation.noui.util.EhcacheUtils;
import org.sss.presentation.noui.util.NumericUtil;
import org.sss.presentation.noui.util.StringUtil;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.PrintWriter;
public class OpenTransInterceptor implements HandlerInterceptor {
protected static final Log log = LogFactory.getLog(OpenTransInterceptor.class);
@Autowired
private NoUiVersion noUiVersion;
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception arg3) throws Exception {
}
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView model) throws Exception {
}
// 拦截每个请求
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
response.setCharacterEncoding(Constants.ENCODING);
NoUiRequest noUiRequest = new NoUiRequest(request, "", null);
String token = noUiRequest.getToken();
String userId = noUiRequest.getUserId();
String terminalType = noUiRequest.getTerminalType(); // APP WEB
RedisLoginInfo redisLoginInfo = null;
if (!StringUtils.isEmpty(noUiRequest.getUserId())) //开放模式下
redisLoginInfo = (RedisLoginInfo) EhcacheUtils.get(StringUtil.userUniqueId(noUiRequest));
//如果是已登录状态,要刷新超时时间
if (redisLoginInfo != null && System.currentTimeMillis() <= redisLoginInfo.getExpiredTime()) {
// 重新刷入登陆时间
RedisLoginInfo nweRedisLoginInfo = new RedisLoginInfo(userId, token, NumericUtil.sessionTimeOut(), redisLoginInfo.getSysmod(), noUiRequest.getTerminalType());
EhcacheUtils.set(Constants.SESSION + "." + userId + "." + terminalType, nweRedisLoginInfo);
EhcacheUtils.set(StringUtil.getCacheSessionId(userId),request.getSession().getId());
}
String url = request.getRequestURI();
String trnnam = null;
int idx1 = url.indexOf(NoUiContextManager.openSourcePrefix);
int begpos = idx1 + NoUiContextManager.openSourcePrefix.length() + 1;
int idx2 = url.indexOf("/", begpos);
if (idx2 > 0)
trnnam = url.substring(begpos, idx2);
if (trnnam == null) {
Result rt = new Result(ErrorCodes.UNKNOEW_TRANS, "未知的交易", null, noUiVersion.getVersion());
responseMessage(response, response.getWriter(), rt);
return false;
}
//交易必须是配置允许开放的交易
log.debug("开放访问交易名:" + trnnam);
if (!NoUiContextManager.openTransactions.contains(trnnam)) {
Result rt = new Result(ErrorCodes.FORBIDDEN_TRANS, "非法访问", null, noUiVersion.getVersion());
responseMessage(response, response.getWriter(), rt);
return false;
}
return true;
}
// 请求不通过,返回错误信息给客户端
private void responseMessage(HttpServletResponse response, PrintWriter out, Result result) {
response.setContentType("application/json; charset="+Constants.ENCODING);
String json = new Gson().toJson(result);
out.print(json);
out.flush();
out.close();
}
}
\ No newline at end of file
...@@ -47,10 +47,6 @@ public class TokenInterceptor implements HandlerInterceptor { ...@@ -47,10 +47,6 @@ public class TokenInterceptor implements HandlerInterceptor {
return false; return false;
} }
//如果为后台直接调用交易,则直接跳过token验证,无需redis缓存
if (token.startsWith(Constants.BACKGROUND_FLAG)) {
return true;
}
//服务调用 //服务调用
if (token.startsWith(Constants.APP_FLAG)) { if (token.startsWith(Constants.APP_FLAG)) {
return true; return true;
...@@ -64,39 +60,39 @@ public class TokenInterceptor implements HandlerInterceptor { ...@@ -64,39 +60,39 @@ public class TokenInterceptor implements HandlerInterceptor {
return false; return false;
} }
RedisLoginInfo redisLoginInfo = (RedisLoginInfo) EhcacheUtils.get(StringUtil.userUniqueId(noUiRequest)); LoginInfo loginInfo = (LoginInfo) EhcacheUtils.get(StringUtil.userUniqueId(noUiRequest));
if (redisLoginInfo == null) { if (loginInfo == null) {
Result rt = new Result(ErrorCodes.LOGIN_ERROR, "登陆异常", null, noUiVersion.getVersion()); Result rt = new Result(ErrorCodes.LOGIN_ERROR, "登陆异常", null, noUiVersion.getVersion());
responseMessage(response, response.getWriter(), rt); responseMessage(response, response.getWriter(), rt);
return false; return false;
} }
//验证token是否一致 //验证token是否一致
if (!token.equals(redisLoginInfo.getToken())) { if (!token.equals(loginInfo.getToken())) {
Result rt = new Result(ErrorCodes.LOGIN_TOKEN_CHECKERROR, "token失效,该用户被强迫下线", null, noUiVersion.getVersion()); Result rt = new Result(ErrorCodes.LOGIN_TOKEN_CHECKERROR, "token失效,该用户被强迫下线", null, noUiVersion.getVersion());
responseMessage(response, response.getWriter(), rt); responseMessage(response, response.getWriter(), rt);
return false; return false;
} }
// 验证登录时间 // 验证登录时间
if (System.currentTimeMillis() > redisLoginInfo.getExpiredTime()) { if (System.currentTimeMillis() > loginInfo.getExpiredTime()) {
Result rt = new Result(ErrorCodes.LOGIN_TIMEOUT, "会话超时,请重新登录。超时时间戳:" + redisLoginInfo.getExpiredTime() + Result rt = new Result(ErrorCodes.LOGIN_TIMEOUT, "会话超时,请重新登录。超时时间戳:" + loginInfo.getExpiredTime() +
",当前时间戳:" + System.currentTimeMillis(), null, noUiVersion.getVersion()); ",当前时间戳:" + System.currentTimeMillis(), null, noUiVersion.getVersion());
responseMessage(response, response.getWriter(), rt); responseMessage(response, response.getWriter(), rt);
return false; return false;
} }
// 重新刷入登陆时间 // 重新刷入登陆时间
RedisLoginInfo nweRedisLoginInfo = new RedisLoginInfo(userId, token, NumericUtil.sessionTimeOut(), redisLoginInfo.getSysmod(), noUiRequest.getTerminalType()); LoginInfo nweLoginInfo = new LoginInfo(userId, token, NumericUtil.sessionTimeOut(), loginInfo.getSysmod(), noUiRequest.getTerminalType());
EhcacheUtils.set(Constants.SESSION + "." + userId + "." + terminalType, nweRedisLoginInfo); EhcacheUtils.set(StringUtil.userUniqueId(noUiRequest), nweLoginInfo);
EhcacheUtils.set(StringUtil.getCacheSessionId(userId),request.getSession().getId()); EhcacheUtils.set(StringUtil.getCacheSessionId(userId), request.getSession().getId());
NoUiUtils.setLoginInfo(nweRedisLoginInfo); NoUiUtils.setLoginInfo(nweLoginInfo);
return true; return true;
} }
// 请求不通过,返回错误信息给客户端 // 请求不通过,返回错误信息给客户端
private void responseMessage(HttpServletResponse response, PrintWriter out, Result result) { private void responseMessage(HttpServletResponse response, PrintWriter out, Result result) {
response.setContentType("application/json; charset="+Constants.ENCODING); 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();
......
...@@ -61,7 +61,7 @@ public class NoUiPresentationUtil { ...@@ -61,7 +61,7 @@ public class NoUiPresentationUtil {
for (Map<String, Object> m : valueList) { for (Map<String, Object> m : valueList) {
IModule module = moduleList.add(); IModule module = moduleList.add();
for (Map.Entry<String, Object> entry : m.entrySet()) for (Map.Entry<String, Object> entry : m.entrySet())
handleDatafield(context, (IDatafield<Object>) module.get(changeForELCS(entry.getKey())), entry.getValue()); handleDatafield(context, (IDatafield<Object>) module.get(obfuscationPath(entry.getKey())), entry.getValue());
} }
} }
} }
...@@ -286,7 +286,7 @@ public class NoUiPresentationUtil { ...@@ -286,7 +286,7 @@ public class NoUiPresentationUtil {
IModule module = (IModule)moduleList.get(index); IModule module = (IModule)moduleList.get(index);
Collection<IDatafield> datafields = module.getDatafields(); Collection<IDatafield> datafields = module.getDatafields();
for (IDatafield datafield : datafields) { for (IDatafield datafield : datafields) {
map.put(changeForELCS(datafield.getName()), handle(datafield.getValue(), datafield)); map.put(obfuscationPath(datafield.getName()), handle(datafield.getValue(), datafield));
} }
list.add(map); list.add(map);
} }
...@@ -376,8 +376,8 @@ public class NoUiPresentationUtil { ...@@ -376,8 +376,8 @@ public class NoUiPresentationUtil {
return sysmodBytes; return sysmodBytes;
} }
//偏移 头4 尾7 //混淆路径,算法:偏移 头4 尾7
public static String changeForELCS(String str){ public static String obfuscationPath(String str){
if(NoUiUtils.fieldencode){ if(NoUiUtils.fieldencode){
String btw_str = str.substring(1,str.length()-1); String btw_str = str.substring(1,str.length()-1);
String head = change(str.charAt(0),4); String head = change(str.charAt(0),4);
......
...@@ -10,7 +10,7 @@ import org.sss.presentation.noui.api.request.NoUiRequest; ...@@ -10,7 +10,7 @@ import org.sss.presentation.noui.api.request.NoUiRequest;
import org.sss.presentation.noui.common.Constants; import org.sss.presentation.noui.common.Constants;
import org.sss.presentation.noui.context.NoUiContext; import org.sss.presentation.noui.context.NoUiContext;
import org.sss.presentation.noui.context.NoUiPresentation; import org.sss.presentation.noui.context.NoUiPresentation;
import org.sss.presentation.noui.jwt.RedisLoginInfo; import org.sss.presentation.noui.jwt.LoginInfo;
import org.sss.util.ContainerUtils; import org.sss.util.ContainerUtils;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -124,10 +124,10 @@ public class NoUiUtils { ...@@ -124,10 +124,10 @@ public class NoUiUtils {
} }
} }
public static ThreadLocal<RedisLoginInfo> tl = new ThreadLocal<RedisLoginInfo>(); public static ThreadLocal<LoginInfo> tl = new ThreadLocal<LoginInfo>();
public static void setLoginInfo(RedisLoginInfo redisLoginInfo){ public static void setLoginInfo(LoginInfo loginInfo){
tl.set(redisLoginInfo); tl.set(loginInfo);
} }
...@@ -151,27 +151,6 @@ public class NoUiUtils { ...@@ -151,27 +151,6 @@ public class NoUiUtils {
} }
public final static String salt= "706798214808651@;RHxC"; public final static String salt= "706798214808651@;RHxC";
/**
*
* @param keyParams 要素
* @return
*/
public static String genSafeCode(String[] keyParams)
{
StringBuilder sb = new StringBuilder();
sb = sb.append(tl.get().getUserInr()).reverse();
for(String item : keyParams)
{
sb.append(item);
}
sb.append(getToken());
sb.append(salt);
return DigestUtils.md5Hex(sb.toString());
}
public static boolean verfyParams(String[] keyParams,String safeCode)
{
return safeCode.equals(genSafeCode(keyParams));
}
public static String getDatapath() { public static String getDatapath() {
return datapath; return datapath;
......
...@@ -2,7 +2,7 @@ package org.sss.presentation.noui.util; ...@@ -2,7 +2,7 @@ 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.common.Constants;
import org.sss.presentation.noui.jwt.RedisLoginInfo; import org.sss.presentation.noui.jwt.LoginInfo;
public class ResourceAcccessEncryptUtil { public class ResourceAcccessEncryptUtil {
private static final String KEY = "session.##.WEB"; private static final String KEY = "session.##.WEB";
...@@ -23,9 +23,9 @@ public class ResourceAcccessEncryptUtil { ...@@ -23,9 +23,9 @@ public class ResourceAcccessEncryptUtil {
if (obj == null) { if (obj == null) {
return false; return false;
} }
RedisLoginInfo redisLoginInfo = (RedisLoginInfo) obj; LoginInfo loginInfo = (LoginInfo) obj;
StringBuilder raw = new StringBuilder(); StringBuilder raw = new StringBuilder();
raw.append(redisLoginInfo.getToken()); raw.append(loginInfo.getToken());
raw.append(SALT); raw.append(SALT);
raw.append(rawuid); raw.append(rawuid);
raw.append(SALT); raw.append(SALT);
......
package org.sss.presentation.noui.util; package org.sss.presentation.noui.util;
import org.sss.presentation.noui.api.request.NoUiRequest; import org.sss.presentation.noui.api.request.NoUiRequest;
import org.sss.presentation.noui.common.Constants; import org.sss.presentation.noui.common.Constants;
import java.security.MessageDigest; import java.security.MessageDigest;
public class StringUtil { public class StringUtil {
public static boolean isEmpty(String str) { public static boolean isEmpty(String str) {
if (str == null || str.trim().equals("")){ if (str == null || str.trim().equals("")) {
return true; return true;
} }
return false; return false;
} }
public static String userUniqueId(NoUiRequest request) { public static String userUniqueId(NoUiRequest request) {
return Constants.SESSION + "." + request.getUserId() + "." + request.getTerminalType(); String setKey = new StringBuilder(Constants.SESSION).append(".").
} append(request.getUserId()).append(".").append(request.getTerminalType()).toString();
return setKey;
/** }
* 获取指定用户缓存的sessionid
* /**
* @param userId 用户ID * 获取指定用户缓存的sessionid
* @return 返回指定用户登陆客户端的sessionid *
*/ * @param userId 用户ID
public static String getCacheSessionId(String userId) { * @return 返回指定用户登陆客户端的sessionid
String setKey = new StringBuilder(Constants.SESSION).append(".").append(userId).append(".CACHE_SESSION").toString(); */
return setKey; public static String getCacheSessionId(String userId) {
} String setKey = new StringBuilder(Constants.SESSION).append(".").append(userId).append(".CACHE_SESSION").toString();
return setKey;
/** }
* MD5加密字符串
* /**
* @param inStr * MD5加密字符串
* @return *
* @throws Exception * @param inStr
*/ * @return
public static String encryptMD5(String inStr) throws Exception { * @throws Exception
MessageDigest md5 = null; */
md5 = MessageDigest.getInstance("MD5"); public static String encryptMD5(String inStr) throws Exception {
char[] charArray = inStr.toCharArray(); MessageDigest md5 = null;
byte[] byteArray = new byte[charArray.length]; md5 = MessageDigest.getInstance("MD5");
char[] charArray = inStr.toCharArray();
for (int i = 0; i < charArray.length; i++) byte[] byteArray = new byte[charArray.length];
byteArray[i] = (byte) charArray[i];
for (int i = 0; i < charArray.length; i++)
byte[] md5Bytes = md5.digest(byteArray); byteArray[i] = (byte) charArray[i];
StringBuffer hexValue = new StringBuffer(); byte[] md5Bytes = md5.digest(byteArray);
for (int i = 0; i < md5Bytes.length; i++) { StringBuffer hexValue = new StringBuffer();
int val = ((int) md5Bytes[i]) & 0xff;
if (val < 16) for (int i = 0; i < md5Bytes.length; i++) {
hexValue.append("0"); int val = ((int) md5Bytes[i]) & 0xff;
hexValue.append(Integer.toHexString(val)); if (val < 16)
} hexValue.append("0");
hexValue.append(Integer.toHexString(val));
return hexValue.toString(); }
}
return hexValue.toString();
} }
}
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