抽离过滤器接口 SaFilter

This commit is contained in:
click33 2023-04-29 07:12:11 +08:00
parent 14fc74ec9d
commit bc855f2b1b
13 changed files with 191 additions and 411 deletions

View File

@ -0,0 +1,70 @@
package cn.dev33.satoken.filter;
import java.util.List;
/**
* Sa-Token 过滤器接口为不同版本的过滤器
* 1封装共同代码
* 2定义统一的行为接口
*
* @author click33
* @since 2023/4/29
*/
public interface SaFilter {
// ------------------------ 设置此过滤器 拦截 & 放行 的路由
/**
* 添加 [ 拦截路由 ]
* @param paths 路由
* @return 对象自身
*/
public SaFilter addInclude(String... paths);
/**
* 添加 [ 放行路由 ]
* @param paths 路由
* @return 对象自身
*/
public SaFilter addExclude(String... paths);
/**
* 写入 [ 拦截路由 ] 集合
* @param pathList 路由集合
* @return 对象自身
*/
public SaFilter setIncludeList(List<String> pathList);
/**
* 写入 [ 放行路由 ] 集合
* @param pathList 路由集合
* @return 对象自身
*/
public SaFilter setExcludeList(List<String> pathList);
// ------------------------ 钩子函数
/**
* 写入[ 认证函数 ]: 每次请求执行
* @param auth see note
* @return 对象自身
*/
public SaFilter setAuth(SaFilterAuthStrategy auth);
/**
* 写入[ 异常处理函数 ]每次[ 认证函数 ]发生异常时执行此函数
* @param error see note
* @return 对象自身
*/
public SaFilter setError(SaFilterErrorStrategy error);
/**
* 写入[ 前置函数 ]在每次[ 认证函数 ]之前执行
* <b>注意点前置认证函数将不受 includeList excludeList 的限制所有路由的请求都会进入 beforeAuth</b>
* @param beforeAuth /
* @return 对象自身
*/
public SaFilter setBeforeAuth(SaFilterAuthStrategy beforeAuth);
}

View File

@ -6,6 +6,13 @@
<artifactId>sa-token-demo-solon</artifactId>
<version>0.0.1-SNAPSHOT</version>
<!-- Solon -->
<parent>
<groupId>org.noear</groupId>
<artifactId>solon-parent</artifactId>
<version>2.2.3</version>
<relativePath/>
</parent>
<!-- 定义 Sa-Token 版本号 -->
<properties>

View File

@ -6,6 +6,14 @@
<artifactId>sa-token-demo-sso-server-solon</artifactId>
<version>0.0.1-SNAPSHOT</version>
<!-- Solon -->
<parent>
<groupId>org.noear</groupId>
<artifactId>solon-parent</artifactId>
<version>2.2.3</version>
<relativePath/>
</parent>
<!-- 定义 Sa-Token 版本号 -->
<properties>
<sa-token.version>1.34.0</sa-token.version>

View File

@ -1,6 +1,7 @@
package com.pj;
import cn.dev33.satoken.SaManager;
import cn.dev33.satoken.filter.SaServletFilter;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>cn.dev33</groupId>

View File

