Commit 45299683 by cjh

代码版本同步

parent 8ff5dd8b
...@@ -28,12 +28,12 @@ public class ErrorCodes { ...@@ -28,12 +28,12 @@ public class ErrorCodes {
public static final String UNSUPPORTED_DATA_TYPE = "R0016"; public static final String UNSUPPORTED_DATA_TYPE = "R0016";
public static final String UNKNOEW_TRANS = "R0017"; public static final String UNKNOEW_TRANS = "R0017";
public static final String FORBIDDEN_TRANS = "R0018"; public static final String FORBIDDEN_TRANS = "R0018";
public static final String INTERRUPTED_ERROR = "R9997"; public static final String INTERRUPTED_ERROR = "R9997";
public static final String REDIS_CONNECTION_ERROR = "R9998"; public static final String REDIS_CONNECTION_ERROR = "R9998";
public static final String ERROR = "R9999"; public static final String ERROR = "R9999";
public static final String BUSINESS_ERROR = "E0001"; public static final String BUSINESS_ERROR = "E0001";
} }
...@@ -8,6 +8,7 @@ public class Constants { ...@@ -8,6 +8,7 @@ public class Constants {
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 DISPLAY_FILE_NAME = "fileName"; public final static String DISPLAY_FILE_NAME = "fileName";
......
package org.sss.presentation.noui.controller; package org.sss.presentation.noui.controller;
import java.util.ArrayList; import java.util.*;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
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;
...@@ -23,6 +18,7 @@ import org.sss.common.model.IMenuItem; ...@@ -23,6 +18,7 @@ import org.sss.common.model.IMenuItem;
import org.sss.presentation.noui.api.exception.NoUiException; import org.sss.presentation.noui.api.exception.NoUiException;
import org.sss.presentation.noui.api.model.Menu; import org.sss.presentation.noui.api.model.Menu;
import org.sss.presentation.noui.api.request.NoUiRequest; import org.sss.presentation.noui.api.request.NoUiRequest;
import org.sss.presentation.noui.api.response.ErrorCode;
import org.sss.presentation.noui.api.response.ErrorCodes; import org.sss.presentation.noui.api.response.ErrorCodes;
import org.sss.presentation.noui.api.response.ResultUtil; import org.sss.presentation.noui.api.response.ResultUtil;
import org.sss.presentation.noui.common.Constants; import org.sss.presentation.noui.common.Constants;
...@@ -39,6 +35,7 @@ import org.sss.presentation.noui.util.StringUtil; ...@@ -39,6 +35,7 @@ import org.sss.presentation.noui.util.StringUtil;
@Controller @Controller
public class LoginController { public class LoginController {
private static final Log log = LogFactory.getLog(LoginController.class); private static final Log log = LogFactory.getLog(LoginController.class);
public static final String ERROR="error";
@ResponseBody @ResponseBody
@RequestMapping(value = "/login", method = RequestMethod.POST) @RequestMapping(value = "/login", method = RequestMethod.POST)
...@@ -46,11 +43,13 @@ public class LoginController { ...@@ -46,11 +43,13 @@ public class LoginController {
// TODO??? // TODO???
//System.out.println(dataMap); //System.out.println(dataMap);
NoUiRequest noUiRequest = new NoUiRequest(request, "", dataMap); NoUiRequest noUiRequest = new NoUiRequest(request, "", dataMap);
Map<String, Object> map = new HashMap<String, Object>(); Map<String, Object> map = new HashMap<>();//此map会存储返回错误码
String userId = noUiRequest.getDataMap().get(Constants.USERNAME).toString(); String userId = noUiRequest.getDataMap().get(Constants.USERNAME).toString();
String password = noUiRequest.getDataMap().get(Constants.PASSWORD).toString(); String password = noUiRequest.getDataMap().get(Constants.PASSWORD).toString();
String dncode = noUiRequest.getDataMap().get(Constants.DNCODE).toString();
map.put("j_username", userId); map.put("j_username", userId);
map.put("j_password", password); map.put("j_password", password);
map.put("j_dncode", dncode);
NoUiContext context = NoUiContextManager.createNoUiContext(noUiRequest); NoUiContext context = NoUiContextManager.createNoUiContext(noUiRequest);
try { try {
if (context.getSession().login(map)) { if (context.getSession().login(map)) {
...@@ -82,12 +81,25 @@ public class LoginController { ...@@ -82,12 +81,25 @@ public class LoginController {
RedisLoginInfo redisLoginInfo = new RedisLoginInfo(userId, token, NumericUtil.sessionTimeOut(), sysmodBytes,noUiRequest.getTerminalType()); RedisLoginInfo redisLoginInfo = new RedisLoginInfo(userId, token, NumericUtil.sessionTimeOut(), sysmodBytes,noUiRequest.getTerminalType());
RedisUtil.set(StringUtil.userUniqueId(noUiRequest), redisLoginInfo); RedisUtil.set(StringUtil.userUniqueId(noUiRequest), redisLoginInfo);
return ResultUtil.result(ErrorCodes.SUCCESS, ErrorCodes.SUCCESS_INFO, retDatamap); //解决初次登陆,超期限登陆
final Object o = map.get(ERROR);
if (Objects.isNull(o)) {
return ResultUtil.result(ErrorCodes.SUCCESS, ErrorCodes.SUCCESS_INFO, retDatamap);
}else {
ErrorCode errorCode = (ErrorCode) o;
log.error(errorCode);
return ResultUtil.result(errorCode.getCode(), errorCode.getMessage(), retDatamap);
}
}else {
final ErrorCode errorCode = (ErrorCode) map.get(ERROR);
log.error(errorCode);
return ResultUtil.result(errorCode.getCode(), errorCode.getMessage(), null);
} }
} catch (Exception e) { } catch (Exception e) {
log.error("Login command error", e); log.error("Login command error", e);
//throw new NoUiException("Login command error", e); //throw new NoUiException("Login command error", e);
return ResultUtil.result(ErrorCodes.ERROR, "login failed with exception", null); // return ResultUtil.result(ErrorCodes.ERROR, "login failed with exception", null);
return ResultUtil.result(ErrorCode.SYSTEM_ERROR.getCode(), ErrorCode.SYSTEM_ERROR.getMessage(), null);
} }
finally{ finally{
if (context != null) if (context != null)
...@@ -96,10 +108,13 @@ public class LoginController { ...@@ -96,10 +108,13 @@ public class LoginController {
context.dispose(); context.dispose();
} }
} }
log.debug("Login command is finished"); // log.debug("Login command is finished");
return ResultUtil.result(ErrorCodes.ERROR, "login failed", null); // return ResultUtil.result(ErrorCodes.ERROR, "login failed", null);
} }
/* /*
* private void getMenu(IMenuItem menuItem, List<Map<String, String>> * private void getMenu(IMenuItem menuItem, List<Map<String, String>>
* menuList) { Iterator<IMenuItem> iterator = menuItem.iterator(); while * menuList) { Iterator<IMenuItem> iterator = menuItem.iterator(); while
...@@ -122,14 +137,14 @@ public class LoginController { ...@@ -122,14 +137,14 @@ public class LoginController {
getMenus(item, subMenuList); getMenus(item, subMenuList);
} }
} }
@ResponseBody @ResponseBody
@RequestMapping(value = "/logout", method = RequestMethod.POST) @RequestMapping(value = "/logout", method = RequestMethod.POST)
public Object logout(@RequestBody Map<String, Object> dataMap, HttpServletRequest request, HttpSession session) { public Object logout(@RequestBody Map<String, Object> dataMap, HttpServletRequest request, HttpSession session) {
return "ok"; return "ok";
} }
} }
...@@ -47,6 +47,12 @@ public class TokenInterceptor implements HandlerInterceptor { ...@@ -47,6 +47,12 @@ public class TokenInterceptor implements HandlerInterceptor {
return false; return false;
} }
//如果为后台直接调用交易,则直接跳过token验证,无需redis缓存
if (token.startsWith(Constants.BACKGROUND_FLAG)) {
return true;
}
JwtLogin login = JWT.unsign(token, JwtLogin.class); JwtLogin login = JWT.unsign(token, JwtLogin.class);
if (login == null || (!userId.equals((login.getUserId())))) { if (login == null || (!userId.equals((login.getUserId())))) {
Result rt = new Result(ErrorCodes.LOGIN_TOKEN_CHECKERROR, "用户token或ID验证不通过", null); Result rt = new Result(ErrorCodes.LOGIN_TOKEN_CHECKERROR, "用户token或ID验证不通过", null);
...@@ -60,15 +66,15 @@ public class TokenInterceptor implements HandlerInterceptor { ...@@ -60,15 +66,15 @@ public class TokenInterceptor implements HandlerInterceptor {
responseMessage(response, response.getWriter(), rt); responseMessage(response, response.getWriter(), rt);
return false; return false;
} }
//验证token是否一致 如果为后台直接调用交易,则直接跳过token验证 //验证token是否一致
if( !token.startsWith(Constants.BACKGROUND_FLAG) && !token.equals(redisLoginInfo.getToken())){ if(!token.equals(redisLoginInfo.getToken())){
Result rt = new Result(ErrorCodes.LOGIN_TOKEN_CHECKERROR, "token失效,该用户被强迫下线", null); Result rt = new Result(ErrorCodes.LOGIN_TOKEN_CHECKERROR, "token失效,该用户被强迫下线", null);
responseMessage(response, response.getWriter(), rt); responseMessage(response, response.getWriter(), rt);
return false; return false;
} }
// 验证登录时间 // 验证登录时间
if (System.currentTimeMillis() > redisLoginInfo.getExpiredTime()) { if (System.currentTimeMillis() > redisLoginInfo.getExpiredTime()) {
Result rt = new Result(ErrorCodes.LOGIN_TIMEOUT, "会话超时,请重新登录。超时时间戳:"+redisLoginInfo.getExpiredTime()+ Result rt = new Result(ErrorCodes.LOGIN_TIMEOUT, "会话超时,请重新登录。超时时间戳:"+redisLoginInfo.getExpiredTime()+
",当前时间戳:"+System.currentTimeMillis(), null); ",当前时间戳:"+System.currentTimeMillis(), null);
responseMessage(response, response.getWriter(), rt); responseMessage(response, response.getWriter(), rt);
...@@ -76,7 +82,7 @@ public class TokenInterceptor implements HandlerInterceptor { ...@@ -76,7 +82,7 @@ public class TokenInterceptor implements HandlerInterceptor {
} }
// 重新刷入登陆时间 // 重新刷入登陆时间
RedisLoginInfo nweRedisLoginInfo = new RedisLoginInfo(userId, token, NumericUtil.sessionTimeOut(), redisLoginInfo.getSysmod(),terminalType); RedisLoginInfo nweRedisLoginInfo = new RedisLoginInfo(userId, token, NumericUtil.sessionTimeOut(), redisLoginInfo.getSysmod(),noUiRequest.getTerminalType());
RedisUtil.set(Constants.SESSION + "." + userId + "." + terminalType, nweRedisLoginInfo); RedisUtil.set(Constants.SESSION + "." + userId + "." + terminalType, nweRedisLoginInfo);
return true; return true;
......
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