diff --git a/epmet-commons/epmet-common-clienttoken/src/main/java/com/epmet/common/token/enums/ErrorCode.java b/epmet-commons/epmet-common-clienttoken/src/main/java/com/epmet/common/token/enums/ErrorCode.java index 2f9cdd1376..9296333cac 100644 --- a/epmet-commons/epmet-common-clienttoken/src/main/java/com/epmet/common/token/enums/ErrorCode.java +++ b/epmet-commons/epmet-common-clienttoken/src/main/java/com/epmet/common/token/enums/ErrorCode.java @@ -18,9 +18,13 @@ public enum ErrorCode implements IErrorCode { ERR10003(10003, "token生成失败,请重试。"), ERR10004(10004, "返回的Object类型不是EsuaResponse,无法添加token!"), ERR10005(10005, "token不能为空"), + ERR10006(10006, "登录超时,请重新登录"), + ERR10007(10007, "当前帐号已在别处登录"), ERR500(500, "Internal Server Error"), ERR501(501, "参数绑定异常"), + ERR401(401, "未授权"), + ERR(ErrorCode.COMMON_ERR_CODE, "其他异常"); diff --git a/epmet-gateway/src/main/java/com/epmet/filter/CpAuthGatewayFilterFactory.java b/epmet-gateway/src/main/java/com/epmet/filter/CpAuthGatewayFilterFactory.java index 02705c0e89..7e02a517ee 100644 --- a/epmet-gateway/src/main/java/com/epmet/filter/CpAuthGatewayFilterFactory.java +++ b/epmet-gateway/src/main/java/com/epmet/filter/CpAuthGatewayFilterFactory.java @@ -2,11 +2,12 @@ package com.epmet.filter; import com.alibaba.fastjson.JSON; +import com.epmet.common.token.enums.ErrorCode; import com.epmet.commons.tools.constant.Constant; -import com.epmet.commons.tools.exception.ErrorCode; import com.epmet.commons.tools.exception.RenException; import com.epmet.commons.tools.security.dto.TokenDto; import com.epmet.commons.tools.utils.CpUserDetailRedis; +import com.epmet.commons.tools.utils.Result; import com.epmet.jwt.JwtTokenUtils; import io.jsonwebtoken.Claims; import org.apache.commons.lang3.StringUtils; @@ -68,7 +69,7 @@ public class CpAuthGatewayFilterFactory extends AbstractGatewayFilterFactory().error(ErrorCode.ERR10005.getCode(),ErrorCode.ERR10005.getMsg())); } - TokenDto user = this.getLoginUserInfo(token); - //当前登录用户userId,添加到header中 - if (user != null) { - String redisKey = user.getApp() + "-" + user.getClient() + "-" + user.getUserId(); - logger.info("redisKey=" + redisKey); - ServerHttpRequest build = exchange.getRequest().mutate().header(Constant.APP_USER_KEY, redisKey).build(); - return chain.filter(exchange.mutate().request(build).build()); + try { + //当前登录用户userId,添加到header中 + TokenDto user = this.getLoginUserInfo(token); + if (user != null) { + String redisKey = user.getApp() + "-" + user.getClient() + "-" + user.getUserId(); + logger.info("redisKey=" + redisKey); + ServerHttpRequest build = exchange.getRequest().mutate().header(Constant.APP_USER_KEY, redisKey).build(); + return chain.filter(exchange.mutate().request(build).build()); + } + }catch(RenException e){ + return response(exchange,new Result<>().error(e.getCode(),e.getMsg())); } + return chain.filter(exchange); }; } @@ -103,7 +111,7 @@ public class CpAuthGatewayFilterFactory extends AbstractGatewayFilterFactory