|
|
@@ -88,124 +88,124 @@ public class RequestCheckFilter implements Filter {
|
|
|
String accessSpecial = request.getHeader(RequestConstant.ACCESS_SPECIAL);
|
|
|
String requestUri = request.getRequestURI();
|
|
|
|
|
|
- /*1、非token校验接口放行*/
|
|
|
- if (EXCLUDEPATH.contains(requestUri)) {
|
|
|
- filterChain.doFilter(servletRequest, servletResponse);
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- /*2、校验token**/
|
|
|
- /*2.1、校验token非空*/
|
|
|
- HttpResult result = checkBlank(token, clientType, systemType, accessSpecial, requestUri);
|
|
|
- if (result.getCode() != HttpStatus.SUCCESS_CODE) {
|
|
|
- ResponseUtil.writer(response, result);
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- /*2.2、token解析*/
|
|
|
- Map<String, Object> tokenMap = EncryUtil.descryV2(Global.PRI_KEY, token);
|
|
|
- if (tokenMap == null) {
|
|
|
- ResponseUtil.writer(response, HttpResult.error(HttpStatus.TOKEN_INVALID_CODE, HttpStatus.TOKEN_INVALID_MESSAGE));
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- /*2.3、从redis获取用户登录token*/
|
|
|
- Long userId = StringUtils.isNotBlank(tokenMap.get("userId")) ? NumberUtils.parseLong(tokenMap.get("userId")) : null;
|
|
|
- String key = Global.getFullUserTokenKey(clientType, accessSpecial, userId);
|
|
|
- String redisUserToken = RedissonUtils.getString(key);
|
|
|
- if (StringUtils.isBlank(redisUserToken)) {
|
|
|
- ResponseUtil.writer(response, HttpResult.error(HttpStatus.TOKEN_INVALID_CODE, HttpStatus.TOKEN_INVALID_MESSAGE));
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- /*2.4、请求token和redis中token不一致,说明账号在别处登录了*/
|
|
|
- if (!token.equals(redisUserToken)) {
|
|
|
- ResponseUtil.writer(response, HttpResult.error(HttpStatus.TOKEN_INVALID_CODE, HttpStatus.ACCOUNT_OTHER_LOGIN_MESSAGE));
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- /*3、校验登录用户信息*/
|
|
|
- key = Global.getFullUserLoginKey(systemType, userId);
|
|
|
- String userInfoStr = RedissonUtils.getString(key);
|
|
|
- LoginUserInfo loginUserInfo = StringUtils.isNotBlank(userInfoStr) ? JSON.parseObject(userInfoStr, LoginUserInfo.class) : null;
|
|
|
- if (Objects.isNull(loginUserInfo)) {
|
|
|
- ResponseUtil.writer(response, HttpResult.error(HttpStatus.TOKEN_INVALID_CODE, HttpStatus.TOKEN_INVALID_MESSAGE));
|
|
|
- return;
|
|
|
- }
|
|
|
- loginUserInfo.setClientType(clientType);
|
|
|
-
|
|
|
- //校验用户账号是否冻结
|
|
|
- if (loginUserInfo.getStatus() == Global.YES) {
|
|
|
- ResponseUtil.writer(response, HttpResult.error(HttpStatus.TOKEN_INVALID_CODE, "您的账号已被冻结,请联系系统管理员!"));
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- /*4、登录中的企业信息*/
|
|
|
- String loginEntStr = RedissonUtils.getString(Global.getFullUserEntKey(loginUserInfo.getEntId()));
|
|
|
- LoginEntInfo loginEntInfo = StringUtils.isNotBlank(loginEntStr) ? JSON.parseObject(loginEntStr, LoginEntInfo.class) : null;
|
|
|
- if (SystemTypeEnum.MANAGE.getCode().equals(systemType)) {
|
|
|
- //redis 获取客户经理绑定企业ID
|
|
|
- String managerKey = Global.getCustomerManagerUserLoginKey(SystemTypeEnum.MANAGE.getCode(), loginUserInfo.getId());
|
|
|
- RSet<Object> set = RedissonUtils.getSet(managerKey);
|
|
|
- if (Objects.nonNull(set)) {
|
|
|
- List authUserIdList = JSONObject.parseObject(set.toString(), List.class);
|
|
|
- if (CollectionUtils.isNotEmpty(authUserIdList)) {
|
|
|
- loginUserInfo.setAuthEntIdList(authUserIdList);
|
|
|
- }
|
|
|
- }
|
|
|
- LoginUserHolder.set(loginUserInfo);
|
|
|
- LoginEntHolder.set(loginEntInfo);
|
|
|
- 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);
|
|
|
- filterChain.doFilter(servletRequest, servletResponse);
|
|
|
- LoginUserHolder.remove();
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- 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));
|
|
|
- return;
|
|
|
- } else {
|
|
|
- //校验用户企业是否冻结
|
|
|
- if (Objects.isNull(loginEntInfo) || loginEntInfo.getStatus() == Global.YES) {
|
|
|
- ResponseUtil.writer(response, HttpResult.error(HttpStatus.TOKEN_INVALID_CODE, "您所属企业已被冻结,请联系系统管理员!"));
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- //校验用户企业审批状态
|
|
|
- if (!loginEntInfo.getValid() && !REGISTER.equals(requestUri)) {
|
|
|
- if (loginEntInfo.getApproval() == Global.NO) {
|
|
|
- ResponseUtil.writer(response, HttpResult.error(HttpStatus.CODE_60603, HttpStatus.ENTCERTIFICATES_NOT_REGISTER));
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- if (loginEntInfo.getApproval() == Global.NUMERICAL_THREE) {
|
|
|
- ResponseUtil.writer(response, HttpResult.error(HttpStatus.CODE_60603, HttpStatus.ENTCERTIFICATES_NOT_PASS));
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- ResponseUtil.writer(response, HttpResult.error(HttpStatus.CODE_60603, HttpStatus.ENTCERTIFICATES_INVAILD));
|
|
|
- return;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /*5、请求权限校验*/
|
|
|
- //非管理员有接口权限才放行
|
|
|
-// if (loginUserInfo.getIsMain() == Global.NO
|
|
|
-// && !WITHOUTPATH.contains(requestUri)
|
|
|
-// && !checkMenu(clientType, loginUserInfo.getId(), requestUri)) {
|
|
|
-// ResponseUtil.writer(response, HttpResult.error(HttpStatus.AUTHORITY_NO_CODE, HttpStatus.ACCESS_FIAL));
|
|
|
+// /*1、非token校验接口放行*/
|
|
|
+// if (EXCLUDEPATH.contains(requestUri)) {
|
|
|
+// filterChain.doFilter(servletRequest, servletResponse);
|
|
|
+// return;
|
|
|
+// }
|
|
|
+//
|
|
|
+// /*2、校验token**/
|
|
|
+// /*2.1、校验token非空*/
|
|
|
+// HttpResult result = checkBlank(token, clientType, systemType, accessSpecial, requestUri);
|
|
|
+// if (result.getCode() != HttpStatus.SUCCESS_CODE) {
|
|
|
+// ResponseUtil.writer(response, result);
|
|
|
+// return;
|
|
|
+// }
|
|
|
+//
|
|
|
+// /*2.2、token解析*/
|
|
|
+// Map<String, Object> tokenMap = EncryUtil.descryV2(Global.PRI_KEY, token);
|
|
|
+// if (tokenMap == null) {
|
|
|
+// ResponseUtil.writer(response, HttpResult.error(HttpStatus.TOKEN_INVALID_CODE, HttpStatus.TOKEN_INVALID_MESSAGE));
|
|
|
+// return;
|
|
|
+// }
|
|
|
+//
|
|
|
+// /*2.3、从redis获取用户登录token*/
|
|
|
+// Long userId = StringUtils.isNotBlank(tokenMap.get("userId")) ? NumberUtils.parseLong(tokenMap.get("userId")) : null;
|
|
|
+// String key = Global.getFullUserTokenKey(clientType, accessSpecial, userId);
|
|
|
+// String redisUserToken = RedissonUtils.getString(key);
|
|
|
+// if (StringUtils.isBlank(redisUserToken)) {
|
|
|
+// ResponseUtil.writer(response, HttpResult.error(HttpStatus.TOKEN_INVALID_CODE, HttpStatus.TOKEN_INVALID_MESSAGE));
|
|
|
+// return;
|
|
|
+// }
|
|
|
+//
|
|
|
+// /*2.4、请求token和redis中token不一致,说明账号在别处登录了*/
|
|
|
+// if (!token.equals(redisUserToken)) {
|
|
|
+// ResponseUtil.writer(response, HttpResult.error(HttpStatus.TOKEN_INVALID_CODE, HttpStatus.ACCOUNT_OTHER_LOGIN_MESSAGE));
|
|
|
+// return;
|
|
|
+// }
|
|
|
+//
|
|
|
+// /*3、校验登录用户信息*/
|
|
|
+// key = Global.getFullUserLoginKey(systemType, userId);
|
|
|
+// String userInfoStr = RedissonUtils.getString(key);
|
|
|
+// LoginUserInfo loginUserInfo = StringUtils.isNotBlank(userInfoStr) ? JSON.parseObject(userInfoStr, LoginUserInfo.class) : null;
|
|
|
+// if (Objects.isNull(loginUserInfo)) {
|
|
|
+// ResponseUtil.writer(response, HttpResult.error(HttpStatus.TOKEN_INVALID_CODE, HttpStatus.TOKEN_INVALID_MESSAGE));
|
|
|
+// return;
|
|
|
+// }
|
|
|
+// loginUserInfo.setClientType(clientType);
|
|
|
+//
|
|
|
+// //校验用户账号是否冻结
|
|
|
+// if (loginUserInfo.getStatus() == Global.YES) {
|
|
|
+// ResponseUtil.writer(response, HttpResult.error(HttpStatus.TOKEN_INVALID_CODE, "您的账号已被冻结,请联系系统管理员!"));
|
|
|
+// return;
|
|
|
+// }
|
|
|
+//
|
|
|
+// /*4、登录中的企业信息*/
|
|
|
+// String loginEntStr = RedissonUtils.getString(Global.getFullUserEntKey(loginUserInfo.getEntId()));
|
|
|
+// LoginEntInfo loginEntInfo = StringUtils.isNotBlank(loginEntStr) ? JSON.parseObject(loginEntStr, LoginEntInfo.class) : null;
|
|
|
+// if (SystemTypeEnum.MANAGE.getCode().equals(systemType)) {
|
|
|
+// //redis 获取客户经理绑定企业ID
|
|
|
+// String managerKey = Global.getCustomerManagerUserLoginKey(SystemTypeEnum.MANAGE.getCode(), loginUserInfo.getId());
|
|
|
+// RSet<Object> set = RedissonUtils.getSet(managerKey);
|
|
|
+// if (Objects.nonNull(set)) {
|
|
|
+// List authUserIdList = JSONObject.parseObject(set.toString(), List.class);
|
|
|
+// if (CollectionUtils.isNotEmpty(authUserIdList)) {
|
|
|
+// loginUserInfo.setAuthEntIdList(authUserIdList);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// LoginUserHolder.set(loginUserInfo);
|
|
|
+// LoginEntHolder.set(loginEntInfo);
|
|
|
+// 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);
|
|
|
+// filterChain.doFilter(servletRequest, servletResponse);
|
|
|
+// LoginUserHolder.remove();
|
|
|
+// return;
|
|
|
+// }
|
|
|
+//
|
|
|
+// 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));
|
|
|
// return;
|
|
|
+// } else {
|
|
|
+// //校验用户企业是否冻结
|
|
|
+// if (Objects.isNull(loginEntInfo) || loginEntInfo.getStatus() == Global.YES) {
|
|
|
+// ResponseUtil.writer(response, HttpResult.error(HttpStatus.TOKEN_INVALID_CODE, "您所属企业已被冻结,请联系系统管理员!"));
|
|
|
+// return;
|
|
|
+// }
|
|
|
+//
|
|
|
+// //校验用户企业审批状态
|
|
|
+// if (!loginEntInfo.getValid() && !REGISTER.equals(requestUri)) {
|
|
|
+// if (loginEntInfo.getApproval() == Global.NO) {
|
|
|
+// ResponseUtil.writer(response, HttpResult.error(HttpStatus.CODE_60603, HttpStatus.ENTCERTIFICATES_NOT_REGISTER));
|
|
|
+// return;
|
|
|
+// }
|
|
|
+//
|
|
|
+// if (loginEntInfo.getApproval() == Global.NUMERICAL_THREE) {
|
|
|
+// ResponseUtil.writer(response, HttpResult.error(HttpStatus.CODE_60603, HttpStatus.ENTCERTIFICATES_NOT_PASS));
|
|
|
+// return;
|
|
|
+// }
|
|
|
+//
|
|
|
+// ResponseUtil.writer(response, HttpResult.error(HttpStatus.CODE_60603, HttpStatus.ENTCERTIFICATES_INVAILD));
|
|
|
+// return;
|
|
|
+// }
|
|
|
// }
|
|
|
- LoginUserHolder.set(loginUserInfo);
|
|
|
- LoginEntHolder.set(loginEntInfo);
|
|
|
- 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.getFullUserTokenKey(clientType, accessSpecial, userId), token, ClientTypeEnum.expireTime(clientType));
|
|
|
+//
|
|
|
+// /*5、请求权限校验*/
|
|
|
+// //非管理员有接口权限才放行
|
|
|
+//// if (loginUserInfo.getIsMain() == Global.NO
|
|
|
+//// && !WITHOUTPATH.contains(requestUri)
|
|
|
+//// && !checkMenu(clientType, loginUserInfo.getId(), requestUri)) {
|
|
|
+//// ResponseUtil.writer(response, HttpResult.error(HttpStatus.AUTHORITY_NO_CODE, HttpStatus.ACCESS_FIAL));
|
|
|
+//// return;
|
|
|
+//// }
|
|
|
+// LoginUserHolder.set(loginUserInfo);
|
|
|
+// LoginEntHolder.set(loginEntInfo);
|
|
|
+// 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.getFullUserTokenKey(clientType, accessSpecial, userId), token, ClientTypeEnum.expireTime(clientType));
|
|
|
filterChain.doFilter(servletRequest, servletResponse);
|
|
|
- LoginUserHolder.remove();
|
|
|
- LoginEntHolder.remove();
|
|
|
+// LoginUserHolder.remove();
|
|
|
+// LoginEntHolder.remove();
|
|
|
}
|
|
|
|
|
|
|