|
@@ -1,6 +1,7 @@
|
|
|
package com.sckw.core.filter;
|
|
package com.sckw.core.filter;
|
|
|
|
|
|
|
|
import com.sckw.core.exception.SystemException;
|
|
import com.sckw.core.exception.SystemException;
|
|
|
|
|
+import com.sckw.core.model.constant.CacheGroup;
|
|
|
import com.sckw.core.model.constant.Global;
|
|
import com.sckw.core.model.constant.Global;
|
|
|
import com.sckw.core.utils.EncryUtil;
|
|
import com.sckw.core.utils.EncryUtil;
|
|
|
import com.sckw.core.utils.StringUtils;
|
|
import com.sckw.core.utils.StringUtils;
|
|
@@ -12,13 +13,24 @@ import jakarta.servlet.*;
|
|
|
import jakarta.servlet.annotation.WebFilter;
|
|
import jakarta.servlet.annotation.WebFilter;
|
|
|
import jakarta.servlet.http.HttpServletRequest;
|
|
import jakarta.servlet.http.HttpServletRequest;
|
|
|
import lombok.Data;
|
|
import lombok.Data;
|
|
|
|
|
+import org.springframework.core.annotation.Order;
|
|
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
|
+import java.util.List;
|
|
|
import java.util.Objects;
|
|
import java.util.Objects;
|
|
|
|
|
|
|
|
-@WebFilter(urlPatterns = "/*")
|
|
|
|
|
|
|
+@Order(1)
|
|
|
|
|
+@Component
|
|
|
public class LoginFilter implements Filter {
|
|
public class LoginFilter implements Filter {
|
|
|
|
|
|
|
|
|
|
+ private static final List<String> excludePath = new ArrayList<>();
|
|
|
|
|
+
|
|
|
|
|
+ static {
|
|
|
|
|
+ excludePath.add("/auth/login");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
@Resource
|
|
@Resource
|
|
|
private RedissonUtils redissonUtils;
|
|
private RedissonUtils redissonUtils;
|
|
|
|
|
|
|
@@ -27,7 +39,7 @@ public class LoginFilter implements Filter {
|
|
|
//将形参servletRequest强制转换为HttpServletRequest类型,以便获取请求的URL地址和请求头
|
|
//将形参servletRequest强制转换为HttpServletRequest类型,以便获取请求的URL地址和请求头
|
|
|
HttpServletRequest request = (HttpServletRequest) servletRequest;
|
|
HttpServletRequest request = (HttpServletRequest) servletRequest;
|
|
|
String requestURI = request.getRequestURI();
|
|
String requestURI = request.getRequestURI();
|
|
|
- if (requestURI.contains("/auth/login")) {
|
|
|
|
|
|
|
+ if (excludePath.contains(requestURI)) {
|
|
|
// 如果是登录请求直接放行
|
|
// 如果是登录请求直接放行
|
|
|
filterChain.doFilter(servletRequest, servletResponse);
|
|
filterChain.doFilter(servletRequest, servletResponse);
|
|
|
return;
|
|
return;
|
|
@@ -44,10 +56,11 @@ public class LoginFilter implements Filter {
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
throw new SystemException(HttpStatus.PARAMETERS_MISSING_CODE, HttpStatus.TOKEN_ERROR);
|
|
throw new SystemException(HttpStatus.PARAMETERS_MISSING_CODE, HttpStatus.TOKEN_ERROR);
|
|
|
}
|
|
}
|
|
|
- Object object = redissonUtils.get(key);
|
|
|
|
|
|
|
+ Object object = redissonUtils.get(CacheGroup.LOGININFO + key);
|
|
|
if (Objects.isNull(object)) {
|
|
if (Objects.isNull(object)) {
|
|
|
throw new SystemException(HttpStatus.PARAMETERS_MISSING_CODE, HttpStatus.TOKEN_INVAILD);
|
|
throw new SystemException(HttpStatus.PARAMETERS_MISSING_CODE, HttpStatus.TOKEN_INVAILD);
|
|
|
}
|
|
}
|
|
|
filterChain.doFilter(servletRequest, servletResponse);
|
|
filterChain.doFilter(servletRequest, servletResponse);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
}
|
|
}
|