From e8e3f9f2b194a7f8847182a7682b4414cb7909c2 Mon Sep 17 00:00:00 2001 From: yexuejc <940526mf> Date: Sat, 25 Aug 2018 16:52:18 +0800 Subject: [PATCH] =?UTF-8?q?1.0.14=20=E4=BC=98=E5=8C=96=E6=8B=A6=E6=88=AA?= =?UTF-8?q?=E8=A7=84=E5=88=99=EF=BC=9A=E5=A2=9E=E5=8A=A0=E9=80=9A=E9=85=8D?= =?UTF-8?q?=E7=AC=A6=20/**?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- UPDATE.md | 1 + .../base/filter/ValidationFilter.java | 21 +++++++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/UPDATE.md b/UPDATE.md index 01d014a..3650dc2 100644 --- a/UPDATE.md +++ b/UPDATE.md @@ -11,6 +11,7 @@ spring-boot-starter-parent:1.5.15.RELEASE ``` **update:**
1. 升级依赖 +2. 优化拦截规则:增加通配符 /** # #### version :1.0.13 diff --git a/yexuejc-springboot-base/src/main/java/com/yexuejc/springboot/base/filter/ValidationFilter.java b/yexuejc-springboot-base/src/main/java/com/yexuejc/springboot/base/filter/ValidationFilter.java index 6080f1c..2e6fed2 100644 --- a/yexuejc-springboot-base/src/main/java/com/yexuejc/springboot/base/filter/ValidationFilter.java +++ b/yexuejc-springboot-base/src/main/java/com/yexuejc/springboot/base/filter/ValidationFilter.java @@ -12,6 +12,7 @@ import javax.servlet.*; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; +import java.util.concurrent.atomic.AtomicBoolean; /** * 过滤器配置 @@ -62,12 +63,28 @@ public class ValidationFilter implements Filter { HttpServletResponse response = (HttpServletResponse) servletResponse; String sp = request.getServletPath(); if (properties.getType() == 0) { - if (properties.getIgnored().contains(sp)) { + AtomicBoolean b = new AtomicBoolean(false); + properties.getIgnored().forEach(it -> { + if (it.endsWith("/**") && sp.indexOf(it.substring(0, it.length() - 3)) > -1) { + b.set(true); + return; + } + }); + if (b.get() || properties.getIgnored().contains(sp)) { + //不拦截 filterChain.doFilter(servletRequest, servletResponse); return; } } else { - if (!properties.getIntercepts().contains(sp)) { + AtomicBoolean b = new AtomicBoolean(true); + properties.getIntercepts().forEach(it -> { + if (it.endsWith("/**") && sp.indexOf(it.substring(0, it.length() - 3)) > -1) { + b.set(false); + return; + } + }); + if (b.get() || !properties.getIntercepts().contains(sp)) { + //不拦截 filterChain.doFilter(servletRequest, servletResponse); return; }