|
@@ -1,5 +1,22 @@
|
|
package cn.org.spring.wechar.interceptor;
|
|
package cn.org.spring.wechar.interceptor;
|
|
|
|
|
|
|
|
+import cn.org.spring.wechar.bean.Result;
|
|
|
|
+import cn.org.spring.wechar.config.BasicInfo;
|
|
|
|
+import cn.org.spring.wechar.utils.CacheUtil;
|
|
|
|
+import cn.org.spring.wechar.utils.CookieUtils;
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
|
+import lombok.Data;
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.boot.context.properties.ConfigurationProperties;
|
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
|
+import org.springframework.util.AntPathMatcher;
|
|
|
|
+import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
|
|
|
|
+
|
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
|
+import java.io.PrintWriter;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* @author: 谢辉
|
|
* @author: 谢辉
|
|
* @date: 2021/5/10
|
|
* @date: 2021/5/10
|
|
@@ -8,9 +25,11 @@ package cn.org.spring.wechar.interceptor;
|
|
* @modifiedBy:
|
|
* @modifiedBy:
|
|
* @version: 1.0
|
|
* @version: 1.0
|
|
*/
|
|
*/
|
|
-/*
|
|
|
|
|
|
+
|
|
@Slf4j
|
|
@Slf4j
|
|
|
|
+@Data
|
|
@Component
|
|
@Component
|
|
|
|
+@ConfigurationProperties(prefix = "login-interceptor")
|
|
public class LoginUserInterceptor extends HandlerInterceptorAdapter {
|
|
public class LoginUserInterceptor extends HandlerInterceptorAdapter {
|
|
@Autowired
|
|
@Autowired
|
|
CacheUtil cacheUtil;
|
|
CacheUtil cacheUtil;
|
|
@@ -18,8 +37,28 @@ public class LoginUserInterceptor extends HandlerInterceptorAdapter {
|
|
@Autowired
|
|
@Autowired
|
|
BasicInfo basicInfo;
|
|
BasicInfo basicInfo;
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ AntPathMatcher antPathMatcher;
|
|
|
|
+
|
|
|
|
+ private String excludePatterns = "";
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
|
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
|
|
|
+ String uri = request.getRequestURI();
|
|
|
|
+
|
|
|
|
+ System.out.println("request.getRequestURI():" + uri);
|
|
|
|
+ System.out.println("不拦截路径信息:" + excludePatterns);
|
|
|
|
+
|
|
|
|
+ String[] split = excludePatterns.split(",");
|
|
|
|
+ for (String s : split) {
|
|
|
|
+ boolean match = antPathMatcher.match(s, uri);
|
|
|
|
+ if (match) {
|
|
|
|
+ log.info("匹配到不拦截的路径:【{}】", s);
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
String cookieValue = CookieUtils.getCookieValue(request, "wechat-token");
|
|
String cookieValue = CookieUtils.getCookieValue(request, "wechat-token");
|
|
Object o = cacheUtil.get("wechatuser:" + cookieValue);
|
|
Object o = cacheUtil.get("wechatuser:" + cookieValue);
|
|
log.info("LoginUserInterceptor拦截器从redis获取信息【{}】", String.valueOf(o));
|
|
log.info("LoginUserInterceptor拦截器从redis获取信息【{}】", String.valueOf(o));
|
|
@@ -49,5 +88,5 @@ public class LoginUserInterceptor extends HandlerInterceptorAdapter {
|
|
public static boolean isAjax(HttpServletRequest request) {
|
|
public static boolean isAjax(HttpServletRequest request) {
|
|
return "XMLHttpRequest".equals(request.getHeader("X-Requested-With"));
|
|
return "XMLHttpRequest".equals(request.getHeader("X-Requested-With"));
|
|
}
|
|
}
|
|
-}*/
|
|
|
|
|
|
+}
|
|
|
|
|