mirror of
https://gitee.com/dromara/sa-token.git
synced 2026-02-27 16:50:24 +08:00
新增二级Context模式
This commit is contained in:
@@ -15,6 +15,7 @@ import cn.dev33.satoken.annotation.SaCheckSafe;
|
||||
import cn.dev33.satoken.basic.SaBasicTemplate;
|
||||
import cn.dev33.satoken.basic.SaBasicUtil;
|
||||
import cn.dev33.satoken.config.SaTokenConfig;
|
||||
import cn.dev33.satoken.context.second.SaTokenSecondContextCreator;
|
||||
import cn.dev33.satoken.dao.SaTokenDao;
|
||||
import cn.dev33.satoken.id.SaIdTemplate;
|
||||
import cn.dev33.satoken.id.SaIdUtil;
|
||||
@@ -49,9 +50,15 @@ public class XPluginImp implements Plugin {
|
||||
SaTokenConfig saTokenConfig = Solon.cfg().getBean("sa-token", SaTokenConfig.class);
|
||||
SaManager.setConfig(saTokenConfig);
|
||||
|
||||
//注入容器交互Bean
|
||||
// 注入上下文Bean
|
||||
SaManager.setSaTokenContext(new SaContextForSolon());
|
||||
|
||||
// 注入二级上下文 Bean
|
||||
Aop.getAsyn(SaTokenSecondContextCreator.class, bw->{
|
||||
SaTokenSecondContextCreator raw = bw.raw();
|
||||
SaManager.setSaTokenSecondContext(raw.create());
|
||||
});
|
||||
|
||||
// 注入侦听器 Bean
|
||||
Aop.getAsyn(SaTokenListener.class, bw->{
|
||||
SaManager.setSaTokenListener(bw.raw());
|
||||
|
||||
@@ -7,6 +7,8 @@ import cn.dev33.satoken.context.model.SaStorage;
|
||||
import cn.dev33.satoken.solon.model.SaRequestForSolon;
|
||||
import cn.dev33.satoken.solon.model.SaResponseForSolon;
|
||||
import cn.dev33.satoken.solon.model.SaStorageForSolon;
|
||||
|
||||
import org.noear.solon.core.handle.Context;
|
||||
import org.noear.solon.core.util.PathAnalyzer;
|
||||
|
||||
/**
|
||||
@@ -45,4 +47,13 @@ public class SaContextForSolon implements SaTokenContext {
|
||||
public boolean matchPath(String pattern, String path) {
|
||||
return PathAnalyzer.get(pattern).matches(path);
|
||||
}
|
||||
|
||||
/**
|
||||
* 此上下文是否有效
|
||||
* @return /
|
||||
*/
|
||||
public boolean isValid() {
|
||||
return Context.current() != null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user