将全局过滤器的 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());
})
// 前置函数:在每次认证函数之前执行
// 前置函数:在每次认证函数之前执行BeforeAuth 不受 includeList 与 excludeList 的限制,所有请求都会进入)
.setBeforeAuth(r -> {
// ---------- 设置一些安全响应头 ----------
SaHolder.getResponse()

View File

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

View File

@@ -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()

View File

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

View File

@@ -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()

View File

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

View File

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

View File

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

View File

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

View File

@@ -120,8 +120,8 @@ public class SaReactorFilter implements SaFilter, WebFilter {
SaReactorSyncHolder.setContext(exchange);
// 执行全局过滤器
SaRouter.match(includeList).notMatch(excludeList).check(r -> {
beforeAuth.run(null);
SaRouter.match(includeList).notMatch(excludeList).check(r -> {
auth.run(null);
});

View File

@@ -120,8 +120,8 @@ public class SaReactorFilter implements SaFilter, WebFilter {
SaReactorSyncHolder.setContext(exchange);
// 执行全局过滤器
SaRouter.match(includeList).notMatch(excludeList).check(r -> {
beforeAuth.run(null);
SaRouter.match(includeList).notMatch(excludeList).check(r -> {
auth.run(null);
});

View File

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

View File

@@ -112,8 +112,8 @@ public class SaServletFilter implements SaFilter, Filter {
try {
// 执行全局过滤器
SaRouter.match(includeList).notMatch(excludeList).check(r -> {
beforeAuth.run(null);
SaRouter.match(includeList).notMatch(excludeList).check(r -> {
auth.run(null);
});

View File

@@ -111,8 +111,8 @@ public class SaServletFilter implements SaFilter, Filter {
try {
// 执行全局过滤器
SaRouter.match(includeList).notMatch(excludeList).check(r -> {
beforeAuth.run(null);
SaRouter.match(includeList).notMatch(excludeList).check(r -> {
auth.run(null);
});