mirror of
https://gitee.com/dromara/sa-token.git
synced 2024-12-02 03:47:50 +08:00
sa-token-solon-plugin 增加对 solon 网关的支持
This commit is contained in:
parent
26c312f8d6
commit
172351ad04
@ -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;
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user