@ -3,81 +3,50 @@ package cn.dev33.satoken.jboot;
import cn.dev33.satoken.exception.SaTokenException;
import cn.dev33.satoken.filter.SaFilterAuthStrategy;
import cn.dev33.satoken.filter.SaFilterErrorStrategy;
import cn.dev33.satoken.filter.SaFilter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class SaTokenPathFilter {
public class SaTokenPathFilter implements SaFilter {
// ------------------------ 设置此过滤器 拦截 & 放行 的路由
/**
* 拦截路由
*/
private List<String> includeList = new ArrayList<>();
public List<String> includeList = new ArrayList<>();
/**
* 放行路由
*/
private List<String> excludeList = new ArrayList<>();
public List<String> excludeList = new ArrayList<>();
/**
* 添加 [拦截路由]
* @param paths 路由
* @return 对象自身
*/
@Override
public SaTokenPathFilter addInclude(String... paths) {
includeList.addAll(Arrays.asList(paths));
return this;
}
/**
* 添加 [放行路由]
* @param paths 路由
* @return 对象自身
*/
@Override
public SaTokenPathFilter addExclude(String... paths) {
excludeList.addAll(Arrays.asList(paths));
return this;
}
/**
* 写入 [拦截路由] 集合
* @param pathList 路由集合
* @return 对象自身
*/
@Override
public SaTokenPathFilter setIncludeList(List<String> pathList) {
includeList = pathList;
return this;
}
/**
* 写入 [放行路由] 集合
* @param pathList 路由集合
* @return 对象自身
*/
@Override
public SaTokenPathFilter setExcludeList(List<String> pathList) {
excludeList = pathList;
return this;
}
/**
* 获取 [拦截路由] 集合
* @return see note
*/
public List<String> getIncludeList() {
return includeList;
}
/**
* 获取 [放行路由] 集合
* @return see note
*/
public List<String> getExcludeList() {
return excludeList;
}
// ------------------------ 钩子函数
@ -95,34 +64,23 @@ public class SaTokenPathFilter {
/**
* 前置函数在每次[认证函数]之前执行
* <b>注意点前置认证函数将不受 includeList excludeList 的限制所有路由的请求都会进入 beforeAuth</b>
*/
public SaFilterAuthStrategy beforeAuth = r -> {};
/**
* 写入[认证函数]: 每次请求执行
* @param auth see note
* @return 对象自身
*/
@Override
public SaTokenPathFilter setAuth(SaFilterAuthStrategy auth) {
this.auth = auth;
return this;
}
/**
* 写入[异常处理函数]每次[认证函数]发生异常时执行此函数
* @param error see note
* @return 对象自身
*/
@Override
public SaTokenPathFilter setError(SaFilterErrorStrategy error) {
this.error = error;
return this;
}
/**
* 写入[前置函数]在每次[认证函数]之前执行
* @param beforeAuth see note
* @return 对象自身
*/
@Override
public SaTokenPathFilter setBeforeAuth(SaFilterAuthStrategy beforeAuth) {
this.beforeAuth = beforeAuth;
return this;

View File

@ -3,81 +3,50 @@ package cn.dev33.satoken.jfinal;
import cn.dev33.satoken.exception.SaTokenException;
import cn.dev33.satoken.filter.SaFilterAuthStrategy;
import cn.dev33.satoken.filter.SaFilterErrorStrategy;
import cn.dev33.satoken.filter.SaFilter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class SaTokenPathFilter {
public class SaTokenPathFilter implements SaFilter {
// ------------------------ 设置此过滤器 拦截 & 放行 的路由
/**
* 拦截路由
*/
private List<String> includeList = new ArrayList<>();
public List<String> includeList = new ArrayList<>();
/**
* 放行路由
*/
private List<String> excludeList = new ArrayList<>();
public List<String> excludeList = new ArrayList<>();
/**
* 添加 [拦截路由]
* @param paths 路由
* @return 对象自身
*/
@Override
public SaTokenPathFilter addInclude(String... paths) {
includeList.addAll(Arrays.asList(paths));
return this;
}
/**
* 添加 [放行路由]
* @param paths 路由
* @return 对象自身
*/
@Override
public SaTokenPathFilter addExclude(String... paths) {
excludeList.addAll(Arrays.asList(paths));
return this;
}
/**
* 写入 [拦截路由] 集合
* @param pathList 路由集合
* @return 对象自身
*/
@Override
public SaTokenPathFilter setIncludeList(List<String> pathList) {
includeList = pathList;
return this;
}
/**
* 写入 [放行路由] 集合
* @param pathList 路由集合
* @return 对象自身
*/
@Override
public SaTokenPathFilter setExcludeList(List<String> pathList) {
excludeList = pathList;
return this;
}
/**
* 获取 [拦截路由] 集合
* @return see note
*/
public List<String> getIncludeList() {
return includeList;
}
/**
* 获取 [放行路由] 集合
* @return see note
*/
public List<String> getExcludeList() {
return excludeList;
}
// ------------------------ 钩子函数
@ -95,34 +64,23 @@ public class SaTokenPathFilter {
/**
* 前置函数在每次[认证函数]之前执行
* <b>注意点前置认证函数将不受 includeList excludeList 的限制所有路由的请求都会进入 beforeAuth</b>
*/
public SaFilterAuthStrategy beforeAuth = r -> {};
/**
* 写入[认证函数]: 每次请求执行
* @param auth see note
* @return 对象自身
*/
@Override
public SaTokenPathFilter setAuth(SaFilterAuthStrategy auth) {
this.auth = auth;
return this;
}
/**
* 写入[异常处理函数]每次[认证函数]发生异常时执行此函数
* @param error see note
* @return 对象自身
*/
@Override
public SaTokenPathFilter setError(SaFilterErrorStrategy error) {
this.error = error;
return this;
}
/**
* 写入[前置函数]在每次[认证函数]之前执行
* @param beforeAuth see note
* @return 对象自身
*/
@Override
public SaTokenPathFilter setBeforeAuth(SaFilterAuthStrategy beforeAuth) {
this.beforeAuth = beforeAuth;
return this;

View File

@ -4,6 +4,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import cn.dev33.satoken.filter.SaFilter;
import org.springframework.core.annotation.Order;
import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.server.WebFilter;
@ -27,75 +28,43 @@ import reactor.core.publisher.Mono;
*
*/
@Order(SaTokenConsts.ASSEMBLY_ORDER)
public class SaReactorFilter implements WebFilter {
public class SaReactorFilter implements SaFilter, WebFilter {
// ------------------------ 设置此过滤器 拦截 & 放行 的路由
/**
* 拦截路由
*/
private List<String> includeList = new ArrayList<>();
public List<String> includeList = new ArrayList<>();
/**
* 放行路由
*/
private List<String> excludeList = new ArrayList<>();
public List<String> excludeList = new ArrayList<>();
/**
* 添加 [拦截路由]
* @param paths 路由
* @return 对象自身
*/
@Override
public SaReactorFilter addInclude(String... paths) {
includeList.addAll(Arrays.asList(paths));
return this;
}
/**
* 添加 [放行路由]
* @param paths 路由
* @return 对象自身
*/
@Override
public SaReactorFilter addExclude(String... paths) {
excludeList.addAll(Arrays.asList(paths));
return this;
}
/**
* 写入 [拦截路由] 集合
* @param pathList 路由集合
* @return 对象自身
*/
@Override
public SaReactorFilter setIncludeList(List<String> pathList) {
includeList = pathList;
return this;
}
/**
* 写入 [放行路由] 集合
* @param pathList 路由集合
* @return 对象自身
*/
@Override
public SaReactorFilter setExcludeList(List<String> pathList) {
excludeList = pathList;
return this;
}
/**
* 获取 [拦截路由] 集合
* @return see note
*/
public List<String> getIncludeList() {
return includeList;
}
/**
* 获取 [放行路由] 集合
* @return see note
*/
public List<String> getExcludeList() {
return excludeList;
}
// ------------------------ 钩子函数
@ -113,35 +82,24 @@ public class SaReactorFilter implements WebFilter {
};
/**
* 前置函数在每次[认证函数]之前执行
* 前置函数在每次[认证函数]之前执行
* <b>注意点前置认证函数将不受 includeList excludeList 的限制所有路由的请求都会进入 beforeAuth</b>
*/
public SaFilterAuthStrategy beforeAuth = r -> {};
/**
* 写入[认证函数]: 每次请求执行
* @param auth see note
* @return 对象自身
*/
@Override
public SaReactorFilter setAuth(SaFilterAuthStrategy auth) {
this.auth = auth;
return this;
}
/**
* 写入[异常处理函数]每次[认证函数]发生异常时执行此函数
* @param error see note
* @return 对象自身
*/
@Override
public SaReactorFilter setError(SaFilterErrorStrategy error) {
this.error = error;
return this;
}
/**
* 写入[前置函数]在每次[认证函数]之前执行
* @param beforeAuth see note
* @return 对象自身
*/
@Override
public SaReactorFilter setBeforeAuth(SaFilterAuthStrategy beforeAuth) {
this.beforeAuth = beforeAuth;
return this;

View File

@ -4,6 +4,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import cn.dev33.satoken.filter.SaFilter;
import org.springframework.core.annotation.Order;
import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.server.WebFilter;
@ -27,75 +28,43 @@ import reactor.core.publisher.Mono;
*
*/
@Order(SaTokenConsts.ASSEMBLY_ORDER)
public class SaReactorFilter implements WebFilter {
public class SaReactorFilter implements SaFilter, WebFilter {
// ------------------------ 设置此过滤器 拦截 & 放行 的路由
/**
* 拦截路由
*/
private List<String> includeList = new ArrayList<>();
public List<String> includeList = new ArrayList<>();
/**
* 放行路由
*/
private List<String> excludeList = new ArrayList<>();
public List<String> excludeList = new ArrayList<>();
/**
* 添加 [拦截路由]
* @param paths 路由
* @return 对象自身
*/
@Override
public SaReactorFilter addInclude(String... paths) {
includeList.addAll(Arrays.asList(paths));
return this;
}
/**
* 添加 [放行路由]
* @param paths 路由
* @return 对象自身
*/
@Override
public SaReactorFilter addExclude(String... paths) {
excludeList.addAll(Arrays.asList(paths));
return this;
}
/**
* 写入 [拦截路由] 集合
* @param pathList 路由集合
* @return 对象自身
*/
@Override
public SaReactorFilter setIncludeList(List<String> pathList) {
includeList = pathList;
return this;
}
/**
* 写入 [放行路由] 集合
* @param pathList 路由集合
* @return 对象自身
*/
@Override
public SaReactorFilter setExcludeList(List<String> pathList) {
excludeList = pathList;
return this;
}
/**
* 获取 [拦截路由] 集合
* @return see note
*/
public List<String> getIncludeList() {
return includeList;
}
/**
* 获取 [放行路由] 集合
* @return see note
*/
public List<String> getExcludeList() {
return excludeList;
}
// ------------------------ 钩子函数
@ -113,35 +82,24 @@ public class SaReactorFilter implements WebFilter {
};
/**
* 前置函数在每次[认证函数]之前执行
* 前置函数在每次[认证函数]之前执行
* <b>注意点前置认证函数将不受 includeList excludeList 的限制所有路由的请求都会进入 beforeAuth</b>
*/
public SaFilterAuthStrategy beforeAuth = r -> {};
/**
* 写入[认证函数]: 每次请求执行
* @param auth see note
* @return 对象自身
*/
@Override
public SaReactorFilter setAuth(SaFilterAuthStrategy auth) {
this.auth = auth;
return this;
}
/**
* 写入[异常处理函数]每次[认证函数]发生异常时执行此函数
* @param error see note
* @return 对象自身
*/
@Override
public SaReactorFilter setError(SaFilterErrorStrategy error) {
this.error = error;
return this;
}
/**
* 写入[前置函数]在每次[认证函数]之前执行
* @param beforeAuth see note
* @return 对象自身
*/
@Override
public SaReactorFilter setBeforeAuth(SaFilterAuthStrategy beforeAuth) {
this.beforeAuth = beforeAuth;
return this;

View File

@ -6,6 +6,7 @@ import cn.dev33.satoken.exception.SaTokenException;
import cn.dev33.satoken.exception.StopMatchException;
import cn.dev33.satoken.filter.SaFilterAuthStrategy;
import cn.dev33.satoken.filter.SaFilterErrorStrategy;
import cn.dev33.satoken.filter.SaFilter;
import cn.dev33.satoken.router.SaRouter;
import cn.dev33.satoken.strategy.SaStrategy;
import org.noear.solon.Solon;
@ -26,7 +27,8 @@ import java.util.List;
* @author noear
* @since 1.10
*/
public class SaTokenFilter implements Filter { //之所以改名为了跟 SaTokenInterceptor 形成一对
public class SaTokenFilter implements SaFilter, Filter { //之所以改名为了跟 SaTokenInterceptor 形成一对
/**
* 是否打开注解鉴权
*/
@ -37,88 +39,50 @@ public class SaTokenFilter implements Filter { //之所以改名,为了跟 SaT
/**
* 拦截路由
*/
protected List<String> includeList = new ArrayList<>();
public List<String> includeList = new ArrayList<>();
/**
* 放行路由
*/
protected List<String> excludeList = new ArrayList<>();
public List<String> excludeList = new ArrayList<>();
/**
* 添加 [拦截路由]
*
* @param paths 路由
* @return 对象自身
*/
@Override
public SaTokenFilter addInclude(String... paths) {
includeList.addAll(Arrays.asList(paths));
return this;
}
/**
* 添加 [放行路由]
*
* @param paths 路由
* @return 对象自身
*/
@Override
public SaTokenFilter addExclude(String... paths) {
excludeList.addAll(Arrays.asList(paths));
return this;
}
/**
* 写入 [拦截路由] 集合
*
* @param pathList 路由集合
* @return 对象自身
*/
@Override
public SaTokenFilter setIncludeList(List<String> pathList) {
includeList = pathList;
return this;
}
/**
* 写入 [放行路由] 集合
*
* @param pathList 路由集合
* @return 对象自身
*/
@Override
public SaTokenFilter setExcludeList(List<String> pathList) {
excludeList = pathList;
return this;
}
/**
* 获取 [拦截路由] 集合
*
* @return see note
*/
public List<String> getIncludeList() {
return includeList;
}
/**
* 获取 [放行路由] 集合
*
* @return see note
*/
public List<String> getExcludeList() {
return excludeList;
}
// ------------------------ 钩子函数
/**
* 认证函数每次请求执行
*/
protected SaFilterAuthStrategy auth = r -> {
public SaFilterAuthStrategy auth = r -> {
};
/**
* 异常处理函数每次[认证函数]发生异常时执行此函数
*/
protected SaFilterErrorStrategy error = e -> {
public SaFilterErrorStrategy error = e -> {
if (e instanceof SaTokenException) {
throw (SaTokenException) e;
} else {
@ -128,38 +92,24 @@ public class SaTokenFilter implements Filter { //之所以改名,为了跟 SaT
/**
* 前置函数在每次[认证函数]之前执行
* <b>注意点前置认证函数将不受 includeList excludeList 的限制所有路由的请求都会进入 beforeAuth</b>
*/
protected SaFilterAuthStrategy beforeAuth = r -> {
public SaFilterAuthStrategy beforeAuth = r -> {
};
/**
* 写入[认证函数]: 每次请求执行
*
* @param auth see note
* @return 对象自身
*/
@Override
public SaTokenFilter setAuth(SaFilterAuthStrategy auth) {
this.auth = auth;
return this;
}
/**
* 写入[异常处理函数]每次[认证函数]发生异常时执行此函数
*
* @param error see note
* @return 对象自身
*/
@Override
public SaTokenFilter setError(SaFilterErrorStrategy error) {
this.error = error;
return this;
}
/**
* 写入[前置函数]在每次[认证函数]之前执行
*
* @param beforeAuth see note
* @return 对象自身
*/
@Override
public SaTokenFilter setBeforeAuth(SaFilterAuthStrategy beforeAuth) {
this.beforeAuth = beforeAuth;
return this;

View File

@ -27,75 +27,43 @@ import cn.dev33.satoken.util.SaTokenConsts;
*
*/
@Order(SaTokenConsts.ASSEMBLY_ORDER)
public class SaServletFilter implements Filter {
public class SaServletFilter implements SaFilter, Filter {
// ------------------------ 设置此过滤器 拦截 & 放行 的路由
/**
* 拦截路由
*/
private List<String> includeList = new ArrayList<>();
public List<String> includeList = new ArrayList<>();
/**
* 放行路由
*/
private List<String> excludeList = new ArrayList<>();
public List<String> excludeList = new ArrayList<>();
/**
* 添加 [拦截路由]
* @param paths 路由
* @return 对象自身
*/
@Override
public SaServletFilter addInclude(String... paths) {
includeList.addAll(Arrays.asList(paths));
return this;
}
/**
* 添加 [放行路由]
* @param paths 路由
* @return 对象自身
*/
@Override
public SaServletFilter addExclude(String... paths) {
excludeList.addAll(Arrays.asList(paths));
return this;
}
/**
* 写入 [拦截路由] 集合
* @param pathList 路由集合
* @return 对象自身
*/
@Override
public SaServletFilter setIncludeList(List<String> pathList) {
includeList = pathList;
return this;
}
/**
* 写入 [放行路由] 集合
* @param pathList 路由集合
* @return 对象自身
*/
@Override
public SaServletFilter setExcludeList(List<String> pathList) {
excludeList = pathList;
return this;
}
/**
* 获取 [拦截路由] 集合
* @return see note
*/
public List<String> getIncludeList() {
return includeList;
}
/**
* 获取 [放行路由] 集合
* @return see note
*/
public List<String> getExcludeList() {
return excludeList;
}
// ------------------------ 钩子函数
@ -113,35 +81,24 @@ public class SaServletFilter implements Filter {
};
/**
* 前置函数在每次[认证函数]之前执行
* 前置函数在每次[认证函数]之前执行
* <b>注意点前置认证函数将不受 includeList excludeList 的限制所有路由的请求都会进入 beforeAuth</b>
*/
public SaFilterAuthStrategy beforeAuth = r -> {};
/**
* 写入[认证函数]: 每次请求执行
* @param auth see note
* @return 对象自身
*/
@Override
public SaServletFilter setAuth(SaFilterAuthStrategy auth) {
this.auth = auth;
return this;
}
/**
* 写入[异常处理函数]每次[认证函数]发生异常时执行此函数
* @param error see note
* @return 对象自身
*/
@Override
public SaServletFilter setError(SaFilterErrorStrategy error) {
this.error = error;
return this;
}
/**
* 写入[前置函数]在每次[认证函数]之前执行
* @param beforeAuth see note
* @return 对象自身
*/
@Override
public SaServletFilter setBeforeAuth(SaFilterAuthStrategy beforeAuth) {
this.beforeAuth = beforeAuth;
return this;
@ -151,8 +108,7 @@ public class SaServletFilter implements Filter {
// ------------------------ doFilter
@Override
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 {
// 执行全局过滤器

View File

@ -26,75 +26,43 @@ import jakarta.servlet.ServletResponse;
*
*/
@Order(SaTokenConsts.ASSEMBLY_ORDER)
public class SaServletFilter implements Filter {
public class SaServletFilter implements SaFilter, Filter {
// ------------------------ 设置此过滤器 拦截 & 放行 的路由
/**
* 拦截路由
*/
private List<String> includeList = new ArrayList<>();
public List<String> includeList = new ArrayList<>();
/**
* 放行路由
*/
private List<String> excludeList = new ArrayList<>();
public List<String> excludeList = new ArrayList<>();
/**
* 添加 [拦截路由]
* @param paths 路由
* @return 对象自身
*/
@Override
public SaServletFilter addInclude(String... paths) {
includeList.addAll(Arrays.asList(paths));
return this;
}
/**
* 添加 [放行路由]
* @param paths 路由
* @return 对象自身
*/
@Override
public SaServletFilter addExclude(String... paths) {
excludeList.addAll(Arrays.asList(paths));
return this;
}
/**
* 写入 [拦截路由] 集合
* @param pathList 路由集合
* @return 对象自身
*/
@Override
public SaServletFilter setIncludeList(List<String> pathList) {
includeList = pathList;
return this;
}
/**
* 写入 [放行路由] 集合
* @param pathList 路由集合
* @return 对象自身
*/
@Override
public SaServletFilter setExcludeList(List<String> pathList) {
excludeList = pathList;
return this;
}
/**
* 获取 [拦截路由] 集合
* @return see note
*/
public List<String> getIncludeList() {
return includeList;
}
/**
* 获取 [放行路由] 集合
* @return see note
*/
public List<String> getExcludeList() {
return excludeList;
}
// ------------------------ 钩子函数
@ -112,35 +80,24 @@ public class SaServletFilter implements Filter {
};
/**
* 前置函数在每次[认证函数]之前执行
* 前置函数在每次[认证函数]之前执行
* <b>注意点前置认证函数将不受 includeList excludeList 的限制所有路由的请求都会进入 beforeAuth</b>
*/
public SaFilterAuthStrategy beforeAuth = r -> {};
/**
* 写入[认证函数]: 每次请求执行
* @param auth see note
* @return 对象自身
*/
@Override
public SaServletFilter setAuth(SaFilterAuthStrategy auth) {
this.auth = auth;
return this;
}
/**
* 写入[异常处理函数]每次[认证函数]发生异常时执行此函数
* @param error see note
* @return 对象自身
*/
@Override
public SaServletFilter setError(SaFilterErrorStrategy error) {
this.error = error;
return this;
}
/**
* 写入[前置函数]在每次[认证函数]之前执行
* @param beforeAuth see note
* @return 对象自身
*/
@Override
public SaServletFilter setBeforeAuth(SaFilterAuthStrategy beforeAuth) {
this.beforeAuth = beforeAuth;
return this;
@ -150,8 +107,7 @@ public class SaServletFilter implements Filter {
// ------------------------ doFilter
@Override
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 {
// 执行全局过滤器
@ -179,7 +135,7 @@ public class SaServletFilter implements Filter {
}
@Override
public void init(FilterConfig filterConfig) throws ServletException {
public void init(FilterConfig filterConfig) {
}
@Override

View File

@ -762,8 +762,8 @@ public class BasicsTest {
.setAuth(obj -> {})
.setBeforeAuth(obj -> {})
;
Assertions.assertEquals(filter.getIncludeList().get(0), "/**");
Assertions.assertEquals(filter.getExcludeList().get(0), "/favicon.ico");
Assertions.assertEquals(filter.includeList.get(0), "/**");
Assertions.assertEquals(filter.excludeList.get(0), "/favicon.ico");
// 以下功能无法测试
filter.init(null);
filter.doFilter(SpringMVCUtil.getRequest(), SpringMVCUtil.getResponse(), new MockFilterChain());