|
@@ -1,6 +1,7 @@
|
|
|
-package com.sckw.core.filter;
|
|
|
|
|
|
|
+package com.sckw.gateway.filter;
|
|
|
|
|
|
|
|
-import com.alibaba.fastjson.JSON;
|
|
|
|
|
|
|
+import com.alibaba.fastjson.serializer.SimplePropertyPreFilter;
|
|
|
|
|
+import com.alibaba.fastjson2.JSON;
|
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
|
import com.sckw.core.model.constant.Global;
|
|
import com.sckw.core.model.constant.Global;
|
|
|
import com.sckw.core.model.enums.ClientTypeEnum;
|
|
import com.sckw.core.model.enums.ClientTypeEnum;
|
|
@@ -12,31 +13,31 @@ import com.sckw.core.utils.StringUtils;
|
|
|
import com.sckw.core.web.config.CustomConfig;
|
|
import com.sckw.core.web.config.CustomConfig;
|
|
|
import com.sckw.core.web.constant.HttpStatus;
|
|
import com.sckw.core.web.constant.HttpStatus;
|
|
|
import com.sckw.core.web.constant.RequestConstant;
|
|
import com.sckw.core.web.constant.RequestConstant;
|
|
|
-import com.sckw.core.web.context.LoginEntHolder;
|
|
|
|
|
-import com.sckw.core.web.context.LoginUserHolder;
|
|
|
|
|
import com.sckw.core.web.model.LoginEntInfo;
|
|
import com.sckw.core.web.model.LoginEntInfo;
|
|
|
import com.sckw.core.web.model.LoginUserInfo;
|
|
import com.sckw.core.web.model.LoginUserInfo;
|
|
|
-import com.sckw.core.web.response.HttpResult;
|
|
|
|
|
-import com.sckw.core.web.response.ResponseUtil;
|
|
|
|
|
|
|
+import com.sckw.gateway.pojo.HttpResult;
|
|
|
import com.sckw.redis.utils.RedissonUtils;
|
|
import com.sckw.redis.utils.RedissonUtils;
|
|
|
import jakarta.annotation.PostConstruct;
|
|
import jakarta.annotation.PostConstruct;
|
|
|
-import jakarta.servlet.*;
|
|
|
|
|
-import jakarta.servlet.http.HttpServletRequest;
|
|
|
|
|
-import jakarta.servlet.http.HttpServletResponse;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.redisson.api.RSet;
|
|
import org.redisson.api.RSet;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
+import org.springframework.cloud.gateway.filter.GatewayFilterChain;
|
|
|
|
|
+import org.springframework.cloud.gateway.filter.GlobalFilter;
|
|
|
|
|
+import org.springframework.core.Ordered;
|
|
|
|
|
+import org.springframework.core.io.buffer.DataBuffer;
|
|
|
|
|
+import org.springframework.http.server.reactive.ServerHttpRequest;
|
|
|
|
|
+import org.springframework.http.server.reactive.ServerHttpResponse;
|
|
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
|
|
+import org.springframework.web.server.ServerWebExchange;
|
|
|
|
|
+import reactor.core.publisher.Mono;
|
|
|
|
|
|
|
|
-import java.io.IOException;
|
|
|
|
|
|
|
+import java.net.URLEncoder;
|
|
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
|
|
|
|
-/**
|
|
|
|
|
- * @desc: 登录过滤
|
|
|
|
|
- * @author: czh
|
|
|
|
|
- * @date: 2023/6/14
|
|
|
|
|
- */
|
|
|
|
|
@Slf4j
|
|
@Slf4j
|
|
|
-public class RequestCheckFilter implements Filter {
|
|
|
|
|
|
|
+@Component
|
|
|
|
|
+public class AuthenticationFilter implements GlobalFilter, Ordered {
|
|
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
|
CustomConfig customConfig;
|
|
CustomConfig customConfig;
|
|
@@ -58,6 +59,7 @@ public class RequestCheckFilter implements Filter {
|
|
|
|
|
|
|
|
private static final String REGISTER = "/kwsEnt/register";
|
|
private static final String REGISTER = "/kwsEnt/register";
|
|
|
|
|
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* @desc: 初始化放行路径
|
|
* @desc: 初始化放行路径
|
|
|
* @author: czh
|
|
* @author: czh
|
|
@@ -71,7 +73,7 @@ public class RequestCheckFilter implements Filter {
|
|
|
|
|
|
|
|
String specialLinks = customConfig.getSpecialLinks();
|
|
String specialLinks = customConfig.getSpecialLinks();
|
|
|
if (StringUtils.isNotBlank(specialLinks)) {
|
|
if (StringUtils.isNotBlank(specialLinks)) {
|
|
|
- IMPORT_PASS_PATH.addAll(Arrays.asList(links.split(Global.COMMA)));
|
|
|
|
|
|
|
+ IMPORT_PASS_PATH.addAll(Arrays.asList(specialLinks.split(Global.COMMA)));
|
|
|
}
|
|
}
|
|
|
// String withoutLinks = customConfig.getWithoutLinks();
|
|
// String withoutLinks = customConfig.getWithoutLinks();
|
|
|
// if (StringUtils.isNotBlank(withoutLinks)) {
|
|
// if (StringUtils.isNotBlank(withoutLinks)) {
|
|
@@ -80,60 +82,38 @@ public class RequestCheckFilter implements Filter {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
- public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse,
|
|
|
|
|
- FilterChain filterChain) throws IOException, ServletException {
|
|
|
|
|
- HttpServletRequest request = (HttpServletRequest) servletRequest;
|
|
|
|
|
- HttpServletResponse response = (HttpServletResponse) servletResponse;
|
|
|
|
|
- String token = request.getHeader(RequestConstant.TOKEN);
|
|
|
|
|
- String clientType = request.getHeader(RequestConstant.CLIENT_TYPE);
|
|
|
|
|
- Integer systemType = request.getIntHeader(RequestConstant.SYSTEM_TYPE);
|
|
|
|
|
|
|
+ public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
|
|
|
|
|
+ ServerHttpRequest request = exchange.getRequest();
|
|
|
|
|
+ ServerHttpResponse response = exchange.getResponse();
|
|
|
|
|
+ String token = request.getHeaders().getFirst(RequestConstant.TOKEN);
|
|
|
|
|
+ String clientType = request.getHeaders().getFirst(RequestConstant.CLIENT_TYPE);
|
|
|
|
|
+ String systemTypeStr = request.getHeaders().getFirst(RequestConstant.SYSTEM_TYPE);
|
|
|
|
|
+ Integer systemType = systemTypeStr == null ? null : Integer.parseInt(systemTypeStr);
|
|
|
// String accessSpecial = request.getHeader(RequestConstant.ACCESS_SPECIAL);
|
|
// String accessSpecial = request.getHeader(RequestConstant.ACCESS_SPECIAL);
|
|
|
- String requestUri = request.getRequestURI();
|
|
|
|
|
|
|
+ String requestUri = request.getPath().value();
|
|
|
/*1、非token校验接口放行*/
|
|
/*1、非token校验接口放行*/
|
|
|
- if (EXCLUDEPATH.contains(requestUri)) {//不校验token时,如果存在token,也设置上下文变量信息
|
|
|
|
|
- Map<String, Object> tokenMap = EncryUtil.descryV2(Global.PRI_KEY, token);
|
|
|
|
|
- if (tokenMap != null) {
|
|
|
|
|
- Long userId = StringUtils.isNotBlank(tokenMap.get("userId")) ? NumberUtils.parseLong(tokenMap.get("userId")) : null;
|
|
|
|
|
- String key = Global.getFullUserLoginKey(systemType, userId);
|
|
|
|
|
-
|
|
|
|
|
- String userInfoStr = RedissonUtils.getString(key);
|
|
|
|
|
- LoginUserInfo loginUserInfo = StringUtils.isNotBlank(userInfoStr) ? JSON.parseObject(userInfoStr, LoginUserInfo.class) : null;
|
|
|
|
|
- if (Objects.nonNull(loginUserInfo)) {
|
|
|
|
|
- loginUserInfo.setClientType(clientType);
|
|
|
|
|
- String loginEntStr = RedissonUtils.getString(Global.getFullUserEntKey(loginUserInfo.getEntId()));
|
|
|
|
|
- LoginEntInfo loginEntInfo = StringUtils.isNotBlank(loginEntStr) ? JSON.parseObject(loginEntStr, LoginEntInfo.class) : null;
|
|
|
|
|
- LoginUserHolder.set(loginUserInfo);
|
|
|
|
|
- LoginEntHolder.set(loginEntInfo);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- filterChain.doFilter(servletRequest, servletResponse);
|
|
|
|
|
- LoginUserHolder.remove();
|
|
|
|
|
- LoginEntHolder.remove();
|
|
|
|
|
- return;
|
|
|
|
|
|
|
+ if (EXCLUDEPATH.contains(requestUri)) {
|
|
|
|
|
+ return chain.filter(exchange);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 添加对Swagger相关路径的放行
|
|
// 添加对Swagger相关路径的放行
|
|
|
if (requestUri.startsWith("/swagger-ui") ||
|
|
if (requestUri.startsWith("/swagger-ui") ||
|
|
|
- requestUri.startsWith("/v3/api-docs") || requestUri.startsWith("/doc.htm") ||
|
|
|
|
|
|
|
+ requestUri.startsWith("/v3/api-docs") || requestUri.startsWith("/doc.htm")||
|
|
|
requestUri.startsWith("/webjars/")) {
|
|
requestUri.startsWith("/webjars/")) {
|
|
|
- filterChain.doFilter(servletRequest, servletResponse);
|
|
|
|
|
- return;
|
|
|
|
|
|
|
+ return chain.filter(exchange);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/*2、校验token**/
|
|
/*2、校验token**/
|
|
|
/*2.1、校验token非空*/
|
|
/*2.1、校验token非空*/
|
|
|
HttpResult result = checkBlank(token, clientType, systemType, requestUri);
|
|
HttpResult result = checkBlank(token, clientType, systemType, requestUri);
|
|
|
if (result.getCode() != HttpStatus.SUCCESS_CODE) {
|
|
if (result.getCode() != HttpStatus.SUCCESS_CODE) {
|
|
|
- ResponseUtil.writer(response, result);
|
|
|
|
|
- return;
|
|
|
|
|
|
|
+ return writeResponse(response,result.getCode(),result.getMsg());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/*2.2、token解析*/
|
|
/*2.2、token解析*/
|
|
|
Map<String, Object> tokenMap = EncryUtil.descryV2(Global.PRI_KEY, token);
|
|
Map<String, Object> tokenMap = EncryUtil.descryV2(Global.PRI_KEY, token);
|
|
|
if (tokenMap == null) {
|
|
if (tokenMap == null) {
|
|
|
- log.error("认证失效: token {}", token);
|
|
|
|
|
- ResponseUtil.writer(response, HttpResult.error(HttpStatus.TOKEN_INVALID_CODE, HttpStatus.TOKEN_INVALID_MESSAGE));
|
|
|
|
|
- return;
|
|
|
|
|
|
|
+ return writeResponse(response,HttpStatus.TOKEN_INVALID_CODE,HttpStatus.TOKEN_INVALID_MESSAGE);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/*2.3、从redis获取用户登录token*/
|
|
/*2.3、从redis获取用户登录token*/
|
|
@@ -141,15 +121,12 @@ public class RequestCheckFilter implements Filter {
|
|
|
String key = Global.getFullUserTokenKey(clientType, userId);
|
|
String key = Global.getFullUserTokenKey(clientType, userId);
|
|
|
String redisUserToken = RedissonUtils.getString(key);
|
|
String redisUserToken = RedissonUtils.getString(key);
|
|
|
if (StringUtils.isBlank(redisUserToken)) {
|
|
if (StringUtils.isBlank(redisUserToken)) {
|
|
|
- log.error("认证失效: clientType {} userId {}", clientType, userId);
|
|
|
|
|
- ResponseUtil.writer(response, HttpResult.error(HttpStatus.TOKEN_INVALID_CODE, HttpStatus.TOKEN_INVALID_MESSAGE));
|
|
|
|
|
- return;
|
|
|
|
|
|
|
+ return writeResponse(response,HttpStatus.TOKEN_INVALID_CODE,HttpStatus.TOKEN_INVALID_MESSAGE);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/*2.4、请求token和redis中token不一致,说明账号在别处登录了*/
|
|
/*2.4、请求token和redis中token不一致,说明账号在别处登录了*/
|
|
|
if (!token.equals(redisUserToken)) {
|
|
if (!token.equals(redisUserToken)) {
|
|
|
- ResponseUtil.writer(response, HttpResult.error(HttpStatus.TOKEN_INVALID_CODE, HttpStatus.ACCOUNT_OTHER_LOGIN_MESSAGE));
|
|
|
|
|
- return;
|
|
|
|
|
|
|
+ return writeResponse(response,HttpStatus.TOKEN_INVALID_CODE,HttpStatus.ACCOUNT_OTHER_LOGIN_MESSAGE);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/*3、校验登录用户信息*/
|
|
/*3、校验登录用户信息*/
|
|
@@ -157,22 +134,20 @@ public class RequestCheckFilter implements Filter {
|
|
|
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)) {
|
|
|
- log.error("认证失效,systemType {} userId {}", systemType, userId);
|
|
|
|
|
-
|
|
|
|
|
- ResponseUtil.writer(response, HttpResult.error(HttpStatus.TOKEN_INVALID_CODE, HttpStatus.TOKEN_INVALID_MESSAGE));
|
|
|
|
|
- return;
|
|
|
|
|
|
|
+ return writeResponse(response,HttpStatus.TOKEN_INVALID_CODE,HttpStatus.TOKEN_INVALID_MESSAGE);
|
|
|
}
|
|
}
|
|
|
loginUserInfo.setClientType(clientType);
|
|
loginUserInfo.setClientType(clientType);
|
|
|
|
|
|
|
|
//校验用户账号是否冻结
|
|
//校验用户账号是否冻结
|
|
|
if (loginUserInfo.getStatus() == Global.YES) {
|
|
if (loginUserInfo.getStatus() == Global.YES) {
|
|
|
- ResponseUtil.writer(response, HttpResult.error(HttpStatus.TOKEN_INVALID_CODE, "您的账号已被冻结,请联系系统管理员!"));
|
|
|
|
|
- return;
|
|
|
|
|
|
|
+ return writeResponse(response,HttpStatus.TOKEN_INVALID_CODE,"您的账号已被冻结,请联系系统管理员!");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/*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(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());
|
|
@@ -183,40 +158,35 @@ public class RequestCheckFilter implements Filter {
|
|
|
loginUserInfo.setAuthEntIdList(authUserIdList);
|
|
loginUserInfo.setAuthEntIdList(authUserIdList);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- LoginUserHolder.set(loginUserInfo);
|
|
|
|
|
- LoginEntHolder.set(loginEntInfo);
|
|
|
|
|
|
|
+ //重置缓存有效期
|
|
|
RedissonUtils.putString(Global.getFullUserTokenKey(clientType, userId), token, ClientTypeEnum.expireTime(clientType));
|
|
RedissonUtils.putString(Global.getFullUserTokenKey(clientType, userId), token, ClientTypeEnum.expireTime(clientType));
|
|
|
RedissonUtils.putString(Global.getFullUserLoginKey(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);
|
|
|
- filterChain.doFilter(servletRequest, servletResponse);
|
|
|
|
|
- LoginUserHolder.remove();
|
|
|
|
|
- return;
|
|
|
|
|
|
|
+ //将用户信息和企业信息放入header方便后续微服务获取
|
|
|
|
|
+ ServerWebExchange build = buildNewExchange(exchange,loginUserInfo,loginEntInfo);
|
|
|
|
|
+ return chain.filter(build);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- 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;
|
|
|
|
|
|
|
+ //非运营端
|
|
|
|
|
+ if ((StringUtils.isBlank(loginEntStr) || loginEntInfo == null)) {
|
|
|
|
|
+ return writeResponse(response,HttpStatus.TOKEN_INVALID_CODE,HttpStatus.UN_LOGIN_MESSAGE);
|
|
|
} else {
|
|
} else {
|
|
|
//校验用户企业是否冻结
|
|
//校验用户企业是否冻结
|
|
|
- if (Objects.isNull(loginEntInfo) || loginEntInfo.getStatus() == Global.YES) {
|
|
|
|
|
- ResponseUtil.writer(response, HttpResult.error(HttpStatus.TOKEN_INVALID_CODE, "您所属企业已被冻结,请联系系统管理员!"));
|
|
|
|
|
- return;
|
|
|
|
|
|
|
+ if (loginEntInfo.getStatus() == Global.YES) {
|
|
|
|
|
+ return writeResponse(response,HttpStatus.TOKEN_INVALID_CODE,"您所属企业已被冻结,请联系系统管理员!");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
//校验用户企业审批状态
|
|
//校验用户企业审批状态
|
|
|
if (!loginEntInfo.getValid() && !REGISTER.equals(requestUri)) {
|
|
if (!loginEntInfo.getValid() && !REGISTER.equals(requestUri)) {
|
|
|
if (loginEntInfo.getApproval() == Global.NO) {
|
|
if (loginEntInfo.getApproval() == Global.NO) {
|
|
|
- ResponseUtil.writer(response, HttpResult.error(HttpStatus.CODE_60603, HttpStatus.ENTCERTIFICATES_NOT_REGISTER));
|
|
|
|
|
- return;
|
|
|
|
|
|
|
+ return writeResponse(response,HttpStatus.CODE_60603,HttpStatus.ENTCERTIFICATES_NOT_REGISTER);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (loginEntInfo.getApproval() == Global.NUMERICAL_THREE) {
|
|
if (loginEntInfo.getApproval() == Global.NUMERICAL_THREE) {
|
|
|
- ResponseUtil.writer(response, HttpResult.error(HttpStatus.CODE_60603, HttpStatus.ENTCERTIFICATES_NOT_PASS));
|
|
|
|
|
- return;
|
|
|
|
|
|
|
+ return writeResponse(response,HttpStatus.CODE_60603,HttpStatus.ENTCERTIFICATES_NOT_PASS);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- ResponseUtil.writer(response, HttpResult.error(HttpStatus.CODE_60603, HttpStatus.ENTCERTIFICATES_INVAILD));
|
|
|
|
|
- return;
|
|
|
|
|
|
|
+ return writeResponse(response,HttpStatus.CODE_60603,HttpStatus.ENTCERTIFICATES_INVAILD);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -225,37 +195,54 @@ public class RequestCheckFilter implements Filter {
|
|
|
if (loginUserInfo.getIsMain() == Global.NO
|
|
if (loginUserInfo.getIsMain() == Global.NO
|
|
|
&& !WITHOUTPATH.contains(requestUri)
|
|
&& !WITHOUTPATH.contains(requestUri)
|
|
|
&& !checkMenu(clientType, loginUserInfo.getId(), requestUri)) {
|
|
&& !checkMenu(clientType, loginUserInfo.getId(), requestUri)) {
|
|
|
- ResponseUtil.writer(response, HttpResult.error(HttpStatus.AUTHORITY_NO_CODE, HttpStatus.ACCESS_FIAL));
|
|
|
|
|
- return;
|
|
|
|
|
|
|
+ return writeResponse(response,HttpStatus.AUTHORITY_NO_CODE,HttpStatus.ACCESS_FIAL);
|
|
|
}
|
|
}
|
|
|
- LoginUserHolder.set(loginUserInfo);
|
|
|
|
|
- LoginEntHolder.set(loginEntInfo);
|
|
|
|
|
RedissonUtils.putString(Global.getFullUserLoginKey(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, userId), token, ClientTypeEnum.expireTime(clientType));
|
|
|
- filterChain.doFilter(servletRequest, servletResponse);
|
|
|
|
|
- LoginUserHolder.remove();
|
|
|
|
|
- LoginEntHolder.remove();
|
|
|
|
|
|
|
+ //将用户信息和企业信息放入header方便后续微服务获取
|
|
|
|
|
+ ServerWebExchange build = buildNewExchange(exchange,loginUserInfo,loginEntInfo);
|
|
|
|
|
+ return chain.filter(build);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private ServerWebExchange buildNewExchange(ServerWebExchange exchange, LoginUserInfo loginUserInfo, LoginEntInfo loginEntInfo) {
|
|
|
|
|
+ SimplePropertyPreFilter filter = new SimplePropertyPreFilter("id","entTypes", "firmName","approval","status","special");
|
|
|
|
|
+ String userInfoStrEncode = URLEncoder.encode(JSON.toJSONString(loginUserInfo), StandardCharsets.UTF_8);
|
|
|
|
|
+ String entInfoStrEncode = URLEncoder.encode(JSON.toJSONString(loginEntInfo,filter), StandardCharsets.UTF_8);
|
|
|
|
|
+ ServerHttpRequest newRequest = exchange.getRequest().mutate()
|
|
|
|
|
+ .headers(h -> {
|
|
|
|
|
+ h.add(Global.USER_INFO_STR_ENCODE, userInfoStrEncode);
|
|
|
|
|
+ h.add(Global.ENT_INFO_STR_ENCODE, entInfoStrEncode);
|
|
|
|
|
+ h.remove(RequestConstant.TOKEN);
|
|
|
|
|
+ }).build();
|
|
|
|
|
+ return exchange.mutate().request(newRequest).build();
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * @param userId 用户菜单权限key url 当前请求url
|
|
|
|
|
- * @return boolean
|
|
|
|
|
- * @desc: 校验url权限
|
|
|
|
|
- * @author: czh
|
|
|
|
|
- * @date: 2023/6/28
|
|
|
|
|
|
|
+ * 构建返回内容
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param response ServerHttpResponse
|
|
|
|
|
+ * @param code 返回码
|
|
|
|
|
+ * @param msg 返回数据
|
|
|
|
|
+ * @return Mono
|
|
|
*/
|
|
*/
|
|
|
- private boolean checkMenu(String clientType, Long userId, String url) {
|
|
|
|
|
- return true;
|
|
|
|
|
- //return RedissonUtils.contains(Global.REDIS_SYS_MENU_PREFIX + clientType + Global.COLON + userId, url);
|
|
|
|
|
|
|
+ protected Mono<Void> writeResponse(ServerHttpResponse response, Integer code, String msg) {
|
|
|
|
|
+ JSONObject message = new JSONObject();
|
|
|
|
|
+ message.put("code", code);
|
|
|
|
|
+ message.put("msg", msg);
|
|
|
|
|
+ byte[] bits = message.toJSONString().getBytes(StandardCharsets.UTF_8);
|
|
|
|
|
+ DataBuffer buffer = response.bufferFactory().wrap(bits);
|
|
|
|
|
+ response.setStatusCode(org.springframework.http.HttpStatus.OK);
|
|
|
|
|
+ // 指定编码,否则在浏览器中会中文乱码
|
|
|
|
|
+ response.getHeaders().add("Content-Type", "application/json;charset=UTF-8");
|
|
|
|
|
+ return response.writeWith(Mono.just(buffer));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* @param token token
|
|
* @param token token
|
|
|
* @param clientType 客户端类型
|
|
* @param clientType 客户端类型
|
|
|
* @param systemType 系统类型
|
|
* @param systemType 系统类型
|
|
|
- * @param accessSpecial 专场标识
|
|
|
|
|
* @param requestUri 请求地址
|
|
* @param requestUri 请求地址
|
|
|
* @return 校验结果
|
|
* @return 校验结果
|
|
|
* @desc Hearder内容校验
|
|
* @desc Hearder内容校验
|
|
@@ -275,4 +262,20 @@ public class RequestCheckFilter implements Filter {
|
|
|
return HttpResult.ok();
|
|
return HttpResult.ok();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @param userId 用户菜单权限key url 当前请求url
|
|
|
|
|
+ * @return boolean
|
|
|
|
|
+ * @desc: 校验url权限
|
|
|
|
|
+ * @author: czh
|
|
|
|
|
+ * @date: 2023/6/28
|
|
|
|
|
+ */
|
|
|
|
|
+ private boolean checkMenu(String clientType, Long userId, String url) {
|
|
|
|
|
+ return true;
|
|
|
|
|
+ //return RedissonUtils.contains(Global.REDIS_SYS_MENU_PREFIX + clientType + Global.COLON + userId, url);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public int getOrder() {
|
|
|
|
|
+ return 2;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|