mirror of
https://gitee.com/dromara/sa-token.git
synced 2025-04-05 17:37:53 +08:00
StpLogic 的创建转移到 SaStrategy 全局策略中
This commit is contained in:
parent
a66cd032a6
commit
bacdc37466
@ -285,6 +285,13 @@ public class SaManager {
|
||||
stpLogicMap.put(stpLogic.getLoginType(), stpLogic);
|
||||
}
|
||||
|
||||
/**
|
||||
* 在全局集合中 移除 一个 StpLogic
|
||||
*/
|
||||
public static void removeStpLogic(String loginType) {
|
||||
stpLogicMap.remove(loginType);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据 LoginType 获取对应的StpLogic,如果不存在则新建并返回
|
||||
* @param loginType 对应的账号类型
|
||||
|
@ -67,10 +67,7 @@ public class StpLogic {
|
||||
* @param loginType 账号类型标识
|
||||
*/
|
||||
public StpLogic(String loginType) {
|
||||
this.loginType = loginType;
|
||||
|
||||
// 在 SaManager 中记录下此 StpLogic,以便后续根据 LoginType 进行查找此对象
|
||||
SaManager.putStpLogic(this);
|
||||
setLoginType(loginType);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -89,9 +86,16 @@ public class StpLogic {
|
||||
* @return 对象自身
|
||||
*/
|
||||
public StpLogic setLoginType(String loginType){
|
||||
|
||||
// 先清除此 StpLogic 在全局 SaManager 中的记录
|
||||
if(SaFoxUtil.isNotEmpty(this.loginType)) {
|
||||
SaManager.removeStpLogic(this.loginType);
|
||||
}
|
||||
|
||||
// 赋值
|
||||
this.loginType = loginType;
|
||||
|
||||
// 因为 loginType 变了,所以需要往 SaManager 中重新 put 一下
|
||||
// 将新的 loginType -> StpLogic 映射关系 put 到 SaManager 全局集合中,以便后续根据 LoginType 进行查找此对象
|
||||
SaManager.putStpLogic(this);
|
||||
|
||||
return this;
|
||||
|
@ -40,7 +40,7 @@ public class StpUtil {
|
||||
/**
|
||||
* 底层使用的 StpLogic 对象
|
||||
*/
|
||||
public static StpLogic stpLogic = new StpLogic(TYPE);
|
||||
public static StpLogic stpLogic = SaManager.getStpLogic(TYPE);
|
||||
|
||||
/**
|
||||
* 获取当前 StpLogic 的账号类型
|
||||
|
@ -21,6 +21,7 @@ import cn.dev33.satoken.basic.SaBasicUtil;
|
||||
import cn.dev33.satoken.exception.SaTokenException;
|
||||
import cn.dev33.satoken.fun.SaGenerateUniqueTokenFunction;
|
||||
import cn.dev33.satoken.session.SaSession;
|
||||
import cn.dev33.satoken.stp.StpLogic;
|
||||
import cn.dev33.satoken.util.SaFoxUtil;
|
||||
import cn.dev33.satoken.util.SaTokenConsts;
|
||||
|
||||
@ -240,6 +241,15 @@ public final class SaStrategy {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 创建 StpLogic 的算法
|
||||
*
|
||||
* <p> 参数 [ 账号体系标识 ]
|
||||
*/
|
||||
public Function<String, StpLogic> createStpLogic = (loginType) -> {
|
||||
return new StpLogic(loginType);
|
||||
};
|
||||
|
||||
|
||||
// ----------------------- 重写策略 set连缀风格
|
||||
|
||||
@ -332,4 +342,17 @@ public final class SaStrategy {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建 StpLogic 的算法
|
||||
*
|
||||
* <p> 参数 [ 账号体系标识 ]
|
||||
*
|
||||
* @param createStpLogic /
|
||||
* @return 对象自身
|
||||
*/
|
||||
public SaStrategy setCreateStpLogic(Function<String, StpLogic> createStpLogic) {
|
||||
this.createStpLogic = createStpLogic;
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user