sa-token-solon-plugin 增加对 solon 网关的支持

This commit is contained in:
noear 2023-07-26 10:15:36 +08:00
parent 26c312f8d6
commit 172351ad04
2 changed files with 22 additions and 4 deletions

View File

@ -26,6 +26,7 @@ import cn.dev33.satoken.router.SaRouter;
import cn.dev33.satoken.strategy.SaStrategy;
import org.noear.solon.Solon;
import org.noear.solon.core.handle.*;
import org.noear.solon.core.route.RoutingTable;
import java.lang.reflect.Method;
import java.util.ArrayList;
@ -136,6 +137,13 @@ public class SaTokenFilter implements SaFilter, Filter { //之所以改名,为
try {
//查找当前主处理
Handler mainHandler = Solon.app().router().matchMain(ctx);
if (mainHandler instanceof Gateway) {
//支持网关处理
Gateway gateway = (Gateway) mainHandler;
RoutingTable<Handler> mainRouting = gateway.getMainRouting();
MethodType method = MethodTypeUtil.valueOf(ctx.method());
mainHandler = mainRouting.matchOne(ctx.pathNew(), method);
}
Action action = (mainHandler instanceof Action ? (Action) mainHandler : null);
//1.执行前置处理主要是一些跨域之类的
@ -144,16 +152,16 @@ public class SaTokenFilter implements SaFilter, Filter { //之所以改名,为
}
//先路径过滤下包括了静态文件
Handler finalMainHandler = mainHandler;
SaRouter.match(includeList).notMatch(excludeList).check(r -> {
//2.执行注解处理
if(authAnno(action)) {
//3.执行规则处理如果没有被 @SaIgnore 忽略
auth.run(mainHandler);
auth.run(finalMainHandler);
}
});
} catch (StopMatchException e) {
// StopMatchException 异常代表停止匹配进入Controller
} catch (SaTokenException e) {
// 1. 获取异常处理策略结果
Object result;

View File

@ -26,6 +26,7 @@ import cn.dev33.satoken.strategy.SaStrategy;
import org.noear.solon.core.handle.*;
import org.noear.solon.core.route.RouterInterceptor;
import org.noear.solon.core.route.RouterInterceptorChain;
import org.noear.solon.core.route.RoutingTable;
import java.lang.reflect.Method;
import java.util.ArrayList;
@ -185,6 +186,14 @@ public class SaTokenInterceptor implements RouterInterceptor {
@Override
public void doIntercept(Context ctx, Handler mainHandler, RouterInterceptorChain chain) throws Throwable {
try {
if (mainHandler instanceof Gateway) {
//支持网关处理
Gateway gateway = (Gateway) mainHandler;
RoutingTable<Handler> mainRouting = gateway.getMainRouting();
MethodType method = MethodTypeUtil.valueOf(ctx.method());
mainHandler = mainRouting.matchOne(ctx.pathNew(), method);
}
Action action = (mainHandler instanceof Action ? (Action) mainHandler : null);
//1.执行前置处理主要是一些跨域之类的
@ -193,16 +202,17 @@ public class SaTokenInterceptor implements RouterInterceptor {
}
//先路径过滤下不包括静态文件
Handler finalMainHandler = mainHandler;
SaRouter.match(includeList).notMatch(excludeList).check(r -> {
//2.执行注解处理
if(authAnno(action)) {
//3.执行规则处理如果没有被 @SaIgnore 忽略
auth.run(mainHandler);
auth.run(finalMainHandler);
}
});
} catch (StopMatchException e) {
// StopMatchException 异常代表停止匹配进入Controller
} catch (SaTokenException e) {
// 1. 获取异常处理策略结果
Object result;