mirror of
https://gitee.com/dromara/sa-token.git
synced 2024-12-02 03:47:50 +08:00
将全局过滤器的 BeforeAuth 认证设为不受 includeList 与 excludeList 的限制,所有请求都会进入
This commit is contained in:
parent
bc855f2b1b
commit
d54af36999
@ -94,7 +94,7 @@ public class SaTokenConfigure implements WebMvcConfigurer {
|
||||
return SaResult.error(e.getMessage());
|
||||
})
|
||||
|
||||
// 前置函数:在每次认证函数之前执行
|
||||
// 前置函数:在每次认证函数之前执行(BeforeAuth 不受 includeList 与 excludeList 的限制,所有请求都会进入)
|
||||
.setBeforeAuth(r -> {
|
||||
// ---------- 设置一些安全响应头 ----------
|
||||
SaHolder.getResponse()
|
||||
|
@ -13,7 +13,7 @@
|
||||
<version>2.2.3</version>
|
||||
<relativePath/>
|
||||
</parent>
|
||||
|
||||
|
||||
<!-- 定义 Sa-Token 版本号 -->
|
||||
<properties>
|
||||
<sa-token.version>1.34.0</sa-token.version>
|
||||
|
@ -42,7 +42,7 @@ public class SaTokenConfigure {
|
||||
return AjaxJson.getError(e.getMessage());
|
||||
})
|
||||
|
||||
// 前置函数:在每次认证函数之前执行
|
||||
// 前置函数:在每次认证函数之前执行(BeforeAuth 不受 includeList 与 excludeList 的限制,所有请求都会进入)
|
||||
.setBeforeAuth(r -> {
|
||||
// ---------- 设置一些安全响应头 ----------
|
||||
SaHolder.getResponse()
|
||||
|
@ -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()
|
||||
|
@ -50,7 +50,7 @@ public class SaTokenConfigure implements WebMvcConfigurer {
|
||||
return SaResult.error(e.getMessage());
|
||||
})
|
||||
|
||||
// 前置函数:在每次认证函数之前执行
|
||||
// 前置函数:在每次认证函数之前执行(BeforeAuth 不受 includeList 与 excludeList 的限制,所有请求都会进入)
|
||||
.setBeforeAuth(r -> {
|
||||
// ---------- 设置一些安全响应头 ----------
|
||||
SaHolder.getResponse()
|
||||
|
@ -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()
|
||||
|
@ -51,7 +51,7 @@ public class SaTokenConfigure implements WebMvcConfigurer {
|
||||
return SaResult.error(e.getMessage());
|
||||
})
|
||||
|
||||
// 前置函数:在每次认证函数之前执行
|
||||
// 前置函数:在每次认证函数之前执行(BeforeAuth 不受 includeList 与 excludeList 的限制,所有请求都会进入)
|
||||
.setBeforeAuth(r -> {
|
||||
// ---------- 设置一些安全响应头 ----------
|
||||
SaHolder.getResponse()
|
||||
|
@ -53,7 +53,7 @@ public class SaTokenConfigure {
|
||||
return SaResult.error(e.getMessage());
|
||||
})
|
||||
|
||||
// 前置函数:在每次认证函数之前执行
|
||||
// 前置函数:在每次认证函数之前执行(BeforeAuth 不受 includeList 与 excludeList 的限制,所有请求都会进入)
|
||||
.setBeforeAuth(r -> {
|
||||
// ---------- 设置一些安全响应头 ----------
|
||||
SaHolder.getResponse()
|
||||
|
@ -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);
|
||||
});
|
||||
|
||||
|
@ -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);
|
||||
});
|
||||
|
||||
|
@ -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);
|
||||
});
|
||||
|
||||
|
@ -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);
|
||||
});
|
||||
|
||||
|
@ -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 忽略)
|
||||
|
@ -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);
|
||||
});
|
||||
|
||||
|
@ -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);
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user