mirror of
https://gitee.com/dromara/sa-token.git
synced 2025-06-28 13:34:18 +08:00
sa-token-solon-plugin:升级 solon 为 1.9.2; 优化 SaTokenPathInterceptor 同时支持注解、路径、规则处理
This commit is contained in:
parent
81e0403272
commit
05a9d40151
@ -18,7 +18,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.noear</groupId>
|
<groupId>org.noear</groupId>
|
||||||
<artifactId>solon-web</artifactId>
|
<artifactId>solon-web</artifactId>
|
||||||
<version>1.10.0</version>
|
<version>1.10.4</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- Sa-Token 权限认证, 在线文档:http://sa-token.dev33.cn/ -->
|
<!-- Sa-Token 权限认证, 在线文档:http://sa-token.dev33.cn/ -->
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.noear</groupId>
|
<groupId>org.noear</groupId>
|
||||||
<artifactId>solon</artifactId>
|
<artifactId>solon</artifactId>
|
||||||
<version>1.10.0</version>
|
<version>1.10.4</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
|
@ -71,10 +71,11 @@ public class XPluginImp implements Plugin {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// 注入侦听器 Bean
|
// 注入侦听器 Bean
|
||||||
EventBus.subscribe(SaTokenListener.class, bw->{
|
context.subBean(SaTokenListener.class, sl->{
|
||||||
SaTokenEventCenter.registerListener(bw);
|
SaTokenEventCenter.registerListener(sl);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
// 注入权限认证 Bean
|
// 注入权限认证 Bean
|
||||||
context.getWrapAsyn(StpInterface.class, bw->{
|
context.getWrapAsyn(StpInterface.class, bw->{
|
||||||
SaManager.setStpInterface(bw.raw());
|
SaManager.setStpInterface(bw.raw());
|
||||||
|
@ -1,24 +1,40 @@
|
|||||||
package cn.dev33.satoken.solon.integration;
|
package cn.dev33.satoken.solon.integration;
|
||||||
|
|
||||||
|
import cn.dev33.satoken.annotation.SaIgnore;
|
||||||
|
import cn.dev33.satoken.strategy.SaStrategy;
|
||||||
import org.noear.solon.core.aspect.Interceptor;
|
import org.noear.solon.core.aspect.Interceptor;
|
||||||
import org.noear.solon.core.aspect.Invocation;
|
import org.noear.solon.core.aspect.Invocation;
|
||||||
|
import org.noear.solon.core.handle.Context;
|
||||||
|
|
||||||
import cn.dev33.satoken.strategy.SaStrategy;
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author noear
|
* @author noear
|
||||||
* @since 1.4
|
* @since 1.4
|
||||||
|
* @deprecated 1.10,改用 SaTokenPathInterceptor
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public class SaTokenAnnotationInterceptor implements Interceptor {
|
public class SaTokenAnnotationInterceptor implements Interceptor {
|
||||||
|
|
||||||
public static final SaTokenAnnotationInterceptor INSTANCE = new SaTokenAnnotationInterceptor();
|
public static final SaTokenAnnotationInterceptor INSTANCE = new SaTokenAnnotationInterceptor();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object doIntercept(Invocation inv) throws Throwable {
|
public Object doIntercept(Invocation inv) throws Throwable {
|
||||||
// 注解鉴权
|
// 如果此 Method 或其所属 Class 标注了 @SaIgnore,则忽略掉鉴权
|
||||||
SaStrategy.me.checkMethodAnnotation.accept(inv.method().getMethod());
|
Context ctx = Context.current();
|
||||||
|
|
||||||
|
if (ctx != null && "1".equals(ctx.attr("_SaTokenPathInterceptor"))) {
|
||||||
|
// 执行原有逻辑
|
||||||
|
return inv.invoke();
|
||||||
|
} else {
|
||||||
|
|
||||||
|
Method method = inv.method().getMethod();
|
||||||
|
if (SaStrategy.me.isAnnotationPresent.apply(method, SaIgnore.class) == false) {
|
||||||
|
SaStrategy.me.checkMethodAnnotation.accept(method);
|
||||||
|
}
|
||||||
|
|
||||||
// 执行原有逻辑
|
// 执行原有逻辑
|
||||||
return inv.invoke();
|
return inv.invoke();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@ -16,9 +16,14 @@ import java.util.Arrays;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* sa-token 基于路由的过滤式鉴权( +SaTokenAnnotationInterceptor )
|
||||||
|
*
|
||||||
* @author noear
|
* @author noear
|
||||||
* @since 1.9
|
* @since 1.9
|
||||||
|
* @deprecated 1.10,改用 SaTokenPathInterceptor
|
||||||
|
* @see SaTokenPathInterceptor
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public class SaTokenPathFilter implements Filter {
|
public class SaTokenPathFilter implements Filter {
|
||||||
|
|
||||||
// ------------------------ 设置此过滤器 拦截 & 放行 的路由
|
// ------------------------ 设置此过滤器 拦截 & 放行 的路由
|
||||||
|
@ -1,23 +1,35 @@
|
|||||||
package cn.dev33.satoken.solon.integration;
|
package cn.dev33.satoken.solon.integration;
|
||||||
|
|
||||||
|
import cn.dev33.satoken.annotation.SaIgnore;
|
||||||
import cn.dev33.satoken.exception.BackResultException;
|
import cn.dev33.satoken.exception.BackResultException;
|
||||||
import cn.dev33.satoken.exception.SaTokenException;
|
import cn.dev33.satoken.exception.SaTokenException;
|
||||||
import cn.dev33.satoken.exception.StopMatchException;
|
import cn.dev33.satoken.exception.StopMatchException;
|
||||||
import cn.dev33.satoken.filter.SaFilterAuthStrategy;
|
import cn.dev33.satoken.filter.SaFilterAuthStrategy;
|
||||||
import cn.dev33.satoken.filter.SaFilterErrorStrategy;
|
import cn.dev33.satoken.filter.SaFilterErrorStrategy;
|
||||||
import cn.dev33.satoken.router.SaRouter;
|
import cn.dev33.satoken.router.SaRouter;
|
||||||
|
import cn.dev33.satoken.strategy.SaStrategy;
|
||||||
|
import org.noear.solon.core.handle.Action;
|
||||||
import org.noear.solon.core.handle.Context;
|
import org.noear.solon.core.handle.Context;
|
||||||
import org.noear.solon.core.handle.Handler;
|
import org.noear.solon.core.handle.Handler;
|
||||||
|
|
||||||
|
import java.lang.reflect.Method;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* sa-token基于路由的拦截式鉴权
|
* sa-token 基于路由的拦截式鉴权(增加了注解的处理)
|
||||||
|
*
|
||||||
* @author kong
|
* @author kong
|
||||||
|
* @since 1.9
|
||||||
|
* @author noear
|
||||||
|
* @since 1.10
|
||||||
*/
|
*/
|
||||||
public class SaTokenPathInterceptor implements Handler {
|
public class SaTokenPathInterceptor implements Handler {
|
||||||
|
/**
|
||||||
|
* 是否打开注解鉴权
|
||||||
|
*/
|
||||||
|
public boolean isAnnotation = true;
|
||||||
|
|
||||||
// ------------------------ 设置此过滤器 拦截 & 放行 的路由
|
// ------------------------ 设置此过滤器 拦截 & 放行 的路由
|
||||||
|
|
||||||
@ -156,10 +168,30 @@ public class SaTokenPathInterceptor implements Handler {
|
|||||||
@Override
|
@Override
|
||||||
public void handle(Context ctx) throws Throwable {
|
public void handle(Context ctx) throws Throwable {
|
||||||
try {
|
try {
|
||||||
// 执行全局过滤器
|
//注处处理
|
||||||
|
Action action = ctx.action();
|
||||||
|
|
||||||
|
if(isAnnotation && action != null){
|
||||||
|
ctx.attrSet("_SaTokenPathInterceptor", "1");
|
||||||
|
|
||||||
|
// 获取此请求对应的 Method 处理函数
|
||||||
|
Method method = action.method().getMethod();
|
||||||
|
|
||||||
|
// 如果此 Method 或其所属 Class 标注了 @SaIgnore,则忽略掉鉴权
|
||||||
|
if(SaStrategy.me.isAnnotationPresent.apply(method, SaIgnore.class)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 注解校验
|
||||||
|
SaStrategy.me.checkMethodAnnotation.accept(method);
|
||||||
|
}else{
|
||||||
|
ctx.attrSet("_SaTokenPathInterceptor", "0");
|
||||||
|
}
|
||||||
|
|
||||||
|
//路径规则处理
|
||||||
SaRouter.match(includeList).notMatch(excludeList).check(r -> {
|
SaRouter.match(includeList).notMatch(excludeList).check(r -> {
|
||||||
beforeAuth.run(null);
|
beforeAuth.run(action);
|
||||||
auth.run(null);
|
auth.run(action);
|
||||||
});
|
});
|
||||||
|
|
||||||
} catch (StopMatchException e) {
|
} catch (StopMatchException e) {
|
||||||
|
@ -1,12 +1,11 @@
|
|||||||
package cn.dev33.satoken.solon.model;
|
package cn.dev33.satoken.solon.model;
|
||||||
|
|
||||||
import org.noear.solon.core.handle.Context;
|
|
||||||
import org.noear.solon.core.util.PathAnalyzer;
|
|
||||||
|
|
||||||
import cn.dev33.satoken.context.SaTokenContext;
|
import cn.dev33.satoken.context.SaTokenContext;
|
||||||
import cn.dev33.satoken.context.model.SaRequest;
|
import cn.dev33.satoken.context.model.SaRequest;
|
||||||
import cn.dev33.satoken.context.model.SaResponse;
|
import cn.dev33.satoken.context.model.SaResponse;
|
||||||
import cn.dev33.satoken.context.model.SaStorage;
|
import cn.dev33.satoken.context.model.SaStorage;
|
||||||
|
import org.noear.solon.core.handle.Context;
|
||||||
|
import org.noear.solon.core.util.PathAnalyzer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author noear
|
* @author noear
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
package cn.dev33.satoken.solon.model;
|
package cn.dev33.satoken.solon.model;
|
||||||
|
|
||||||
import org.noear.solon.core.handle.Context;
|
|
||||||
|
|
||||||
import cn.dev33.satoken.SaManager;
|
import cn.dev33.satoken.SaManager;
|
||||||
import cn.dev33.satoken.context.model.SaRequest;
|
import cn.dev33.satoken.context.model.SaRequest;
|
||||||
import cn.dev33.satoken.util.SaFoxUtil;
|
import cn.dev33.satoken.util.SaFoxUtil;
|
||||||
|
import org.noear.solon.core.handle.Context;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author noear
|
* @author noear
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
package cn.dev33.satoken.solon.model;
|
package cn.dev33.satoken.solon.model;
|
||||||
|
|
||||||
import org.noear.solon.core.handle.Context;
|
|
||||||
|
|
||||||
import cn.dev33.satoken.context.model.SaResponse;
|
import cn.dev33.satoken.context.model.SaResponse;
|
||||||
|
import org.noear.solon.core.handle.Context;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author noear
|
* @author noear
|
||||||
|
Loading…
Reference in New Issue
Block a user