Commit db28984f by fukai

优化

parent 590e6ba8
...@@ -31,7 +31,8 @@ public class NoUiRequest { ...@@ -31,7 +31,8 @@ public class NoUiRequest {
this.userId = userId; this.userId = userId;
this.terminalType = terminalType; this.terminalType = terminalType;
this.mappingUrl = mappingUrl; this.mappingUrl = mappingUrl;
if(request.getRequestURI().startsWith(NoUiContextManager.openSourcePrefix))
if(request.getRequestURI().indexOf(NoUiContextManager.openSourcePrefix+"/") >= 0)
{ {
this.openSource = true; //开放访问路径 this.openSource = true; //开放访问路径
} }
......
...@@ -166,6 +166,7 @@ public abstract class AbstractCommonController { ...@@ -166,6 +166,7 @@ public abstract class AbstractCommonController {
} }
String realPath = alias.getRelPath(aliasKey); String realPath = alias.getRelPath(aliasKey);
IBaseObject baseObject = context.getSession().getBaseObject(context.getRoot(), realPath); IBaseObject baseObject = context.getSession().getBaseObject(context.getRoot(), realPath);
data.put(aliasKey, NoUiPresentationUtil.handIBaseObject(context, baseObject, realPath)); data.put(aliasKey, NoUiPresentationUtil.handIBaseObject(context, baseObject, realPath));
} }
return data; return data;
...@@ -178,8 +179,20 @@ public abstract class AbstractCommonController { ...@@ -178,8 +179,20 @@ public abstract class AbstractCommonController {
for (Map.Entry<String, String> aliasEntry : alias.getRel().entrySet()) { for (Map.Entry<String, String> aliasEntry : alias.getRel().entrySet()) {
String aliasKey = aliasEntry.getKey(); String aliasKey = aliasEntry.getKey();
String aliasPath = aliasEntry.getValue(); String aliasPath = aliasEntry.getValue();
if(aliasPath == null)
{
log.error("错误的mapping:"+noUiRequest.getMappingUrl()+"--"+aliasKey+"--"+aliasPath);
continue;
}
if(modifyEntry.getKey() == null)
{
log.error("错误的modifymap:"+noUiRequest.getMappingUrl()+"--"+modifyMap);
continue;
}
if (aliasPath.startsWith(modifyEntry.getKey())) { if (aliasPath.startsWith(modifyEntry.getKey())) {
Object val = modifyEntry.getValue(); Object val = modifyEntry.getValue();
if(aliasKey == null)
continue;
data.put(aliasKey, NoUiPresentationUtil.handIBaseObject(context, val, aliasEntry.getValue())); data.put(aliasKey, NoUiPresentationUtil.handIBaseObject(context, val, aliasEntry.getValue()));
containsKeys.add(modifyEntry.getKey()); containsKeys.add(modifyEntry.getKey());
} }
...@@ -194,11 +207,12 @@ public abstract class AbstractCommonController { ...@@ -194,11 +207,12 @@ public abstract class AbstractCommonController {
System.out.println("modify datafield:" + (modifyMap.get(key) instanceof IDatafield)); System.out.println("modify datafield:" + (modifyMap.get(key) instanceof IDatafield));
System.out.println("modify module:" + (modifyMap.get(key) instanceof IModule)); System.out.println("modify module:" + (modifyMap.get(key) instanceof IModule));
System.out.println("modify moduleList:" + (modifyMap.get(key) instanceof IModuleList)); System.out.println("modify moduleList:" + (modifyMap.get(key) instanceof IModuleList));
if(key == null)
continue;
data.put(key, NoUiPresentationUtil.handIBaseObject(context, modifyMap.get(key), key)); data.put(key, NoUiPresentationUtil.handIBaseObject(context, modifyMap.get(key), key));
} }
} }
return data; return data;
} }
} }
...@@ -5,6 +5,7 @@ import java.util.HashMap; ...@@ -5,6 +5,7 @@ import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.UUID;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession; import javax.servlet.http.HttpSession;
...@@ -58,7 +59,7 @@ public class LoginController { ...@@ -58,7 +59,7 @@ public class LoginController {
login.setUserId(userId); login.setUserId(userId);
login.setPassword(password); login.setPassword(password);
// 给用户jwt加密生成token // 给用户jwt加密生成token
String token = JWT.sign(login, 60L * 1000L * 30L); String token = JWT.sign(login, NumericUtil.sessionTimeOut());
// 登陆成功后获取菜单并跳转到office交易 // 登陆成功后获取菜单并跳转到office交易
Map<String, Object> authMap = new HashMap<>(); Map<String, Object> authMap = new HashMap<>();
...@@ -74,6 +75,7 @@ public class LoginController { ...@@ -74,6 +75,7 @@ public class LoginController {
Map<String, Object> retDatamap = new HashMap<String, Object>(); Map<String, Object> retDatamap = new HashMap<String, Object>();
retDatamap.put("token", token); retDatamap.put("token", token);
retDatamap.put("menu", menuList); retDatamap.put("menu", menuList);
retDatamap.put("salt", UUID.randomUUID().toString());
context.getSession().chain(true, "office"); context.getSession().chain(true, "office");
byte[] sysmodBytes = NoUiPresentationUtil.sysmodToBytes(context); byte[] sysmodBytes = NoUiPresentationUtil.sysmodToBytes(context);
// redis中存储用户相关信息 // redis中存储用户相关信息
......
...@@ -35,9 +35,10 @@ public class JWT { ...@@ -35,9 +35,10 @@ public class JWT {
try { try {
final Map<String, Object> claims = verifier.verify(jwt); final Map<String, Object> claims = verifier.verify(jwt);
if (claims.containsKey(EXP) && claims.containsKey(PAYLOAD)) { if (claims.containsKey(EXP) && claims.containsKey(PAYLOAD)) {
long exp = (Long) claims.get(EXP); //long exp = (Long) claims.get(EXP);
long currentTimeMillis = System.currentTimeMillis(); //long currentTimeMillis = System.currentTimeMillis();
if (exp > currentTimeMillis) { //if (exp > currentTimeMillis)
{
String json = (String) claims.get(PAYLOAD); String json = (String) claims.get(PAYLOAD);
ObjectMapper objectMapper = new ObjectMapper(); ObjectMapper objectMapper = new ObjectMapper();
return objectMapper.readValue(json, classT); return objectMapper.readValue(json, classT);
......
...@@ -59,10 +59,17 @@ public class TokenInterceptor implements HandlerInterceptor { ...@@ -59,10 +59,17 @@ public class TokenInterceptor implements HandlerInterceptor {
responseMessage(response, response.getWriter(), rt); responseMessage(response, response.getWriter(), rt);
return false; return false;
} }
//验证token是否一致
if(!token.equals(redisLoginInfo.getToken())){
Result rt = new Result(ErrorCodes.LOGIN_TOKEN_CHECKERROR, "token失效,该用户被强迫下线", null);
responseMessage(response, response.getWriter(), rt);
return false;
}
// 验证登录时间 // 验证登录时间
if (System.currentTimeMillis() > redisLoginInfo.getExpiredTime()) { if (System.currentTimeMillis() > redisLoginInfo.getExpiredTime()) {
Result rt = new Result(ErrorCodes.LOGIN_TIMEOUT, "登录时间超长,请重新登录", null);
Result rt = new Result(ErrorCodes.LOGIN_TIMEOUT, "会话超时,请重新登录。超时时间戳:"+redisLoginInfo.getExpiredTime()+
",当前时间戳:"+System.currentTimeMillis(), null);
responseMessage(response, response.getWriter(), rt); responseMessage(response, response.getWriter(), rt);
return false; return false;
} }
......
...@@ -24,7 +24,8 @@ public class NoUiApiInitListener implements ServletContextListener { ...@@ -24,7 +24,8 @@ public class NoUiApiInitListener implements ServletContextListener {
private static final String LOGIN_CONTEXT_NAME = "loginContextName"; private static final String LOGIN_CONTEXT_NAME = "loginContextName";
private static final String OPEN_PREFIX = "openPrefix"; private static final String OPEN_PREFIX = "openPrefix";
private static final String OPEN_TRANS = "openTrans"; private static final String OPEN_TRANS = "openTrans";
private static final int ENDLESS_TIME = 5*24*60*60;
@Override @Override
public void contextDestroyed(ServletContextEvent arg0) { public void contextDestroyed(ServletContextEvent arg0) {
...@@ -36,10 +37,13 @@ public class NoUiApiInitListener implements ServletContextListener { ...@@ -36,10 +37,13 @@ public class NoUiApiInitListener implements ServletContextListener {
String dbType = context.getInitParameter(DATABASE_SUPPORT_TYPE); String dbType = context.getInitParameter(DATABASE_SUPPORT_TYPE);
int timeout = Integer.valueOf(context.getInitParameter(NOUI_TIMEOUT)); //秒数 int timeout = Integer.valueOf(context.getInitParameter(NOUI_TIMEOUT)); //秒数
if(timeout > 0) if(timeout > 0)
RedisUtil.setSessionTimeOut(timeout); RedisUtil.setSessionTimeOut(timeout);
else else
RedisUtil.setSessionTimeOut(3*30*24*60*60); //一个月 RedisUtil.setSessionTimeOut(ENDLESS_TIME); //一个月
log.debug("timeout:"+timeout);
log.debug("sessionTimeout:"+RedisUtil.getSessionTimeOut());
NoUiContextManager.dbType = dbType; NoUiContextManager.dbType = dbType;
NoUiContextManager.loginContextName = context.getInitParameter(LOGIN_CONTEXT_NAME); NoUiContextManager.loginContextName = context.getInitParameter(LOGIN_CONTEXT_NAME);
String openSource = context.getInitParameter(OPEN_PREFIX); String openSource = context.getInitParameter(OPEN_PREFIX);
......
...@@ -68,6 +68,7 @@ public class NoUiPresentationUtil { ...@@ -68,6 +68,7 @@ public class NoUiPresentationUtil {
} }
if (baseObject instanceof IModuleList<?> && value instanceof List<?>) { if (baseObject instanceof IModuleList<?> && value instanceof List<?>) {
IModuleList<IModule> moduleList = (IModuleList<IModule>) baseObject; IModuleList<IModule> moduleList = (IModuleList<IModule>) baseObject;
moduleList.clear();
List<Map<String, Object>> valueList = (List<Map<String, Object>>) value; List<Map<String, Object>> valueList = (List<Map<String, Object>>) value;
for (Map<String, Object> m : valueList) { for (Map<String, Object> m : valueList) {
IModule module = moduleList.add(); IModule module = moduleList.add();
...@@ -78,6 +79,7 @@ public class NoUiPresentationUtil { ...@@ -78,6 +79,7 @@ public class NoUiPresentationUtil {
} }
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace();
log.error("Input command error", e); log.error("Input command error", e);
throw new NoUiException("Input command error", e); throw new NoUiException("Input command error", e);
} }
...@@ -87,7 +89,7 @@ public class NoUiPresentationUtil { ...@@ -87,7 +89,7 @@ public class NoUiPresentationUtil {
} }
private static void handleDatafield(IContext context, IDatafield<Object> dataField, Object value) { private static void handleDatafield(IContext context, IDatafield<Object> dataField, Object value) {
if (null == value) if (null == value || dataField == null)
return; return;
Class<?> dataType = dataField.getDataType(); Class<?> dataType = dataField.getDataType();
if (dataType.equals(String.class)) { if (dataType.equals(String.class)) {
......
...@@ -70,6 +70,8 @@ public class RedisUtil { ...@@ -70,6 +70,8 @@ public class RedisUtil {
public static Object get(String key) { public static Object get(String key) {
Jedis jedis = jedisPool.getResource(); Jedis jedis = jedisPool.getResource();
Object getObj = jedis.get(key.getBytes()); Object getObj = jedis.get(key.getBytes());
if(getObj == null)
return null;
Object obj = SerializeUtil.unserialize((byte[]) getObj); Object obj = SerializeUtil.unserialize((byte[]) getObj);
jedis.close(); jedis.close();
return obj; return obj;
......
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