refactor: 登录参数与注销参数代码细节优化

This commit is contained in:
click33 2025-03-19 08:09:49 +08:00
parent 75df0597a0
commit 937844f4f6
4 changed files with 15 additions and 12 deletions

View File

@ -35,7 +35,7 @@ import cn.dev33.satoken.stp.parameter.SaLoginParameter;
import cn.dev33.satoken.stp.parameter.SaLogoutParameter;
import cn.dev33.satoken.stp.parameter.enums.SaLogoutMode;
import cn.dev33.satoken.stp.parameter.enums.SaLogoutRange;
import cn.dev33.satoken.stp.parameter.enums.SaReplacedMode;
import cn.dev33.satoken.stp.parameter.enums.SaReplacedRange;
import cn.dev33.satoken.strategy.SaStrategy;
import cn.dev33.satoken.util.SaFoxUtil;
import cn.dev33.satoken.util.SaTokenConsts;
@ -523,10 +523,10 @@ public class StpLogic {
// 1获取全局配置的 isConcurrent 参数
// 如果配置为不允许一个账号多地同时登录则需要先将这个账号的历史登录会话标记为被顶下线
if( ! loginParameter.getIsConcurrent()) {
if(loginParameter.getReplacedMode() == SaReplacedMode.CURR_DEVICE_TYPE) {
if(loginParameter.getReplacedRange() == SaReplacedRange.CURR_DEVICE_TYPE) {
replaced(id, loginParameter.getDeviceTypeOrDefault());
}
if(loginParameter.getReplacedMode() == SaReplacedMode.ALL_DEVICE_TYPE) {
if(loginParameter.getReplacedRange() == SaReplacedRange.ALL_DEVICE_TYPE) {
replaced(id, createSaLogoutParameter());
}
}

View File

@ -19,7 +19,7 @@ import cn.dev33.satoken.SaManager;
import cn.dev33.satoken.config.SaTokenConfig;
import cn.dev33.satoken.dao.SaTokenDao;
import cn.dev33.satoken.stp.parameter.enums.SaLogoutMode;
import cn.dev33.satoken.stp.parameter.enums.SaReplacedMode;
import cn.dev33.satoken.stp.parameter.enums.SaReplacedRange;
import cn.dev33.satoken.util.SaTokenConsts;
import java.util.LinkedHashMap;
@ -53,7 +53,7 @@ public class SaLoginParameter {
/**
* 顶人下线的范围
*/
private SaReplacedMode replacedMode = SaReplacedMode.CURR_DEVICE_TYPE;
private SaReplacedRange replacedRange = SaReplacedRange.CURR_DEVICE_TYPE;
/**
* 溢出 maxLoginCount 的客户端将以何种方式注销下线
@ -291,18 +291,18 @@ public class SaLoginParameter {
*
* @return replacedMode 顶人下线的范围
*/
public SaReplacedMode getReplacedMode() {
return this.replacedMode;
public SaReplacedRange getReplacedRange() {
return this.replacedRange;
}
/**
* 设置 顶人下线的范围
*
* @param replacedMode /
* @param replacedRange /
* @return 对象自身
*/
public SaLoginParameter setReplacedMode(SaReplacedMode replacedMode) {
this.replacedMode = replacedMode;
public SaLoginParameter setReplacedRange(SaReplacedRange replacedRange) {
this.replacedRange = replacedRange;
return this;
}
@ -513,7 +513,7 @@ public class SaLoginParameter {
return "SaLoginParameter ["
+ "deviceType=" + deviceType
+ ", deviceId=" + deviceId
+ ", replacedMode=" + replacedMode
+ ", replacedRange=" + replacedRange
+ ", overflowLogoutMode=" + overflowLogoutMode
+ ", isLastingCookie=" + isLastingCookie
+ ", timeout=" + timeout

View File

@ -40,6 +40,7 @@ public class SaLogoutParameter {
/**
* 如果 token 已被冻结是否保留其操作权 (是否允许此 token 调用注销API)
* (此参数只在调用 StpUtil.[logout/kickout/replaced]ByTokenValue("xxxxxxxxxxxxxxxxxxx", new SaLogoutParameter()) 时有效)
*/
private Boolean isKeepFreezeOps = false;
@ -109,6 +110,7 @@ public class SaLogoutParameter {
/**
* 获取 如果 token 已被冻结是否保留其操作权 (是否允许此 token 调用注销API)
* (此参数只在调用 StpUtil.[logout/kickout/replaced]ByTokenValue("xxxxxxxxxxxxxxxxxxx", new SaLogoutParameter()) 时有效)
*
* @return /
*/
@ -118,6 +120,7 @@ public class SaLogoutParameter {
/**
* 设置 如果 token 已被冻结是否保留其操作权 (是否允许此 token 调用注销API)
* (此参数只在调用 StpUtil.[logout/kickout/replaced]ByTokenValue("xxxxxxxxxxxxxxxxxxx", new SaLogoutParameter()) 时有效)
*
* @param isKeepFreezeOps /
* @return 对象自身

View File

@ -21,7 +21,7 @@ package cn.dev33.satoken.stp.parameter.enums;
* @author click33
* @since 1.41.0
*/
public enum SaReplacedMode {
public enum SaReplacedRange {
/**
* 当前指定的设备类型端