mirror of
https://gitee.com/dromara/sa-token.git
synced 2025-05-04 04:37:56 +08:00
调整 sa-token 拦截适配的处理顺序
This commit is contained in:
parent
34f63449f7
commit
228c709d41
@ -173,25 +173,17 @@ public class SaTokenFilter implements Filter { //之所以改名,为了跟 SaT
|
|||||||
Handler mainHandler = Solon.app().router().matchMain(ctx);
|
Handler mainHandler = Solon.app().router().matchMain(ctx);
|
||||||
Action action = (mainHandler instanceof Action ? (Action) mainHandler : null);
|
Action action = (mainHandler instanceof Action ? (Action) mainHandler : null);
|
||||||
|
|
||||||
//1.路径规则处理(包括了静态文件)
|
//先路径过滤下(包括了静态文件)
|
||||||
SaRouter.match(includeList).notMatch(excludeList).check(r -> {
|
SaRouter.match(includeList).notMatch(excludeList).check(r -> {
|
||||||
beforeAuth.run(mainHandler);
|
//1.执行前置处理(主要是一些跨域之类的)
|
||||||
|
if(beforeAuth != null) {
|
||||||
|
beforeAuth.run(mainHandler);
|
||||||
|
}
|
||||||
|
//2.执行注解处理
|
||||||
|
authAnno(action);
|
||||||
|
//3.执行规则处理
|
||||||
auth.run(mainHandler);
|
auth.run(mainHandler);
|
||||||
});
|
});
|
||||||
|
|
||||||
//2.验证注解处理
|
|
||||||
if (isAnnotation && action != null) {
|
|
||||||
// 获取此请求对应的 Method 处理函数
|
|
||||||
Method method = action.method().getMethod();
|
|
||||||
|
|
||||||
// 如果此 Method 或其所属 Class 标注了 @SaIgnore,则忽略掉鉴权
|
|
||||||
if (SaStrategy.me.isAnnotationPresent.apply(method, SaIgnore.class)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 注解校验
|
|
||||||
SaStrategy.me.checkMethodAnnotation.accept(method);
|
|
||||||
}
|
|
||||||
} catch (StopMatchException e) {
|
} catch (StopMatchException e) {
|
||||||
|
|
||||||
} catch (SaTokenException e) {
|
} catch (SaTokenException e) {
|
||||||
@ -213,4 +205,20 @@ public class SaTokenFilter implements Filter { //之所以改名,为了跟 SaT
|
|||||||
|
|
||||||
chain.doFilter(ctx);
|
chain.doFilter(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void authAnno(Action action) {
|
||||||
|
//2.验证注解处理
|
||||||
|
if (isAnnotation && action != null) {
|
||||||
|
// 获取此请求对应的 Method 处理函数
|
||||||
|
Method method = action.method().getMethod();
|
||||||
|
|
||||||
|
// 如果此 Method 或其所属 Class 标注了 @SaIgnore,则忽略掉鉴权
|
||||||
|
if (SaStrategy.me.isAnnotationPresent.apply(method, SaIgnore.class)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 注解校验
|
||||||
|
SaStrategy.me.checkMethodAnnotation.accept(method);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -172,26 +172,18 @@ public class SaTokenInterceptor implements RouterInterceptor {
|
|||||||
try {
|
try {
|
||||||
Action action = (mainHandler instanceof Action ? (Action) mainHandler : null);
|
Action action = (mainHandler instanceof Action ? (Action) mainHandler : null);
|
||||||
|
|
||||||
//1.路径规则处理
|
//先路径过滤下(包括了静态文件)
|
||||||
SaRouter.match(includeList).notMatch(excludeList).check(r -> {
|
SaRouter.match(includeList).notMatch(excludeList).check(r -> {
|
||||||
beforeAuth.run(mainHandler);
|
//1.执行前置处理(主要是一些跨域之类的)
|
||||||
|
if(beforeAuth != null) {
|
||||||
|
beforeAuth.run(mainHandler);
|
||||||
|
}
|
||||||
|
//2.执行注解处理
|
||||||
|
authAnno(action);
|
||||||
|
//3.执行规则处理
|
||||||
auth.run(mainHandler);
|
auth.run(mainHandler);
|
||||||
});
|
});
|
||||||
|
|
||||||
//2.验证注解处理
|
|
||||||
if (isAnnotation && action != null) {
|
|
||||||
// 获取此请求对应的 Method 处理函数
|
|
||||||
Method method = action.method().getMethod();
|
|
||||||
|
|
||||||
// 如果此 Method 或其所属 Class 标注了 @SaIgnore,则忽略掉鉴权
|
|
||||||
if (SaStrategy.me.isAnnotationPresent.apply(method, SaIgnore.class)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 注解校验
|
|
||||||
SaStrategy.me.checkMethodAnnotation.accept(method);
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (StopMatchException e) {
|
} catch (StopMatchException e) {
|
||||||
|
|
||||||
} catch (SaTokenException e) {
|
} catch (SaTokenException e) {
|
||||||
@ -213,4 +205,20 @@ public class SaTokenInterceptor implements RouterInterceptor {
|
|||||||
|
|
||||||
chain.doIntercept(ctx, mainHandler);
|
chain.doIntercept(ctx, mainHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void authAnno(Action action) {
|
||||||
|
//2.验证注解处理
|
||||||
|
if (isAnnotation && action != null) {
|
||||||
|
// 获取此请求对应的 Method 处理函数
|
||||||
|
Method method = action.method().getMethod();
|
||||||
|
|
||||||
|
// 如果此 Method 或其所属 Class 标注了 @SaIgnore,则忽略掉鉴权
|
||||||
|
if (SaStrategy.me.isAnnotationPresent.apply(method, SaIgnore.class)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 注解校验
|
||||||
|
SaStrategy.me.checkMethodAnnotation.accept(method);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -173,23 +173,17 @@ public class SaTokenPathInterceptor implements Handler {
|
|||||||
|
|
||||||
//1.路径规则处理
|
//1.路径规则处理
|
||||||
SaRouter.match(includeList).notMatch(excludeList).check(r -> {
|
SaRouter.match(includeList).notMatch(excludeList).check(r -> {
|
||||||
beforeAuth.run(action);
|
//1.执行前置处理(主要是一些跨域之类的)
|
||||||
|
if(beforeAuth != null) {
|
||||||
|
beforeAuth.run(action);
|
||||||
|
}
|
||||||
|
//2.执行注解处理
|
||||||
|
authAnno(action);
|
||||||
|
//3.执行规则处理
|
||||||
auth.run(action);
|
auth.run(action);
|
||||||
});
|
});
|
||||||
|
|
||||||
//2.验证注解处理
|
|
||||||
if(isAnnotation && action != null){
|
|
||||||
// 获取此请求对应的 Method 处理函数
|
|
||||||
Method method = action.method().getMethod();
|
|
||||||
|
|
||||||
// 如果此 Method 或其所属 Class 标注了 @SaIgnore,则忽略掉鉴权
|
|
||||||
if(SaStrategy.me.isAnnotationPresent.apply(method, SaIgnore.class)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 注解校验
|
|
||||||
SaStrategy.me.checkMethodAnnotation.accept(method);
|
|
||||||
}
|
|
||||||
} catch (StopMatchException e) {
|
} catch (StopMatchException e) {
|
||||||
|
|
||||||
} catch (SaTokenException e) {
|
} catch (SaTokenException e) {
|
||||||
@ -202,10 +196,26 @@ public class SaTokenPathInterceptor implements Handler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 2. 写入输出流
|
// 2. 写入输出流
|
||||||
if(result != null) {
|
if (result != null) {
|
||||||
ctx.render(result);
|
ctx.render(result);
|
||||||
}
|
}
|
||||||
ctx.setHandled(true);
|
ctx.setHandled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void authAnno(Action action) {
|
||||||
|
//2.验证注解处理
|
||||||
|
if (isAnnotation && action != null) {
|
||||||
|
// 获取此请求对应的 Method 处理函数
|
||||||
|
Method method = action.method().getMethod();
|
||||||
|
|
||||||
|
// 如果此 Method 或其所属 Class 标注了 @SaIgnore,则忽略掉鉴权
|
||||||
|
if (SaStrategy.me.isAnnotationPresent.apply(method, SaIgnore.class)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 注解校验
|
||||||
|
SaStrategy.me.checkMethodAnnotation.accept(method);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user