From d54af3699961146c25622c4f919354c3f254927e Mon Sep 17 00:00:00 2001
From: click33 <2393584716@qq.com>
Date: Sat, 29 Apr 2023 22:10:14 +0800
Subject: [PATCH] =?UTF-8?q?=E5=B0=86=E5=85=A8=E5=B1=80=E8=BF=87=E6=BB=A4?=
=?UTF-8?q?=E5=99=A8=E7=9A=84=20BeforeAuth=20=E8=AE=A4=E8=AF=81=E8=AE=BE?=
=?UTF-8?q?=E4=B8=BA=E4=B8=8D=E5=8F=97=20includeList=20=E4=B8=8E=20exclude?=
=?UTF-8?q?List=20=E7=9A=84=E9=99=90=E5=88=B6=EF=BC=8C=E6=89=80=E6=9C=89?=
=?UTF-8?q?=E8=AF=B7=E6=B1=82=E9=83=BD=E4=BC=9A=E8=BF=9B=E5=85=A5?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../main/java/com/pj/satoken/SaTokenConfigure.java | 2 +-
sa-token-demo/sa-token-demo-solon/pom.xml | 2 +-
.../main/java/com/pj/satoken/SaTokenConfigure.java | 2 +-
.../main/java/com/pj/satoken/SaTokenConfigure.java | 13 ++++++-------
.../main/java/com/pj/satoken/SaTokenConfigure.java | 2 +-
.../main/java/com/pj/satoken/SaTokenConfigure.java | 4 ++--
.../main/java/com/pj/satoken/SaTokenConfigure.java | 2 +-
sa-token-doc/up/global-filter.md | 2 +-
.../cn/dev33/satoken/jboot/SaTokenPathFilter.java | 2 +-
.../cn/dev33/satoken/jfinal/SaTokenPathFilter.java | 2 +-
.../satoken/reactor/filter/SaReactorFilter.java | 4 ++--
.../satoken/reactor/filter/SaReactorFilter.java | 4 ++--
.../satoken/solon/integration/SaTokenFilter.java | 8 ++++----
.../cn/dev33/satoken/filter/SaServletFilter.java | 4 ++--
.../cn/dev33/satoken/filter/SaServletFilter.java | 4 ++--
15 files changed, 28 insertions(+), 29 deletions(-)
diff --git a/sa-token-demo/sa-token-demo-case/src/main/java/com/pj/satoken/SaTokenConfigure.java b/sa-token-demo/sa-token-demo-case/src/main/java/com/pj/satoken/SaTokenConfigure.java
index 9ef97a41..7f41b5fb 100644
--- a/sa-token-demo/sa-token-demo-case/src/main/java/com/pj/satoken/SaTokenConfigure.java
+++ b/sa-token-demo/sa-token-demo-case/src/main/java/com/pj/satoken/SaTokenConfigure.java
@@ -94,7 +94,7 @@ public class SaTokenConfigure implements WebMvcConfigurer {
return SaResult.error(e.getMessage());
})
- // 前置函数:在每次认证函数之前执行
+ // 前置函数:在每次认证函数之前执行(BeforeAuth 不受 includeList 与 excludeList 的限制,所有请求都会进入)
.setBeforeAuth(r -> {
// ---------- 设置一些安全响应头 ----------
SaHolder.getResponse()
diff --git a/sa-token-demo/sa-token-demo-solon/pom.xml b/sa-token-demo/sa-token-demo-solon/pom.xml
index b2f65adf..87289c56 100644
--- a/sa-token-demo/sa-token-demo-solon/pom.xml
+++ b/sa-token-demo/sa-token-demo-solon/pom.xml
@@ -13,7 +13,7 @@
2.2.3
-
+
1.34.0
diff --git a/sa-token-demo/sa-token-demo-solon/src/main/java/com/pj/satoken/SaTokenConfigure.java b/sa-token-demo/sa-token-demo-solon/src/main/java/com/pj/satoken/SaTokenConfigure.java
index 72a3c559..567489d5 100644
--- a/sa-token-demo/sa-token-demo-solon/src/main/java/com/pj/satoken/SaTokenConfigure.java
+++ b/sa-token-demo/sa-token-demo-solon/src/main/java/com/pj/satoken/SaTokenConfigure.java
@@ -42,7 +42,7 @@ public class SaTokenConfigure {
return AjaxJson.getError(e.getMessage());
})
- // 前置函数:在每次认证函数之前执行
+ // 前置函数:在每次认证函数之前执行(BeforeAuth 不受 includeList 与 excludeList 的限制,所有请求都会进入)
.setBeforeAuth(r -> {
// ---------- 设置一些安全响应头 ----------
SaHolder.getResponse()
diff --git a/sa-token-demo/sa-token-demo-springboot-redis/src/main/java/com/pj/satoken/SaTokenConfigure.java b/sa-token-demo/sa-token-demo-springboot-redis/src/main/java/com/pj/satoken/SaTokenConfigure.java
index a4a4995e..71e7aca7 100644
--- a/sa-token-demo/sa-token-demo-springboot-redis/src/main/java/com/pj/satoken/SaTokenConfigure.java
+++ b/sa-token-demo/sa-token-demo-springboot-redis/src/main/java/com/pj/satoken/SaTokenConfigure.java
@@ -1,14 +1,13 @@
package com.pj.satoken;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
-import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
-
import cn.dev33.satoken.context.SaHolder;
import cn.dev33.satoken.filter.SaServletFilter;
import cn.dev33.satoken.interceptor.SaInterceptor;
import cn.dev33.satoken.util.SaResult;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
/**
@@ -40,7 +39,7 @@ public class SaTokenConfigure implements WebMvcConfigurer {
// 认证函数: 每次请求执行
.setAuth(obj -> {
- // System.out.println("---------- sa全局认证 " + SaHolder.getRequest().getRequestPath());
+ // SaManager.getLog().debug("----- 请求path={} 提交token={}", SaHolder.getRequest().getRequestPath(), StpUtil.getTokenValue());
})
@@ -50,7 +49,7 @@ public class SaTokenConfigure implements WebMvcConfigurer {
return SaResult.error(e.getMessage());
})
- // 前置函数:在每次认证函数之前执行
+ // 前置函数:在每次认证函数之前执行 (BeforeAuth不受 includeList 与 excludeList 的限制,所有请求都会进入)
.setBeforeAuth(r -> {
// ---------- 设置一些安全响应头 ----------
SaHolder.getResponse()
diff --git a/sa-token-demo/sa-token-demo-springboot-redisson/src/main/java/com/pj/satoken/SaTokenConfigure.java b/sa-token-demo/sa-token-demo-springboot-redisson/src/main/java/com/pj/satoken/SaTokenConfigure.java
index a4a4995e..9de045f8 100644
--- a/sa-token-demo/sa-token-demo-springboot-redisson/src/main/java/com/pj/satoken/SaTokenConfigure.java
+++ b/sa-token-demo/sa-token-demo-springboot-redisson/src/main/java/com/pj/satoken/SaTokenConfigure.java
@@ -50,7 +50,7 @@ public class SaTokenConfigure implements WebMvcConfigurer {
return SaResult.error(e.getMessage());
})
- // 前置函数:在每次认证函数之前执行
+ // 前置函数:在每次认证函数之前执行(BeforeAuth 不受 includeList 与 excludeList 的限制,所有请求都会进入)
.setBeforeAuth(r -> {
// ---------- 设置一些安全响应头 ----------
SaHolder.getResponse()
diff --git a/sa-token-demo/sa-token-demo-springboot/src/main/java/com/pj/satoken/SaTokenConfigure.java b/sa-token-demo/sa-token-demo-springboot/src/main/java/com/pj/satoken/SaTokenConfigure.java
index 30149e15..9d628520 100644
--- a/sa-token-demo/sa-token-demo-springboot/src/main/java/com/pj/satoken/SaTokenConfigure.java
+++ b/sa-token-demo/sa-token-demo-springboot/src/main/java/com/pj/satoken/SaTokenConfigure.java
@@ -41,7 +41,7 @@ public class SaTokenConfigure implements WebMvcConfigurer {
// 认证函数: 每次请求执行
.setAuth(obj -> {
- // System.out.println("---------- sa全局认证 " + SaHolder.getRequest().getRequestPath());
+ // SaManager.getLog().debug("----- 请求path={} 提交token={}", SaHolder.getRequest().getRequestPath(), StpUtil.getTokenValue());
})
@@ -51,7 +51,7 @@ public class SaTokenConfigure implements WebMvcConfigurer {
return AjaxJson.getError(e.getMessage());
})
- // 前置函数:在每次认证函数之前执行
+ // 前置函数:在每次认证函数之前执行(BeforeAuth 不受 includeList 与 excludeList 的限制,所有请求都会进入)
.setBeforeAuth(r -> {
// ---------- 设置一些安全响应头 ----------
SaHolder.getResponse()
diff --git a/sa-token-demo/sa-token-demo-springboot3-redis/src/main/java/com/pj/satoken/SaTokenConfigure.java b/sa-token-demo/sa-token-demo-springboot3-redis/src/main/java/com/pj/satoken/SaTokenConfigure.java
index 07736e4e..c4cacc6e 100644
--- a/sa-token-demo/sa-token-demo-springboot3-redis/src/main/java/com/pj/satoken/SaTokenConfigure.java
+++ b/sa-token-demo/sa-token-demo-springboot3-redis/src/main/java/com/pj/satoken/SaTokenConfigure.java
@@ -51,7 +51,7 @@ public class SaTokenConfigure implements WebMvcConfigurer {
return SaResult.error(e.getMessage());
})
- // 前置函数:在每次认证函数之前执行
+ // 前置函数:在每次认证函数之前执行(BeforeAuth 不受 includeList 与 excludeList 的限制,所有请求都会进入)
.setBeforeAuth(r -> {
// ---------- 设置一些安全响应头 ----------
SaHolder.getResponse()
diff --git a/sa-token-doc/up/global-filter.md b/sa-token-doc/up/global-filter.md
index d305f2bf..fe2f5a32 100644
--- a/sa-token-doc/up/global-filter.md
+++ b/sa-token-doc/up/global-filter.md
@@ -53,7 +53,7 @@ public class SaTokenConfigure {
return SaResult.error(e.getMessage());
})
- // 前置函数:在每次认证函数之前执行
+ // 前置函数:在每次认证函数之前执行(BeforeAuth 不受 includeList 与 excludeList 的限制,所有请求都会进入)
.setBeforeAuth(r -> {
// ---------- 设置一些安全响应头 ----------
SaHolder.getResponse()
diff --git a/sa-token-starter/sa-token-jboot-plugin/src/main/java/cn/dev33/satoken/jboot/SaTokenPathFilter.java b/sa-token-starter/sa-token-jboot-plugin/src/main/java/cn/dev33/satoken/jboot/SaTokenPathFilter.java
index c8de6c95..e20c03fd 100644
--- a/sa-token-starter/sa-token-jboot-plugin/src/main/java/cn/dev33/satoken/jboot/SaTokenPathFilter.java
+++ b/sa-token-starter/sa-token-jboot-plugin/src/main/java/cn/dev33/satoken/jboot/SaTokenPathFilter.java
@@ -91,8 +91,8 @@ public class SaTokenPathFilter implements SaFilter {
public void doFilter(Controller ctx, FilterChain chain) throws Throwable {
try {
// 执行全局过滤器
+ beforeAuth.run(null);
SaRouter.match(includeList).notMatch(excludeList).check(r -> {
- beforeAuth.run(null);
auth.run(null);
});
diff --git a/sa-token-starter/sa-token-jfinal-plugin/src/main/java/cn/dev33/satoken/jfinal/SaTokenPathFilter.java b/sa-token-starter/sa-token-jfinal-plugin/src/main/java/cn/dev33/satoken/jfinal/SaTokenPathFilter.java
index 2444422e..078164a4 100644
--- a/sa-token-starter/sa-token-jfinal-plugin/src/main/java/cn/dev33/satoken/jfinal/SaTokenPathFilter.java
+++ b/sa-token-starter/sa-token-jfinal-plugin/src/main/java/cn/dev33/satoken/jfinal/SaTokenPathFilter.java
@@ -91,8 +91,8 @@ public class SaTokenPathFilter implements SaFilter {
public void doFilter(Controller ctx, FilterChain chain) throws Throwable {
try {
// 执行全局过滤器
+ beforeAuth.run(null);
SaRouter.match(includeList).notMatch(excludeList).check(r -> {
- beforeAuth.run(null);
auth.run(null);
});
diff --git a/sa-token-starter/sa-token-reactor-spring-boot-starter/src/main/java/cn/dev33/satoken/reactor/filter/SaReactorFilter.java b/sa-token-starter/sa-token-reactor-spring-boot-starter/src/main/java/cn/dev33/satoken/reactor/filter/SaReactorFilter.java
index f48d150d..b9ec70e5 100644
--- a/sa-token-starter/sa-token-reactor-spring-boot-starter/src/main/java/cn/dev33/satoken/reactor/filter/SaReactorFilter.java
+++ b/sa-token-starter/sa-token-reactor-spring-boot-starter/src/main/java/cn/dev33/satoken/reactor/filter/SaReactorFilter.java
@@ -119,9 +119,9 @@ public class SaReactorFilter implements SaFilter, WebFilter {
// 写入全局上下文 (同步)
SaReactorSyncHolder.setContext(exchange);
- // 执行全局过滤器
+ // 执行全局过滤器
+ beforeAuth.run(null);
SaRouter.match(includeList).notMatch(excludeList).check(r -> {
- beforeAuth.run(null);
auth.run(null);
});
diff --git a/sa-token-starter/sa-token-reactor-spring-boot3-starter/src/main/java/cn/dev33/satoken/reactor/filter/SaReactorFilter.java b/sa-token-starter/sa-token-reactor-spring-boot3-starter/src/main/java/cn/dev33/satoken/reactor/filter/SaReactorFilter.java
index a3287b31..07207108 100644
--- a/sa-token-starter/sa-token-reactor-spring-boot3-starter/src/main/java/cn/dev33/satoken/reactor/filter/SaReactorFilter.java
+++ b/sa-token-starter/sa-token-reactor-spring-boot3-starter/src/main/java/cn/dev33/satoken/reactor/filter/SaReactorFilter.java
@@ -119,9 +119,9 @@ public class SaReactorFilter implements SaFilter, WebFilter {
// 写入全局上下文 (同步)
SaReactorSyncHolder.setContext(exchange);
- // 执行全局过滤器
+ // 执行全局过滤器
+ beforeAuth.run(null);
SaRouter.match(includeList).notMatch(excludeList).check(r -> {
- beforeAuth.run(null);
auth.run(null);
});
diff --git a/sa-token-starter/sa-token-solon-plugin/src/main/java/cn/dev33/satoken/solon/integration/SaTokenFilter.java b/sa-token-starter/sa-token-solon-plugin/src/main/java/cn/dev33/satoken/solon/integration/SaTokenFilter.java
index 6a4698f6..7179865d 100644
--- a/sa-token-starter/sa-token-solon-plugin/src/main/java/cn/dev33/satoken/solon/integration/SaTokenFilter.java
+++ b/sa-token-starter/sa-token-solon-plugin/src/main/java/cn/dev33/satoken/solon/integration/SaTokenFilter.java
@@ -124,11 +124,11 @@ public class SaTokenFilter implements SaFilter, Filter { //之所以改名,为
Action action = (mainHandler instanceof Action ? (Action) mainHandler : null);
//先路径过滤下(包括了静态文件)
+ //1.执行前置处理(主要是一些跨域之类的)
+ if(beforeAuth != null) {
+ beforeAuth.run(mainHandler);
+ }
SaRouter.match(includeList).notMatch(excludeList).check(r -> {
- //1.执行前置处理(主要是一些跨域之类的)
- if(beforeAuth != null) {
- beforeAuth.run(mainHandler);
- }
//2.执行注解处理
if(authAnno(action)) {
//3.执行规则处理(如果没有被 @SaIgnore 忽略)
diff --git a/sa-token-starter/sa-token-spring-boot-starter/src/main/java/cn/dev33/satoken/filter/SaServletFilter.java b/sa-token-starter/sa-token-spring-boot-starter/src/main/java/cn/dev33/satoken/filter/SaServletFilter.java
index ddd54d7d..15875222 100644
--- a/sa-token-starter/sa-token-spring-boot-starter/src/main/java/cn/dev33/satoken/filter/SaServletFilter.java
+++ b/sa-token-starter/sa-token-spring-boot-starter/src/main/java/cn/dev33/satoken/filter/SaServletFilter.java
@@ -111,9 +111,9 @@ public class SaServletFilter implements SaFilter, Filter {
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
try {
- // 执行全局过滤器
+ // 执行全局过滤器
+ beforeAuth.run(null);
SaRouter.match(includeList).notMatch(excludeList).check(r -> {
- beforeAuth.run(null);
auth.run(null);
});
diff --git a/sa-token-starter/sa-token-spring-boot3-starter/src/main/java/cn/dev33/satoken/filter/SaServletFilter.java b/sa-token-starter/sa-token-spring-boot3-starter/src/main/java/cn/dev33/satoken/filter/SaServletFilter.java
index 9255993c..98aa8f0c 100644
--- a/sa-token-starter/sa-token-spring-boot3-starter/src/main/java/cn/dev33/satoken/filter/SaServletFilter.java
+++ b/sa-token-starter/sa-token-spring-boot3-starter/src/main/java/cn/dev33/satoken/filter/SaServletFilter.java
@@ -110,9 +110,9 @@ public class SaServletFilter implements SaFilter, Filter {
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
try {
- // 执行全局过滤器
+ // 执行全局过滤器
+ beforeAuth.run(null);
SaRouter.match(includeList).notMatch(excludeList).check(r -> {
- beforeAuth.run(null);
auth.run(null);
});