|
@@ -74,7 +74,8 @@ public class RequestCheckFilter implements Filter {
|
|
|
HttpServletResponse response = (HttpServletResponse) servletResponse;
|
|
HttpServletResponse response = (HttpServletResponse) servletResponse;
|
|
|
String token = request.getHeader(RequestConstant.TOKEN);
|
|
String token = request.getHeader(RequestConstant.TOKEN);
|
|
|
String clientType = request.getHeader(RequestConstant.CLIENT_TYPE);
|
|
String clientType = request.getHeader(RequestConstant.CLIENT_TYPE);
|
|
|
- String systemType = request.getHeader(RequestConstant.SYSTEM_TYPE);
|
|
|
|
|
|
|
+ Integer systemType = request.getIntHeader(RequestConstant.SYSTEM_TYPE);
|
|
|
|
|
+ String accessSpecial = request.getHeader(RequestConstant.ACCESS_SPECIAL);
|
|
|
String requestUri = request.getRequestURI();
|
|
String requestUri = request.getRequestURI();
|
|
|
|
|
|
|
|
/*1、非token校验接口放行*/
|
|
/*1、非token校验接口放行*/
|
|
@@ -85,8 +86,9 @@ public class RequestCheckFilter implements Filter {
|
|
|
|
|
|
|
|
/*2、校验token**/
|
|
/*2、校验token**/
|
|
|
/*2.1、校验token非空*/
|
|
/*2.1、校验token非空*/
|
|
|
- if (StringUtils.isBlank(token)) {
|
|
|
|
|
- ResponseUtil.writer(response, HttpResult.error(HttpStatus.TOKEN_INVALID_CODE, HttpStatus.UN_LOGIN_MESSAGE));
|
|
|
|
|
|
|
+ HttpResult result = checkBlank(token, clientType, systemType, accessSpecial);
|
|
|
|
|
+ if (result.getCode() != HttpStatus.SUCCESS_CODE) {
|
|
|
|
|
+ ResponseUtil.writer(response, result);
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -99,7 +101,8 @@ public class RequestCheckFilter implements Filter {
|
|
|
|
|
|
|
|
/*2.3、从redis获取用户登录token*/
|
|
/*2.3、从redis获取用户登录token*/
|
|
|
Long userId = StringUtils.isNotBlank(tokenMap.get("userId")) ? NumberUtils.parseLong(tokenMap.get("userId")) : null;
|
|
Long userId = StringUtils.isNotBlank(tokenMap.get("userId")) ? NumberUtils.parseLong(tokenMap.get("userId")) : null;
|
|
|
- String redisUserToken = RedissonUtils.getString(Global.getFullUserTokenKey(clientType, userId));
|
|
|
|
|
|
|
+ String key = Global.getFullUserTokenKey(clientType, accessSpecial, userId);
|
|
|
|
|
+ String redisUserToken = RedissonUtils.getString(key);
|
|
|
if (StringUtils.isBlank(redisUserToken)) {
|
|
if (StringUtils.isBlank(redisUserToken)) {
|
|
|
ResponseUtil.writer(response, HttpResult.error(HttpStatus.TOKEN_INVALID_CODE, HttpStatus.TOKEN_INVALID_MESSAGE));
|
|
ResponseUtil.writer(response, HttpResult.error(HttpStatus.TOKEN_INVALID_CODE, HttpStatus.TOKEN_INVALID_MESSAGE));
|
|
|
return;
|
|
return;
|
|
@@ -112,7 +115,7 @@ public class RequestCheckFilter implements Filter {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/*3、校验登录用户信息*/
|
|
/*3、校验登录用户信息*/
|
|
|
- String key = Global.getFullUserLoginKey(NumberUtils.parseInt(systemType), userId);
|
|
|
|
|
|
|
+ key = Global.getFullUserLoginKey(systemType, userId);
|
|
|
String userInfoStr = RedissonUtils.getString(key);
|
|
String userInfoStr = RedissonUtils.getString(key);
|
|
|
LoginUserInfo loginUserInfo = StringUtils.isNotBlank(userInfoStr) ? JSON.parseObject(userInfoStr, LoginUserInfo.class) : null;
|
|
LoginUserInfo loginUserInfo = StringUtils.isNotBlank(userInfoStr) ? JSON.parseObject(userInfoStr, LoginUserInfo.class) : null;
|
|
|
if (Objects.isNull(loginUserInfo)) {
|
|
if (Objects.isNull(loginUserInfo)) {
|
|
@@ -130,8 +133,7 @@ public class RequestCheckFilter implements Filter {
|
|
|
/*4、登录中的企业信息*/
|
|
/*4、登录中的企业信息*/
|
|
|
String loginEntStr = RedissonUtils.getString(Global.getFullUserEntKey(loginUserInfo.getEntId()));
|
|
String loginEntStr = RedissonUtils.getString(Global.getFullUserEntKey(loginUserInfo.getEntId()));
|
|
|
LoginEntInfo loginEntInfo = StringUtils.isNotBlank(loginEntStr) ? JSON.parseObject(loginEntStr, LoginEntInfo.class) : null;
|
|
LoginEntInfo loginEntInfo = StringUtils.isNotBlank(loginEntStr) ? JSON.parseObject(loginEntStr, LoginEntInfo.class) : null;
|
|
|
-
|
|
|
|
|
- if (SystemTypeEnum.MANAGE.getCode().equals(Integer.parseInt(systemType))) {
|
|
|
|
|
|
|
+ if (SystemTypeEnum.MANAGE.getCode().equals(systemType)) {
|
|
|
//redis 获取客户经理绑定企业ID
|
|
//redis 获取客户经理绑定企业ID
|
|
|
String managerKey = Global.getCustomerManagerUserLoginKey(SystemTypeEnum.MANAGE.getCode(), loginUserInfo.getId());
|
|
String managerKey = Global.getCustomerManagerUserLoginKey(SystemTypeEnum.MANAGE.getCode(), loginUserInfo.getId());
|
|
|
RSet<Object> set = RedissonUtils.getSet(managerKey);
|
|
RSet<Object> set = RedissonUtils.getSet(managerKey);
|
|
@@ -143,15 +145,15 @@ public class RequestCheckFilter implements Filter {
|
|
|
}
|
|
}
|
|
|
LoginUserHolder.set(loginUserInfo);
|
|
LoginUserHolder.set(loginUserInfo);
|
|
|
LoginEntHolder.set(loginEntInfo);
|
|
LoginEntHolder.set(loginEntInfo);
|
|
|
- RedissonUtils.putString(Global.getFullUserTokenKey(clientType, userId), token, ClientTypeEnum.expireTime(clientType));
|
|
|
|
|
- RedissonUtils.putString(Global.getFullUserLoginKey(NumberUtils.parseInt(systemType), loginUserInfo.getId()), JSON.toJSONString(loginUserInfo), Global.APP_TOKEN_EXPIRE);
|
|
|
|
|
|
|
+ RedissonUtils.putString(Global.getFullUserTokenKey(clientType , accessSpecial, userId), token, ClientTypeEnum.expireTime(clientType));
|
|
|
|
|
+ RedissonUtils.putString(Global.getFullUserLoginKey(systemType, loginUserInfo.getId()), JSON.toJSONString(loginUserInfo), Global.APP_TOKEN_EXPIRE);
|
|
|
RedissonUtils.putString(Global.getFullUserEntKey(loginEntInfo.getId()), JSON.toJSONString(loginEntInfo), Global.APP_TOKEN_EXPIRE);
|
|
RedissonUtils.putString(Global.getFullUserEntKey(loginEntInfo.getId()), JSON.toJSONString(loginEntInfo), Global.APP_TOKEN_EXPIRE);
|
|
|
filterChain.doFilter(servletRequest, servletResponse);
|
|
filterChain.doFilter(servletRequest, servletResponse);
|
|
|
LoginUserHolder.remove();
|
|
LoginUserHolder.remove();
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if ((StringUtils.isBlank(loginEntStr) || loginEntInfo == null) && NumberUtils.parseInt(systemType) != SystemTypeEnum.MANAGE.getCode()) {
|
|
|
|
|
|
|
+ if ((StringUtils.isBlank(loginEntStr) || loginEntInfo == null) && !Objects.equals(systemType, SystemTypeEnum.MANAGE.getCode())) {
|
|
|
ResponseUtil.writer(response, HttpResult.error(HttpStatus.TOKEN_INVALID_CODE, HttpStatus.UN_LOGIN_MESSAGE));
|
|
ResponseUtil.writer(response, HttpResult.error(HttpStatus.TOKEN_INVALID_CODE, HttpStatus.UN_LOGIN_MESSAGE));
|
|
|
return;
|
|
return;
|
|
|
} else {
|
|
} else {
|
|
@@ -188,9 +190,9 @@ public class RequestCheckFilter implements Filter {
|
|
|
// }
|
|
// }
|
|
|
LoginUserHolder.set(loginUserInfo);
|
|
LoginUserHolder.set(loginUserInfo);
|
|
|
LoginEntHolder.set(loginEntInfo);
|
|
LoginEntHolder.set(loginEntInfo);
|
|
|
- RedissonUtils.putString(Global.getFullUserLoginKey(NumberUtils.parseInt(systemType), loginUserInfo.getId()), JSON.toJSONString(loginUserInfo), Global.APP_TOKEN_EXPIRE);
|
|
|
|
|
|
|
+ RedissonUtils.putString(Global.getFullUserLoginKey(systemType, loginUserInfo.getId()), JSON.toJSONString(loginUserInfo), Global.APP_TOKEN_EXPIRE);
|
|
|
RedissonUtils.putString(Global.getFullUserEntKey(loginEntInfo.getId()), JSON.toJSONString(loginEntInfo), Global.APP_TOKEN_EXPIRE);
|
|
RedissonUtils.putString(Global.getFullUserEntKey(loginEntInfo.getId()), JSON.toJSONString(loginEntInfo), Global.APP_TOKEN_EXPIRE);
|
|
|
- RedissonUtils.putString(Global.getFullUserTokenKey(clientType, userId), token, ClientTypeEnum.expireTime(clientType));
|
|
|
|
|
|
|
+ RedissonUtils.putString(Global.getFullUserTokenKey(clientType, accessSpecial, userId), token, ClientTypeEnum.expireTime(clientType));
|
|
|
filterChain.doFilter(servletRequest, servletResponse);
|
|
filterChain.doFilter(servletRequest, servletResponse);
|
|
|
LoginUserHolder.remove();
|
|
LoginUserHolder.remove();
|
|
|
LoginEntHolder.remove();
|
|
LoginEntHolder.remove();
|
|
@@ -208,6 +210,33 @@ public class RequestCheckFilter implements Filter {
|
|
|
return RedissonUtils.contains(Global.REDIS_SYS_MENU_PREFIX + clientType + Global.COLON + userId, url);
|
|
return RedissonUtils.contains(Global.REDIS_SYS_MENU_PREFIX + clientType + Global.COLON + userId, url);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @param token token
|
|
|
|
|
+ * @param clientType 客户端类型
|
|
|
|
|
+ * @param systemType 系统类型
|
|
|
|
|
+ * @param accessSpecial 专场标识
|
|
|
|
|
+ * @return 校验结果
|
|
|
|
|
+ * @desc Hearder内容校验
|
|
|
|
|
+ * @author zk
|
|
|
|
|
+ * @date 2023/12/14
|
|
|
|
|
+ **/
|
|
|
|
|
+ private HttpResult checkBlank(String token, String clientType, Integer systemType, String accessSpecial) {
|
|
|
|
|
+ if (StringUtils.isBlank(token)) {
|
|
|
|
|
+ return HttpResult.error(HttpStatus.PARAMETERS_MISSING_CODE, HttpStatus.UN_LOGIN_MESSAGE);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (StringUtils.isBlank(clientType)) {
|
|
|
|
|
+ return HttpResult.error(HttpStatus.PARAMETERS_MISSING_CODE, HttpStatus.INVALID_REQUEST);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (StringUtils.isBlank(systemType)) {
|
|
|
|
|
+ return HttpResult.error(HttpStatus.PARAMETERS_MISSING_CODE, HttpStatus.INVALID_REQUEST);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (StringUtils.isBlank(accessSpecial) && !Objects.equals(systemType, SystemTypeEnum.MANAGE.getCode())) {
|
|
|
|
|
+ return HttpResult.error(HttpStatus.PARAMETERS_MISSING_CODE, HttpStatus.INVALID_REQUEST);
|
|
|
|
|
+ }
|
|
|
|
|
+ accessSpecial = !Objects.equals(systemType, SystemTypeEnum.MANAGE.getCode()) ? accessSpecial : null;
|
|
|
|
|
+ return HttpResult.ok();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
public static void main(String[] args) {
|
|
public static void main(String[] args) {
|
|
|
Map<String, Object> tokenMap = EncryUtil.descryV2(Global.PRI_KEY, "afc3fc350d5c17e52beba3bcd631eaca9f5f440509f72b182880a429b1b9b22b53154436ec72865566320514f3a6e39389c2ed412180c90b07f6ff66c12a5e139ed05793cf37d580ae9a2a166ddd79d6b7cd10e209d78c6eee9381d878df29f7");
|
|
Map<String, Object> tokenMap = EncryUtil.descryV2(Global.PRI_KEY, "afc3fc350d5c17e52beba3bcd631eaca9f5f440509f72b182880a429b1b9b22b53154436ec72865566320514f3a6e39389c2ed412180c90b07f6ff66c12a5e139ed05793cf37d580ae9a2a166ddd79d6b7cd10e209d78c6eee9381d878df29f7");
|
|
|
System.out.println(tokenMap);
|
|
System.out.println(tokenMap);
|