Browse Source

Merge remote-tracking branch 'origin/dev/one' into dev/one

wangyu 6 years ago
parent
commit
35fad62c47

+ 2 - 1
common/src/main/java/com/diagbot/exception/CommonErrorCode.java

@@ -22,7 +22,8 @@ public enum CommonErrorCode implements ErrorCode {
     SERVER_IS_ERROR("00020007", "各自业务错误!"),
     NO_PERMISSION("00020008", "无权访问!"),
     IS_EXISTS("00020009", "已存在!"),
-    ANALYZER_TOKEN_FAIL("10020010", "解析token失败");
+    ANALYZER_TOKEN_FAIL("10020010", "解析token失败"),
+    TOKEN_PAST("10020011", "token已失效,请重新登录");
 
     private String code;
     private String msg;

+ 7 - 0
gateway-service/src/main/java/com/diagbot/filter/GlobalGatewayFilter.java

@@ -5,6 +5,7 @@ import com.diagbot.client.UserServiceClient;
 import com.diagbot.dto.RespDTO;
 import com.diagbot.entity.ServiceToken;
 import com.diagbot.entity.Token;
+import com.diagbot.exception.CommonErrorCode;
 import com.diagbot.util.GsonUtil;
 import com.diagbot.util.StringUtil;
 import lombok.extern.slf4j.Slf4j;
@@ -76,11 +77,17 @@ public class GlobalGatewayFilter implements GlobalFilter {
         String tokenStr = request.getHeaders().getFirst("Authorization");
         if(StringUtil.isNotEmpty(tokenStr)) {
             Token token = new Token();
+            tokenStr = tokenStr.replaceFirst("Bearer ", "");
             token.setToken(tokenStr);
             RespDTO<Boolean> res = userServiceClient.verifyToken(token);
             if (res == null || !RespDTO.TRUE_CODE.equals(res.code)) {
                 return getVoidMono(serverWebExchange, res);
             }
+            if(!res.data) {
+                res.code = CommonErrorCode.TOKEN_PAST.getCode();
+                res.msg = CommonErrorCode.TOKEN_PAST.getMsg();
+                return getVoidMono(serverWebExchange, res);
+            }
         }
 
         //        if(!IS_GENERATE) {

+ 1 - 2
user-service/src/main/java/com/diagbot/facade/UserFacade.java

@@ -418,8 +418,7 @@ public class UserFacade extends UserServiceImpl {
 
         //验证刷新令牌有效性
         if (!tokenFacade.verifyToken(refreshToken, 2)) {
-            throw new CommonException(CommonErrorCode.PARAM_IS_ERROR,
-                    "不是被允许的刷新令牌");
+            throw new CommonException(CommonErrorCode.TOKEN_PAST);
         }
 
         JWT jwt = authServiceClient.refreshToken("Basic dWFhLXNlcnZpY2U6MTIzNDU2", "refresh_token", refreshToken);