mirror of
https://gitee.com/dromara/sa-token.git
synced 2025-09-18 17:48:03 +08:00
将全局过滤器的 BeforeAuth 认证设为不受 includeList 与 excludeList 的限制,所有请求都会进入
This commit is contained in:
@@ -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()
|
||||||
|
@@ -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>
|
||||||
|
@@ -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()
|
||||||
|
@@ -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()
|
||||||
|
@@ -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()
|
||||||
|
@@ -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()
|
||||||
|
@@ -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()
|
||||||
|
@@ -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()
|
||||||
|
@@ -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);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@@ -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);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@@ -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);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@@ -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);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@@ -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 忽略)
|
||||||
|
@@ -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);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@@ -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);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user