将全局过滤器的 BeforeAuth 认证设为不受 includeList 与 excludeList 的限制,所有请求都会进入

This commit is contained in:
click33
2023-04-29 22:10:14 +08:00
parent bc855f2b1b
commit d54af36999
15 changed files with 28 additions and 29 deletions

View File

@@ -94,7 +94,7 @@ public class SaTokenConfigure implements WebMvcConfigurer {
return SaResult.error(e.getMessage()); return SaResult.error(e.getMessage());
}) })
// 前置函数:在每次认证函数之前执行 // 前置函数:在每次认证函数之前执行BeforeAuth 不受 includeList 与 excludeList 的限制,所有请求都会进入)
.setBeforeAuth(r -> { .setBeforeAuth(r -> {
// ---------- 设置一些安全响应头 ---------- // ---------- 设置一些安全响应头 ----------
SaHolder.getResponse() SaHolder.getResponse()

View File

@@ -13,7 +13,7 @@
<version>2.2.3</version> <version>2.2.3</version>
<relativePath/> <relativePath/>
</parent> </parent>
<!-- 定义 Sa-Token 版本号 --> <!-- 定义 Sa-Token 版本号 -->
<properties> <properties>
<sa-token.version>1.34.0</sa-token.version> <sa-token.version>1.34.0</sa-token.version>

View File

@@ -42,7 +42,7 @@ public class SaTokenConfigure {
return AjaxJson.getError(e.getMessage()); return AjaxJson.getError(e.getMessage());
}) })
// 前置函数:在每次认证函数之前执行 // 前置函数:在每次认证函数之前执行BeforeAuth 不受 includeList 与 excludeList 的限制,所有请求都会进入)
.setBeforeAuth(r -> { .setBeforeAuth(r -> {
// ---------- 设置一些安全响应头 ---------- // ---------- 设置一些安全响应头 ----------
SaHolder.getResponse() SaHolder.getResponse()

View File

@@ -1,14 +1,13 @@
package com.pj.satoken; 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.context.SaHolder;
import cn.dev33.satoken.filter.SaServletFilter; import cn.dev33.satoken.filter.SaServletFilter;
import cn.dev33.satoken.interceptor.SaInterceptor; import cn.dev33.satoken.interceptor.SaInterceptor;
import cn.dev33.satoken.util.SaResult; 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 -> { .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()); return SaResult.error(e.getMessage());
}) })
// 前置函数:在每次认证函数之前执行 // 前置函数:在每次认证函数之前执行 BeforeAuth不受 includeList 与 excludeList 的限制,所有请求都会进入)
.setBeforeAuth(r -> { .setBeforeAuth(r -> {
// ---------- 设置一些安全响应头 ---------- // ---------- 设置一些安全响应头 ----------
SaHolder.getResponse() SaHolder.getResponse()

View File

@@ -50,7 +50,7 @@ public class SaTokenConfigure implements WebMvcConfigurer {
return SaResult.error(e.getMessage()); return SaResult.error(e.getMessage());
}) })
// 前置函数:在每次认证函数之前执行 // 前置函数:在每次认证函数之前执行BeforeAuth 不受 includeList 与 excludeList 的限制,所有请求都会进入)
.setBeforeAuth(r -> { .setBeforeAuth(r -> {
// ---------- 设置一些安全响应头 ---------- // ---------- 设置一些安全响应头 ----------
SaHolder.getResponse() SaHolder.getResponse()

View File

@@ -41,7 +41,7 @@ public class SaTokenConfigure implements WebMvcConfigurer {
// 认证函数: 每次请求执行 // 认证函数: 每次请求执行
.setAuth(obj -> { .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()); return AjaxJson.getError(e.getMessage());
}) })
// 前置函数:在每次认证函数之前执行 // 前置函数:在每次认证函数之前执行BeforeAuth 不受 includeList 与 excludeList 的限制,所有请求都会进入)
.setBeforeAuth(r -> { .setBeforeAuth(r -> {
// ---------- 设置一些安全响应头 ---------- // ---------- 设置一些安全响应头 ----------
SaHolder.getResponse() SaHolder.getResponse()

View File

@@ -51,7 +51,7 @@ public class SaTokenConfigure implements WebMvcConfigurer {
return SaResult.error(e.getMessage()); return SaResult.error(e.getMessage());
}) })
// 前置函数:在每次认证函数之前执行 // 前置函数:在每次认证函数之前执行BeforeAuth 不受 includeList 与 excludeList 的限制,所有请求都会进入)
.setBeforeAuth(r -> { .setBeforeAuth(r -> {
// ---------- 设置一些安全响应头 ---------- // ---------- 设置一些安全响应头 ----------
SaHolder.getResponse() SaHolder.getResponse()

View File

@@ -53,7 +53,7 @@ public class SaTokenConfigure {
return SaResult.error(e.getMessage()); return SaResult.error(e.getMessage());
}) })
// 前置函数:在每次认证函数之前执行 // 前置函数:在每次认证函数之前执行BeforeAuth 不受 includeList 与 excludeList 的限制,所有请求都会进入)
.setBeforeAuth(r -> { .setBeforeAuth(r -> {
// ---------- 设置一些安全响应头 ---------- // ---------- 设置一些安全响应头 ----------
SaHolder.getResponse() SaHolder.getResponse()

View File

@@ -91,8 +91,8 @@ public class SaTokenPathFilter implements SaFilter {
public void doFilter(Controller ctx, FilterChain chain) throws Throwable { public void doFilter(Controller ctx, FilterChain chain) throws Throwable {
try { try {
// 执行全局过滤器 // 执行全局过滤器
beforeAuth.run(null);
SaRouter.match(includeList).notMatch(excludeList).check(r -> { SaRouter.match(includeList).notMatch(excludeList).check(r -> {
beforeAuth.run(null);
auth.run(null); auth.run(null);
}); });

View File

@@ -91,8 +91,8 @@ public class SaTokenPathFilter implements SaFilter {
public void doFilter(Controller ctx, FilterChain chain) throws Throwable { public void doFilter(Controller ctx, FilterChain chain) throws Throwable {
try { try {
// 执行全局过滤器 // 执行全局过滤器
beforeAuth.run(null);
SaRouter.match(includeList).notMatch(excludeList).check(r -> { SaRouter.match(includeList).notMatch(excludeList).check(r -> {
beforeAuth.run(null);
auth.run(null); auth.run(null);
}); });

View File

@@ -119,9 +119,9 @@ public class SaReactorFilter implements SaFilter, WebFilter {
// 写入全局上下文 (同步) // 写入全局上下文 (同步)
SaReactorSyncHolder.setContext(exchange); SaReactorSyncHolder.setContext(exchange);
// 执行全局过滤器 // 执行全局过滤器
beforeAuth.run(null);
SaRouter.match(includeList).notMatch(excludeList).check(r -> { SaRouter.match(includeList).notMatch(excludeList).check(r -> {
beforeAuth.run(null);
auth.run(null); auth.run(null);
}); });

View File

@@ -119,9 +119,9 @@ public class SaReactorFilter implements SaFilter, WebFilter {
// 写入全局上下文 (同步) // 写入全局上下文 (同步)
SaReactorSyncHolder.setContext(exchange); SaReactorSyncHolder.setContext(exchange);
// 执行全局过滤器 // 执行全局过滤器
beforeAuth.run(null);
SaRouter.match(includeList).notMatch(excludeList).check(r -> { SaRouter.match(includeList).notMatch(excludeList).check(r -> {
beforeAuth.run(null);
auth.run(null); auth.run(null);
}); });

View File

@@ -124,11 +124,11 @@ public class SaTokenFilter implements SaFilter, Filter { //之所以改名,为
Action action = (mainHandler instanceof Action ? (Action) mainHandler : null); Action action = (mainHandler instanceof Action ? (Action) mainHandler : null);
//先路径过滤下(包括了静态文件) //先路径过滤下(包括了静态文件)
//1.执行前置处理(主要是一些跨域之类的)
if(beforeAuth != null) {
beforeAuth.run(mainHandler);
}
SaRouter.match(includeList).notMatch(excludeList).check(r -> { SaRouter.match(includeList).notMatch(excludeList).check(r -> {
//1.执行前置处理(主要是一些跨域之类的)
if(beforeAuth != null) {
beforeAuth.run(mainHandler);
}
//2.执行注解处理 //2.执行注解处理
if(authAnno(action)) { if(authAnno(action)) {
//3.执行规则处理(如果没有被 @SaIgnore 忽略) //3.执行规则处理(如果没有被 @SaIgnore 忽略)

View File

@@ -111,9 +111,9 @@ public class SaServletFilter implements SaFilter, Filter {
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
try { try {
// 执行全局过滤器 // 执行全局过滤器
beforeAuth.run(null);
SaRouter.match(includeList).notMatch(excludeList).check(r -> { SaRouter.match(includeList).notMatch(excludeList).check(r -> {
beforeAuth.run(null);
auth.run(null); auth.run(null);
}); });

View File

@@ -110,9 +110,9 @@ public class SaServletFilter implements SaFilter, Filter {
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
try { try {
// 执行全局过滤器 // 执行全局过滤器
beforeAuth.run(null);
SaRouter.match(includeList).notMatch(excludeList).check(r -> { SaRouter.match(includeList).notMatch(excludeList).check(r -> {
beforeAuth.run(null);
auth.run(null); auth.run(null);
}); });