mirror of
https://gitee.com/dromara/sa-token.git
synced 2025-05-07 22:27:56 +08:00
!188 sa-token-solon-plugin:升级 solon 为 1.10.9
Merge pull request !188 from 西东/dev
This commit is contained in:
commit
78d63d8724
2
pom.xml
2
pom.xml
@ -50,7 +50,7 @@
|
|||||||
<jackson-datatype-jsr310.version>2.11.2</jackson-datatype-jsr310.version>
|
<jackson-datatype-jsr310.version>2.11.2</jackson-datatype-jsr310.version>
|
||||||
<servlet-api.version>3.1.0</servlet-api.version>
|
<servlet-api.version>3.1.0</servlet-api.version>
|
||||||
<thymeleaf.version>3.0.9.RELEASE</thymeleaf.version>
|
<thymeleaf.version>3.0.9.RELEASE</thymeleaf.version>
|
||||||
<solon.version>1.10.4</solon.version>
|
<solon.version>1.10.9</solon.version>
|
||||||
<solon-test.version>1.9.1</solon-test.version>
|
<solon-test.version>1.9.1</solon-test.version>
|
||||||
<noear-redisx.version>1.4.3</noear-redisx.version>
|
<noear-redisx.version>1.4.3</noear-redisx.version>
|
||||||
<jfinal.version>4.9.17</jfinal.version>
|
<jfinal.version>4.9.17</jfinal.version>
|
||||||
|
@ -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.4</version>
|
<version>${solon.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- Sa-Token 权限认证, 在线文档:https://sa-token.cc/ -->
|
<!-- Sa-Token 权限认证, 在线文档:https://sa-token.cc/ -->
|
||||||
|
@ -5,12 +5,6 @@ import org.noear.solon.core.AopContext;
|
|||||||
import org.noear.solon.core.Plugin;
|
import org.noear.solon.core.Plugin;
|
||||||
|
|
||||||
import cn.dev33.satoken.SaManager;
|
import cn.dev33.satoken.SaManager;
|
||||||
import cn.dev33.satoken.annotation.SaCheckBasic;
|
|
||||||
import cn.dev33.satoken.annotation.SaCheckDisable;
|
|
||||||
import cn.dev33.satoken.annotation.SaCheckLogin;
|
|
||||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
|
||||||
import cn.dev33.satoken.annotation.SaCheckRole;
|
|
||||||
import cn.dev33.satoken.annotation.SaCheckSafe;
|
|
||||||
import cn.dev33.satoken.basic.SaBasicTemplate;
|
import cn.dev33.satoken.basic.SaBasicTemplate;
|
||||||
import cn.dev33.satoken.basic.SaBasicUtil;
|
import cn.dev33.satoken.basic.SaBasicUtil;
|
||||||
import cn.dev33.satoken.config.SaTokenConfig;
|
import cn.dev33.satoken.config.SaTokenConfig;
|
||||||
@ -23,7 +17,6 @@ import cn.dev33.satoken.listener.SaTokenEventCenter;
|
|||||||
import cn.dev33.satoken.listener.SaTokenListener;
|
import cn.dev33.satoken.listener.SaTokenListener;
|
||||||
import cn.dev33.satoken.same.SaSameTemplate;
|
import cn.dev33.satoken.same.SaSameTemplate;
|
||||||
import cn.dev33.satoken.sign.SaSignTemplate;
|
import cn.dev33.satoken.sign.SaSignTemplate;
|
||||||
import cn.dev33.satoken.solon.integration.SaTokenAnnotationInterceptor;
|
|
||||||
import cn.dev33.satoken.solon.model.SaContextForSolon;
|
import cn.dev33.satoken.solon.model.SaContextForSolon;
|
||||||
import cn.dev33.satoken.stp.StpInterface;
|
import cn.dev33.satoken.stp.StpInterface;
|
||||||
import cn.dev33.satoken.stp.StpLogic;
|
import cn.dev33.satoken.stp.StpLogic;
|
||||||
@ -36,16 +29,9 @@ import cn.dev33.satoken.temp.SaTempInterface;
|
|||||||
*/
|
*/
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public class XPluginImp implements Plugin {
|
public class XPluginImp implements Plugin {
|
||||||
|
|
||||||
@Override
|
|
||||||
public void start(AopContext context) {
|
|
||||||
context.beanAroundAdd(SaCheckPermission.class, SaTokenAnnotationInterceptor.INSTANCE);
|
|
||||||
context.beanAroundAdd(SaCheckRole.class, SaTokenAnnotationInterceptor.INSTANCE);
|
|
||||||
context.beanAroundAdd(SaCheckLogin.class, SaTokenAnnotationInterceptor.INSTANCE);
|
|
||||||
context.beanAroundAdd(SaCheckSafe.class, SaTokenAnnotationInterceptor.INSTANCE);
|
|
||||||
context.beanAroundAdd(SaCheckDisable.class, SaTokenAnnotationInterceptor.INSTANCE);
|
|
||||||
context.beanAroundAdd(SaCheckBasic.class, SaTokenAnnotationInterceptor.INSTANCE);
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void start(AopContext context) {
|
||||||
//集成初始化
|
//集成初始化
|
||||||
|
|
||||||
// 注入上下文Bean
|
// 注入上下文Bean
|
||||||
@ -55,72 +41,70 @@ public class XPluginImp implements Plugin {
|
|||||||
SaTokenConfig saTokenConfig = Solon.cfg().getBean("sa-token", SaTokenConfig.class);
|
SaTokenConfig saTokenConfig = Solon.cfg().getBean("sa-token", SaTokenConfig.class);
|
||||||
SaManager.setConfig(saTokenConfig);
|
SaManager.setConfig(saTokenConfig);
|
||||||
|
|
||||||
context.getWrapAsyn(SaTokenConfig.class, bw -> {
|
context.getBeanAsyn(SaTokenConfig.class, bean -> {
|
||||||
SaManager.setConfig(bw.raw());
|
SaManager.setConfig(bean);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
// 注入Dao Bean
|
// 注入Dao Bean
|
||||||
context.getWrapAsyn(SaTokenDao.class, bw -> {
|
context.getBeanAsyn(SaTokenDao.class, bean -> {
|
||||||
SaManager.setSaTokenDao(bw.raw());
|
SaManager.setSaTokenDao(bean);
|
||||||
});
|
});
|
||||||
|
|
||||||
// 注入二级上下文 Bean
|
// 注入二级上下文 Bean
|
||||||
context.getWrapAsyn(SaTokenSecondContextCreator.class, bw->{
|
context.getBeanAsyn(SaTokenSecondContextCreator.class, bean -> {
|
||||||
SaTokenSecondContextCreator raw = bw.raw();
|
SaManager.setSaTokenSecondContext(bean.create());
|
||||||
SaManager.setSaTokenSecondContext(raw.create());
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// 注入侦听器 Bean
|
// 注入侦听器 Bean
|
||||||
context.subBean(SaTokenListener.class, sl->{
|
context.subBean(SaTokenListener.class, sl -> {
|
||||||
SaTokenEventCenter.registerListener(sl);
|
SaTokenEventCenter.registerListener(sl);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
// 注入权限认证 Bean
|
// 注入权限认证 Bean
|
||||||
context.getWrapAsyn(StpInterface.class, bw->{
|
context.getBeanAsyn(StpInterface.class, bean -> {
|
||||||
SaManager.setStpInterface(bw.raw());
|
SaManager.setStpInterface(bean);
|
||||||
});
|
});
|
||||||
|
|
||||||
// 注入持久化 Bean
|
// 注入持久化 Bean
|
||||||
context.getWrapAsyn(SaTokenDao.class, bw->{
|
context.getBeanAsyn(SaTokenDao.class, bean -> {
|
||||||
SaManager.setSaTokenDao(bw.raw());
|
SaManager.setSaTokenDao(bean);
|
||||||
});
|
});
|
||||||
|
|
||||||
// 临时令牌验证模块 Bean
|
// 临时令牌验证模块 Bean
|
||||||
context.getWrapAsyn(SaTempInterface.class, bw->{
|
context.getBeanAsyn(SaTempInterface.class, bean -> {
|
||||||
SaManager.setSaTemp(bw.raw());
|
SaManager.setSaTemp(bean);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Sa-Token-Id 身份凭证模块 Bean
|
// Sa-Token-Id 身份凭证模块 Bean
|
||||||
context.getWrapAsyn(SaIdTemplate.class, bw->{
|
context.getBeanAsyn(SaIdTemplate.class, bean -> {
|
||||||
SaIdUtil.saIdTemplate = bw.raw();
|
SaIdUtil.saIdTemplate = bean;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Sa-Token Same-Token 模块 Bean
|
// Sa-Token Same-Token 模块 Bean
|
||||||
context.getWrapAsyn(SaSameTemplate.class, bw->{
|
context.getBeanAsyn(SaSameTemplate.class, bean -> {
|
||||||
SaManager.setSaSignTemplate(bw.raw());
|
SaManager.setSaSameTemplate(bean);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Sa-Token Http Basic 认证模块 Bean
|
// Sa-Token Http Basic 认证模块 Bean
|
||||||
context.getWrapAsyn(SaBasicTemplate.class, bw->{
|
context.getBeanAsyn(SaBasicTemplate.class, bean -> {
|
||||||
SaBasicUtil.saBasicTemplate = bw.raw();
|
SaBasicUtil.saBasicTemplate = bean;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Sa-Token JSON 转换器 Bean
|
// Sa-Token JSON 转换器 Bean
|
||||||
context.getWrapAsyn(SaJsonTemplate.class, bw->{
|
context.getBeanAsyn(SaJsonTemplate.class, bean -> {
|
||||||
SaManager.setSaJsonTemplate(bw.raw());
|
SaManager.setSaJsonTemplate(bean);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Sa-Token 参数签名算法 Bean
|
// Sa-Token 参数签名算法 Bean
|
||||||
context.getWrapAsyn(SaSignTemplate.class, bw->{
|
context.getBeanAsyn(SaSignTemplate.class, bean -> {
|
||||||
SaManager.setSaSignTemplate(bw.raw());
|
SaManager.setSaSignTemplate(bean);
|
||||||
});
|
});
|
||||||
|
|
||||||
// 自定义 StpLogic 对象
|
// 自定义 StpLogic 对象
|
||||||
context.getWrapAsyn(StpLogic.class, bw->{
|
context.getBeanAsyn(StpLogic.class, bean -> {
|
||||||
StpUtil.setStpLogic(bw.raw());
|
StpUtil.setStpLogic(bean);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -1,40 +0,0 @@
|
|||||||
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.Invocation;
|
|
||||||
import org.noear.solon.core.handle.Context;
|
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author noear
|
|
||||||
* @since 1.4
|
|
||||||
* @deprecated 1.10,改用 SaTokenPathInterceptor
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public class SaTokenAnnotationInterceptor implements Interceptor {
|
|
||||||
|
|
||||||
public static final SaTokenAnnotationInterceptor INSTANCE = new SaTokenAnnotationInterceptor();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object doIntercept(Invocation inv) throws Throwable {
|
|
||||||
// 如果此 Method 或其所属 Class 标注了 @SaIgnore,则忽略掉鉴权
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,197 +1,215 @@
|
|||||||
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 org.noear.solon.Utils;
|
import cn.dev33.satoken.strategy.SaStrategy;
|
||||||
import org.noear.solon.core.handle.Context;
|
import org.noear.solon.Solon;
|
||||||
import org.noear.solon.core.handle.Filter;
|
import org.noear.solon.core.handle.*;
|
||||||
import org.noear.solon.core.handle.FilterChain;
|
|
||||||
|
|
||||||
|
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 基于路由的过滤式鉴权( +SaTokenAnnotationInterceptor )
|
* sa-token 基于路由的过滤式鉴权(增加了注解的处理);使用优先级要低些
|
||||||
*
|
*
|
||||||
* @author noear
|
* @author noear
|
||||||
* @since 1.9
|
* @since 1.10
|
||||||
* @deprecated 1.10,改用 SaTokenPathInterceptor
|
|
||||||
* @see SaTokenPathInterceptor
|
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
|
||||||
public class SaTokenPathFilter implements Filter {
|
public class SaTokenPathFilter implements Filter {
|
||||||
|
/**
|
||||||
|
* 是否打开注解鉴权
|
||||||
|
*/
|
||||||
|
public boolean isAnnotation = true;
|
||||||
|
|
||||||
// ------------------------ 设置此过滤器 拦截 & 放行 的路由
|
// ------------------------ 设置此过滤器 拦截 & 放行 的路由
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 拦截路由
|
* 拦截路由
|
||||||
*/
|
*/
|
||||||
protected List<String> includeList = new ArrayList<>();
|
protected List<String> includeList = new ArrayList<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 放行路由
|
* 放行路由
|
||||||
*/
|
*/
|
||||||
protected List<String> excludeList = new ArrayList<>();
|
protected List<String> excludeList = new ArrayList<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加 [拦截路由]
|
* 添加 [拦截路由]
|
||||||
*
|
*
|
||||||
* @param paths 路由
|
* @param paths 路由
|
||||||
* @return 对象自身
|
* @return 对象自身
|
||||||
*/
|
*/
|
||||||
public SaTokenPathFilter addInclude(String... paths) {
|
public SaTokenPathFilter addInclude(String... paths) {
|
||||||
includeList.addAll(Arrays.asList(paths));
|
includeList.addAll(Arrays.asList(paths));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加 [放行路由]
|
* 添加 [放行路由]
|
||||||
*
|
*
|
||||||
* @param paths 路由
|
* @param paths 路由
|
||||||
* @return 对象自身
|
* @return 对象自身
|
||||||
*/
|
*/
|
||||||
public SaTokenPathFilter addExclude(String... paths) {
|
public SaTokenPathFilter addExclude(String... paths) {
|
||||||
excludeList.addAll(Arrays.asList(paths));
|
excludeList.addAll(Arrays.asList(paths));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 写入 [拦截路由] 集合
|
* 写入 [拦截路由] 集合
|
||||||
*
|
*
|
||||||
* @param pathList 路由集合
|
* @param pathList 路由集合
|
||||||
* @return 对象自身
|
* @return 对象自身
|
||||||
*/
|
*/
|
||||||
public SaTokenPathFilter setIncludeList(List<String> pathList) {
|
public SaTokenPathFilter setIncludeList(List<String> pathList) {
|
||||||
includeList = pathList;
|
includeList = pathList;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 写入 [放行路由] 集合
|
* 写入 [放行路由] 集合
|
||||||
*
|
*
|
||||||
* @param pathList 路由集合
|
* @param pathList 路由集合
|
||||||
* @return 对象自身
|
* @return 对象自身
|
||||||
*/
|
*/
|
||||||
public SaTokenPathFilter setExcludeList(List<String> pathList) {
|
public SaTokenPathFilter setExcludeList(List<String> pathList) {
|
||||||
excludeList = pathList;
|
excludeList = pathList;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取 [拦截路由] 集合
|
* 获取 [拦截路由] 集合
|
||||||
*
|
*
|
||||||
* @return see note
|
* @return see note
|
||||||
*/
|
*/
|
||||||
public List<String> getIncludeList() {
|
public List<String> getIncludeList() {
|
||||||
return includeList;
|
return includeList;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取 [放行路由] 集合
|
* 获取 [放行路由] 集合
|
||||||
*
|
*
|
||||||
* @return see note
|
* @return see note
|
||||||
*/
|
*/
|
||||||
public List<String> getExcludeList() {
|
public List<String> getExcludeList() {
|
||||||
return excludeList;
|
return excludeList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ------------------------ 钩子函数
|
// ------------------------ 钩子函数
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 认证函数:每次请求执行
|
* 认证函数:每次请求执行
|
||||||
*/
|
*/
|
||||||
protected SaFilterAuthStrategy auth = r -> {
|
protected SaFilterAuthStrategy auth = r -> {
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 异常处理函数:每次[认证函数]发生异常时执行此函数
|
* 异常处理函数:每次[认证函数]发生异常时执行此函数
|
||||||
*/
|
*/
|
||||||
protected SaFilterErrorStrategy error = e -> {
|
protected SaFilterErrorStrategy error = e -> {
|
||||||
if (e instanceof SaTokenException) {
|
if (e instanceof SaTokenException) {
|
||||||
throw (SaTokenException) e;
|
throw (SaTokenException) e;
|
||||||
} else {
|
} else {
|
||||||
throw new SaTokenException(e);
|
throw new SaTokenException(e);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 前置函数:在每次[认证函数]之前执行
|
* 前置函数:在每次[认证函数]之前执行
|
||||||
*/
|
*/
|
||||||
protected SaFilterAuthStrategy beforeAuth = r -> {
|
protected SaFilterAuthStrategy beforeAuth = r -> {
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 写入[认证函数]: 每次请求执行
|
* 写入[认证函数]: 每次请求执行
|
||||||
*
|
*
|
||||||
* @param auth see note
|
* @param auth see note
|
||||||
* @return 对象自身
|
* @return 对象自身
|
||||||
*/
|
*/
|
||||||
public SaTokenPathFilter setAuth(SaFilterAuthStrategy auth) {
|
public SaTokenPathFilter setAuth(SaFilterAuthStrategy auth) {
|
||||||
this.auth = auth;
|
this.auth = auth;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 写入[异常处理函数]:每次[认证函数]发生异常时执行此函数
|
* 写入[异常处理函数]:每次[认证函数]发生异常时执行此函数
|
||||||
*
|
*
|
||||||
* @param error see note
|
* @param error see note
|
||||||
* @return 对象自身
|
* @return 对象自身
|
||||||
*/
|
*/
|
||||||
public SaTokenPathFilter setError(SaFilterErrorStrategy error) {
|
public SaTokenPathFilter setError(SaFilterErrorStrategy error) {
|
||||||
this.error = error;
|
this.error = error;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 写入[前置函数]:在每次[认证函数]之前执行
|
* 写入[前置函数]:在每次[认证函数]之前执行
|
||||||
*
|
*
|
||||||
* @param beforeAuth see note
|
* @param beforeAuth see note
|
||||||
* @return 对象自身
|
* @return 对象自身
|
||||||
*/
|
*/
|
||||||
public SaTokenPathFilter setBeforeAuth(SaFilterAuthStrategy beforeAuth) {
|
public SaTokenPathFilter setBeforeAuth(SaFilterAuthStrategy beforeAuth) {
|
||||||
this.beforeAuth = beforeAuth;
|
this.beforeAuth = beforeAuth;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void doFilter(Context ctx, FilterChain chain) throws Throwable {
|
public void doFilter(Context ctx, FilterChain chain) throws Throwable {
|
||||||
try {
|
try {
|
||||||
// 执行全局过滤器
|
//查找当前主处理
|
||||||
SaRouter.match(includeList).notMatch(excludeList).check(r -> {
|
Handler mainHandler = Solon.app().router().matchMain(ctx);
|
||||||
beforeAuth.run(null);
|
|
||||||
auth.run(null);
|
|
||||||
});
|
|
||||||
|
|
||||||
} catch (StopMatchException e) {
|
//如果是静态文件,则不处理(静态文件,不在路由中)
|
||||||
|
if (mainHandler != null) {
|
||||||
|
Action action = (mainHandler instanceof Action ? (Action) mainHandler : null);
|
||||||
|
|
||||||
} catch (SaTokenException e) {
|
if (isAnnotation && action != null) {
|
||||||
// 1. 获取异常处理策略结果
|
// 获取此请求对应的 Method 处理函数
|
||||||
Object result;
|
Method method = action.method().getMethod();
|
||||||
if (e instanceof BackResultException) {
|
|
||||||
result = e.getMessage();
|
|
||||||
} else {
|
|
||||||
result = error.run(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 2. 写入输出流
|
// 如果此 Method 或其所属 Class 标注了 @SaIgnore,则忽略掉鉴权
|
||||||
if(result != null) {
|
if (SaStrategy.me.isAnnotationPresent.apply(method, SaIgnore.class)) {
|
||||||
ctx.render(result);
|
return;
|
||||||
}
|
}
|
||||||
ctx.setHandled(true);
|
|
||||||
return;
|
|
||||||
} catch (Throwable e) {
|
|
||||||
// 异常解包
|
|
||||||
throw Utils.throwableUnwrap(e); //solon 的最后层还有保底处理
|
|
||||||
}
|
|
||||||
|
|
||||||
// 执行
|
// 注解校验
|
||||||
chain.doFilter(ctx);
|
SaStrategy.me.checkMethodAnnotation.accept(method);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
//路径规则处理
|
||||||
|
SaRouter.match(includeList).notMatch(excludeList).check(r -> {
|
||||||
|
beforeAuth.run(mainHandler);
|
||||||
|
auth.run(mainHandler);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (StopMatchException e) {
|
||||||
|
|
||||||
|
} catch (SaTokenException e) {
|
||||||
|
// 1. 获取异常处理策略结果
|
||||||
|
Object result;
|
||||||
|
if (e instanceof BackResultException) {
|
||||||
|
result = e.getMessage();
|
||||||
|
} else {
|
||||||
|
result = error.run(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. 写入输出流
|
||||||
|
if (result != null) {
|
||||||
|
ctx.render(result);
|
||||||
|
}
|
||||||
|
ctx.setHandled(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
chain.doFilter(ctx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -18,10 +18,8 @@ import java.util.Arrays;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* sa-token 基于路由的拦截式鉴权(增加了注解的处理)
|
* sa-token 基于路由的拦截式鉴权(增加了注解的处理);使用优先级要高些
|
||||||
*
|
*
|
||||||
* @author kong
|
|
||||||
* @since 1.9
|
|
||||||
* @author noear
|
* @author noear
|
||||||
* @since 1.10
|
* @since 1.10
|
||||||
*/
|
*/
|
||||||
@ -172,8 +170,6 @@ public class SaTokenPathInterceptor implements Handler {
|
|||||||
Action action = ctx.action();
|
Action action = ctx.action();
|
||||||
|
|
||||||
if(isAnnotation && action != null){
|
if(isAnnotation && action != null){
|
||||||
ctx.attrSet("_SaTokenPathInterceptor", "1");
|
|
||||||
|
|
||||||
// 获取此请求对应的 Method 处理函数
|
// 获取此请求对应的 Method 处理函数
|
||||||
Method method = action.method().getMethod();
|
Method method = action.method().getMethod();
|
||||||
|
|
||||||
@ -184,8 +180,6 @@ public class SaTokenPathInterceptor implements Handler {
|
|||||||
|
|
||||||
// 注解校验
|
// 注解校验
|
||||||
SaStrategy.me.checkMethodAnnotation.accept(method);
|
SaStrategy.me.checkMethodAnnotation.accept(method);
|
||||||
}else{
|
|
||||||
ctx.attrSet("_SaTokenPathInterceptor", "0");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//路径规则处理
|
//路径规则处理
|
||||||
|
Loading…
Reference in New Issue
Block a user