|
@@ -1,72 +0,0 @@
|
|
|
-package com.sckw.core.interceptor;
|
|
|
|
|
-
|
|
|
|
|
-import com.sckw.core.exception.SystemException;
|
|
|
|
|
-import com.sckw.core.model.constant.Global;
|
|
|
|
|
-import com.sckw.core.utils.EncryUtil;
|
|
|
|
|
-import com.sckw.core.utils.StringUtils;
|
|
|
|
|
-import com.sckw.core.web.constant.HttpStatus;
|
|
|
|
|
-import com.sckw.core.web.constant.RequestConstant;
|
|
|
|
|
-import com.sckw.redis.utils.RedissonUtils;
|
|
|
|
|
-import jakarta.annotation.Resource;
|
|
|
|
|
-import jakarta.servlet.http.HttpServletRequest;
|
|
|
|
|
-import jakarta.servlet.http.HttpServletResponse;
|
|
|
|
|
-import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
-import org.springframework.web.method.HandlerMethod;
|
|
|
|
|
-import org.springframework.web.servlet.HandlerInterceptor;
|
|
|
|
|
-
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
|
|
-import java.util.List;
|
|
|
|
|
-import java.util.Objects;
|
|
|
|
|
-
|
|
|
|
|
-/**
|
|
|
|
|
- * @author czh
|
|
|
|
|
- * @desc 拦截器
|
|
|
|
|
- * @date 2023/6/12
|
|
|
|
|
- */
|
|
|
|
|
-@Slf4j
|
|
|
|
|
-public class LoginInterceptor implements HandlerInterceptor {
|
|
|
|
|
-
|
|
|
|
|
- private static final List<String> excludePath = new ArrayList<>();
|
|
|
|
|
-
|
|
|
|
|
- static {
|
|
|
|
|
- excludePath.add("/auth/login");
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- @Resource
|
|
|
|
|
- private RedissonUtils redissonUtils;
|
|
|
|
|
-
|
|
|
|
|
- @Override
|
|
|
|
|
- public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
|
|
|
|
|
-
|
|
|
|
|
- //1、定义不拦截的接口
|
|
|
|
|
- log.info("==============>getRequestURI:{} ", request.getRequestURI());
|
|
|
|
|
- if (excludePath.contains(request.getRequestURI())) {
|
|
|
|
|
- return true;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
-// if(handler instanceof HandlerMethod){
|
|
|
|
|
-// return true;
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
- //2、非登录接口,校验token是否过期
|
|
|
|
|
- String token = request.getHeader(RequestConstant.TOKEN);
|
|
|
|
|
- if (StringUtils.isBlank(token)) {
|
|
|
|
|
- throw new SystemException(HttpStatus.PARAMETERS_MISSING_CODE, HttpStatus.TOKEN_MISSING);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- String key = null;
|
|
|
|
|
- try {
|
|
|
|
|
- key = EncryUtil.descry(Global.PRI_KEY, token);
|
|
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- throw new SystemException(HttpStatus.PARAMETERS_MISSING_CODE, HttpStatus.TOKEN_ERROR);
|
|
|
|
|
- }
|
|
|
|
|
- Object object = redissonUtils.get(key);
|
|
|
|
|
- if (Objects.isNull(object)) {
|
|
|
|
|
- throw new SystemException(HttpStatus.PARAMETERS_MISSING_CODE, HttpStatus.TOKEN_INVAILD);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- return true;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-}
|
|
|