lighter 2 years ago
parent
commit
3a3f0c6338

+ 3 - 27
src/main/java/thyyxxk/webserver/config/auth/AuthenticationInterceptor.java

@@ -1,27 +1,19 @@
 package thyyxxk.webserver.config.auth;
 
-import com.alibaba.fastjson.JSONObject;
 import com.auth0.jwt.JWT;
 import com.auth0.jwt.JWTVerifier;
 import com.auth0.jwt.algorithms.Algorithm;
 import com.auth0.jwt.exceptions.JWTDecodeException;
 import com.auth0.jwt.exceptions.JWTVerificationException;
 import lombok.extern.slf4j.Slf4j;
-import org.apache.catalina.User;
 import org.springframework.stereotype.Component;
 import org.springframework.web.method.HandlerMethod;
 import org.springframework.web.servlet.HandlerInterceptor;
 import thyyxxk.webserver.config.exception.BizException;
 import thyyxxk.webserver.config.exception.ExceptionEnum;
-import thyyxxk.webserver.constants.Message;
 import thyyxxk.webserver.controller.ShutDownController;
 import thyyxxk.webserver.entity.login.UserInfo;
-import thyyxxk.webserver.entity.socketmessage.ApiMessageBody;
-import thyyxxk.webserver.service.LoginService;
-import thyyxxk.webserver.service.TokenService;
-import thyyxxk.webserver.service.externalhttp.WebSocketService;
 import thyyxxk.webserver.service.redislike.RedisLikeService;
-import thyyxxk.webserver.utils.SocketMsg;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
@@ -33,17 +25,11 @@ import java.lang.reflect.Method;
 @Slf4j
 @Component
 public class AuthenticationInterceptor implements HandlerInterceptor {
-    private final TokenService tokenService;
-    private final WebSocketService socketService;
     private final RedisLikeService redisLikeService;
 
     private static final String EXPIRED = "The Token has expired";
 
-    public AuthenticationInterceptor(TokenService tokenService,
-                                     WebSocketService socketService,
-                                     RedisLikeService redisLikeService) {
-        this.tokenService = tokenService;
-        this.socketService = socketService;
+    public AuthenticationInterceptor(RedisLikeService redisLikeService) {
         this.redisLikeService = redisLikeService;
     }
 
@@ -100,19 +86,9 @@ public class AuthenticationInterceptor implements HandlerInterceptor {
             jwtVerifier.verify(token);
         } catch (JWTVerificationException e) {
             if (e.getMessage().contains(EXPIRED)) {
-                if (code.equals("01897") || code.equals("02896")) {
-                    log.warn("【{}-{}】令牌已过期,自动刷新令牌。", userInfo.getCode(), userInfo.getName());
-                    token = tokenService.getToken(userInfo);
-                    JSONObject message = new JSONObject();
-                    message.put("token", token);
-                    String msg = SocketMsg.socketVo(Message.REFRESH_TOKEN, message);
-                    ApiMessageBody messageBody = new ApiMessageBody(userInfo.getCode(), msg);
-                    socketService.sendMessageByUserCode(messageBody);
-                } else {
-                    throw new BizException(ExceptionEnum.TOKEN_EXPIRED);
-                }
+                throw new BizException(ExceptionEnum.TOKEN_EXPIRED);
             } else {
-                log.error("验证令牌出错!");
+                log.error("验证令牌出错!", e);
                 throw new BizException(ExceptionEnum.TOKEN_ERROR);
             }
         }

+ 2 - 9
src/main/java/thyyxxk/webserver/config/auth/InterceptorConfig.java

@@ -4,9 +4,6 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
 import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
-import thyyxxk.webserver.service.LoginService;
-import thyyxxk.webserver.service.TokenService;
-import thyyxxk.webserver.service.externalhttp.WebSocketService;
 import thyyxxk.webserver.service.redislike.RedisLikeService;
 
 /**
@@ -14,20 +11,16 @@ import thyyxxk.webserver.service.redislike.RedisLikeService;
  */
 @Configuration
 public class InterceptorConfig implements WebMvcConfigurer {
-    private final TokenService tokenService;
-    private final WebSocketService socketService;
     private final RedisLikeService redisLikeService;
 
     @Autowired
-    public InterceptorConfig(TokenService tokenService, WebSocketService socketService, RedisLikeService redisLikeService) {
-        this.tokenService = tokenService;
-        this.socketService = socketService;
+    public InterceptorConfig(RedisLikeService redisLikeService) {
         this.redisLikeService = redisLikeService;
     }
 
     @Override
     public void addInterceptors(InterceptorRegistry registry) {
-        registry.addInterceptor(new AuthenticationInterceptor(tokenService, socketService, redisLikeService))
+        registry.addInterceptor(new AuthenticationInterceptor(redisLikeService))
                 .addPathPatterns("/**");
     }
 }

+ 0 - 1
src/main/java/thyyxxk/webserver/scheduled/FetchAccessTokenTask.java

@@ -77,5 +77,4 @@ public class FetchAccessTokenTask {
         }
     }
 
-
 }

+ 0 - 1
src/main/java/thyyxxk/webserver/service/externalhttp/OutpatientBookingHttp.java

@@ -3,7 +3,6 @@ package thyyxxk.webserver.service.externalhttp;
 import com.alibaba.fastjson.JSONObject;
 import com.dtflys.forest.annotation.*;
 
-
 //@BaseRequest(baseURL = "http://172.16.30.33:8089/thmz")
 @BaseRequest(baseURL = "http://webhis.thyy.cn:81/thmz")
 public interface OutpatientBookingHttp {