mirror of
https://gitee.com/dromara/sa-token.git
synced 2025-10-21 02:57:23 +08:00
feat: SaTokenConfig 新增 replacedRange、overflowLogoutMode、logoutRange、isLogoutKeepFreezeOps、isLogoutKeepTokenSession 配置项
This commit is contained in:
@@ -15,6 +15,9 @@
|
||||
*/
|
||||
package cn.dev33.satoken.config;
|
||||
|
||||
import cn.dev33.satoken.stp.parameter.enums.SaLogoutMode;
|
||||
import cn.dev33.satoken.stp.parameter.enums.SaLogoutRange;
|
||||
import cn.dev33.satoken.stp.parameter.enums.SaReplacedRange;
|
||||
import cn.dev33.satoken.util.SaFoxUtil;
|
||||
|
||||
import java.io.Serializable;
|
||||
@@ -63,11 +66,21 @@ public class SaTokenConfig implements Serializable {
|
||||
*/
|
||||
private Boolean isShare = false;
|
||||
|
||||
/**
|
||||
* 当 isConcurrent=false 时,顶人下线的范围 (CURR_DEVICE_TYPE=当前指定的设备类型端, ALL_DEVICE_TYPE=所有设备类型端)
|
||||
*/
|
||||
private SaReplacedRange replacedRange = SaReplacedRange.CURR_DEVICE_TYPE;
|
||||
|
||||
/**
|
||||
* 同一账号最大登录数量,-1代表不限 (只有在 isConcurrent=true, isShare=false 时此配置项才有意义)
|
||||
*/
|
||||
private int maxLoginCount = 12;
|
||||
|
||||
/**
|
||||
* 溢出 maxLoginCount 的客户端,将以何种方式注销下线 (LOGOUT=注销下线, KICKOUT=踢人下线, REPLACED=顶人下线)
|
||||
*/
|
||||
private SaLogoutMode overflowLogoutMode = SaLogoutMode.LOGOUT;
|
||||
|
||||
/**
|
||||
* 在每次创建 token 时的最高循环次数,用于保证 token 唯一性(-1=不循环尝试,直接使用)
|
||||
*/
|
||||
@@ -98,6 +111,23 @@ public class SaTokenConfig implements Serializable {
|
||||
*/
|
||||
private Boolean isWriteHeader = false;
|
||||
|
||||
/**
|
||||
* 注销范围 (TOKEN=只注销当前 token 的会话,ACCOUNT=注销当前 token 指向的 loginId 其所有客户端会话)
|
||||
* <br/> (此参数只在调用 StpUtil.logout() 时有效)
|
||||
*/
|
||||
private SaLogoutRange logoutRange = SaLogoutRange.TOKEN;
|
||||
|
||||
/**
|
||||
* 如果 token 已被冻结,是否保留其操作权 (是否允许此 token 调用注销API)
|
||||
* <br/> (此参数只在调用 StpUtil.[logout/kickout/replaced]ByTokenValue("token") 时有效)
|
||||
*/
|
||||
private Boolean isLogoutKeepFreezeOps = false;
|
||||
|
||||
/**
|
||||
* 在注销 token 后,是否保留其对应的 Token-Session
|
||||
*/
|
||||
private Boolean isLogoutKeepTokenSession = false;
|
||||
|
||||
/**
|
||||
* token 风格(默认可取值:uuid、simple-uuid、random-32、random-64、random-128、tik)
|
||||
*/
|
||||
@@ -669,7 +699,107 @@ public class SaTokenConfig implements Serializable {
|
||||
this.checkSameToken = checkSameToken;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取 当 isConcurrent=false 时,顶人下线的范围 (CURR_DEVICE_TYPE=当前指定的设备类型端 ALL_DEVICE_TYPE=所有设备类型端)
|
||||
*
|
||||
* @return /
|
||||
*/
|
||||
public SaReplacedRange getReplacedRange() {
|
||||
return this.replacedRange;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置 当 isConcurrent=false 时,顶人下线的范围 (CURR_DEVICE_TYPE=当前指定的设备类型端 ALL_DEVICE_TYPE=所有设备类型端)
|
||||
*
|
||||
* @param replacedRange /
|
||||
* @return 对象自身
|
||||
*/
|
||||
public SaTokenConfig setReplacedRange(SaReplacedRange replacedRange) {
|
||||
this.replacedRange = replacedRange;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 溢出 maxLoginCount 的客户端,将以何种方式注销下线 (LOGOUT=注销下线, KICKOUT=踢人下线, REPLACED=顶人下线)
|
||||
*
|
||||
* @return /
|
||||
*/
|
||||
public SaLogoutMode getOverflowLogoutMode() {
|
||||
return this.overflowLogoutMode;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置 溢出 maxLoginCount 的客户端,将以何种方式注销下线 (LOGOUT=注销下线, KICKOUT=踢人下线, REPLACED=顶人下线)
|
||||
*
|
||||
* @param overflowLogoutMode /
|
||||
* @return 对象自身
|
||||
*/
|
||||
public SaTokenConfig setOverflowLogoutMode(SaLogoutMode overflowLogoutMode) {
|
||||
this.overflowLogoutMode = overflowLogoutMode;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 注销范围 (TOKEN=只注销当前 token 的会话,ACCOUNT=注销当前 token 指向的 loginId 其所有客户端会话) <br> (此参数只在调用 StpUtil.logout() 时有效)
|
||||
*
|
||||
* @return /
|
||||
*/
|
||||
public SaLogoutRange getLogoutRange() {
|
||||
return this.logoutRange;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置 注销范围 (TOKEN=只注销当前 token 的会话,ACCOUNT=注销当前 token 指向的 loginId 其所有客户端会话) <br> (此参数只在调用 StpUtil.logout() 时有效)
|
||||
*
|
||||
* @param logoutRange /
|
||||
* @return 对象自身
|
||||
*/
|
||||
public SaTokenConfig setLogoutRange(SaLogoutRange logoutRange) {
|
||||
this.logoutRange = logoutRange;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 如果 token 已被冻结,是否保留其操作权 (是否允许此 token 调用注销API) <br> (此参数只在调用 StpUtil.[logoutkickoutreplaced]ByTokenValue("token") 时有效)
|
||||
*
|
||||
* @return isLogoutKeepFreezeOps /
|
||||
*/
|
||||
public Boolean getIsLogoutKeepFreezeOps() {
|
||||
return this.isLogoutKeepFreezeOps;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置 如果 token 已被冻结,是否保留其操作权 (是否允许此 token 调用注销API) <br> (此参数只在调用 StpUtil.[logoutkickoutreplaced]ByTokenValue("token") 时有效)
|
||||
*
|
||||
* @param isLogoutKeepFreezeOps /
|
||||
* @return 对象自身
|
||||
*/
|
||||
public SaTokenConfig setIsLogoutKeepFreezeOps(Boolean isLogoutKeepFreezeOps) {
|
||||
this.isLogoutKeepFreezeOps = isLogoutKeepFreezeOps;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 在注销 token 后,是否保留其对应的 Token-Session
|
||||
*
|
||||
* @return isLogoutKeepTokenSession /
|
||||
*/
|
||||
public Boolean getIsLogoutKeepTokenSession() {
|
||||
return this.isLogoutKeepTokenSession;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置 在注销 token 后,是否保留其对应的 Token-Session
|
||||
*
|
||||
* @param isLogoutKeepTokenSession /
|
||||
* @return 对象自身
|
||||
*/
|
||||
public SaTokenConfig setIsLogoutKeepTokenSession(Boolean isLogoutKeepTokenSession) {
|
||||
this.isLogoutKeepTokenSession = isLogoutKeepTokenSession;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Cookie 全局配置对象
|
||||
*/
|
||||
@@ -721,6 +851,8 @@ public class SaTokenConfig implements Serializable {
|
||||
this.signMany = signMany;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SaTokenConfig ["
|
||||
@@ -728,15 +860,20 @@ public class SaTokenConfig implements Serializable {
|
||||
+ ", timeout=" + timeout
|
||||
+ ", activeTimeout=" + activeTimeout
|
||||
+ ", dynamicActiveTimeout=" + dynamicActiveTimeout
|
||||
+ ", isConcurrent=" + isConcurrent
|
||||
+ ", isShare=" + isShare
|
||||
+ ", isConcurrent=" + isConcurrent
|
||||
+ ", isShare=" + isShare
|
||||
+ ", replacedRange=" + replacedRange
|
||||
+ ", maxLoginCount=" + maxLoginCount
|
||||
+ ", overflowLogoutMode=" + overflowLogoutMode
|
||||
+ ", maxTryTimes=" + maxTryTimes
|
||||
+ ", isReadBody=" + isReadBody
|
||||
+ ", isReadHeader=" + isReadHeader
|
||||
+ ", isReadCookie=" + isReadCookie
|
||||
+ ", isLastingCookie=" + isLastingCookie
|
||||
+ ", isWriteHeader=" + isWriteHeader
|
||||
+ ", logoutRange=" + logoutRange
|
||||
+ ", isLogoutKeepFreezeOps=" + isLogoutKeepFreezeOps
|
||||
+ ", isLogoutKeepTokenSession=" + isLogoutKeepTokenSession
|
||||
+ ", tokenStyle=" + tokenStyle
|
||||
+ ", dataRefreshPeriod=" + dataRefreshPeriod
|
||||
+ ", tokenSessionCheckLogin=" + tokenSessionCheckLogin
|
||||
|
@@ -50,16 +50,6 @@ public class SaLoginParameter {
|
||||
*/
|
||||
private String deviceId;
|
||||
|
||||
/**
|
||||
* 顶人下线的范围
|
||||
*/
|
||||
private SaReplacedRange replacedRange = SaReplacedRange.CURR_DEVICE_TYPE;
|
||||
|
||||
/**
|
||||
* 溢出 maxLoginCount 的客户端,将以何种方式注销下线
|
||||
*/
|
||||
private SaLogoutMode overflowLogoutMode = SaLogoutMode.LOGOUT;
|
||||
|
||||
/**
|
||||
* 扩展信息(只在 jwt 模式下生效)
|
||||
*/
|
||||
@@ -118,6 +108,16 @@ public class SaLoginParameter {
|
||||
*/
|
||||
private Boolean isWriteHeader;
|
||||
|
||||
/**
|
||||
* 当 isConcurrent=false 时,顶人下线的范围 (CURR_DEVICE_TYPE=当前指定的设备类型端, ALL_DEVICE_TYPE=所有设备类型端)
|
||||
*/
|
||||
private SaReplacedRange replacedRange;
|
||||
|
||||
/**
|
||||
* 溢出 maxLoginCount 的客户端,将以何种方式注销下线 (LOGOUT=注销下线, KICKOUT=踢人下线, REPLACED=顶人下线)
|
||||
*/
|
||||
private SaLogoutMode overflowLogoutMode;
|
||||
|
||||
|
||||
// ------ 附加方法
|
||||
|
||||
@@ -143,6 +143,8 @@ public class SaLoginParameter {
|
||||
this.maxTryTimes = config.getMaxTryTimes();
|
||||
this.isLastingCookie = config.getIsLastingCookie();
|
||||
this.isWriteHeader = config.getIsWriteHeader();
|
||||
this.replacedRange = config.getReplacedRange();
|
||||
this.overflowLogoutMode = config.getOverflowLogoutMode();
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -287,7 +289,7 @@ public class SaLoginParameter {
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 顶人下线的范围
|
||||
* 当 isConcurrent=false 时,顶人下线的范围 (CURR_DEVICE_TYPE=当前指定的设备类型端, ALL_DEVICE_TYPE=所有设备类型端)
|
||||
*
|
||||
* @return replacedMode 顶人下线的范围
|
||||
*/
|
||||
@@ -296,7 +298,7 @@ public class SaLoginParameter {
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置 顶人下线的范围
|
||||
* 当 isConcurrent=false 时,顶人下线的范围 (CURR_DEVICE_TYPE=当前指定的设备类型端, ALL_DEVICE_TYPE=所有设备类型端)
|
||||
*
|
||||
* @param replacedRange /
|
||||
* @return 对象自身
|
||||
@@ -307,7 +309,7 @@ public class SaLoginParameter {
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 溢出 maxLoginCount 的客户端,将以何种方式注销下线
|
||||
* 获取 溢出 maxLoginCount 的客户端,将以何种方式注销下线 (LOGOUT=注销下线, KICKOUT=踢人下线, REPLACED=顶人下线)
|
||||
*
|
||||
* @return overflowLogoutMode /
|
||||
*/
|
||||
@@ -316,7 +318,7 @@ public class SaLoginParameter {
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置 溢出 maxLoginCount 的客户端,将以何种方式注销下线
|
||||
* 设置 溢出 maxLoginCount 的客户端,将以何种方式注销下线 (LOGOUT=注销下线, KICKOUT=踢人下线, REPLACED=顶人下线)
|
||||
*
|
||||
* @param overflowLogoutMode /
|
||||
* @return 对象自身
|
||||
@@ -325,6 +327,7 @@ public class SaLoginParameter {
|
||||
this.overflowLogoutMode = overflowLogoutMode;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return 是否为持久Cookie(临时Cookie在浏览器关闭时会自动删除,持久Cookie在重新打开后依然存在)
|
||||
*/
|
||||
|
@@ -33,31 +33,37 @@ import cn.dev33.satoken.stp.parameter.enums.SaLogoutRange;
|
||||
*/
|
||||
public class SaLogoutParameter {
|
||||
|
||||
/**
|
||||
* 是否保留 Token-Session
|
||||
*/
|
||||
private Boolean isKeepTokenSession = false;
|
||||
// --------- 单独参数
|
||||
|
||||
/**
|
||||
* 如果 token 已被冻结,是否保留其操作权 (是否允许此 token 调用注销API)
|
||||
* (此参数只在调用 StpUtil.[logout/kickout/replaced]ByTokenValue("xxxxxxxxxxxxxxxxxxx", new SaLogoutParameter()) 时有效)
|
||||
*/
|
||||
private Boolean isKeepFreezeOps = false;
|
||||
|
||||
/**
|
||||
* 设备类型 (如果不指定,则默认注销所有客户端)
|
||||
* 需要注销的设备类型 (如果不指定,则默认注销所有客户端)
|
||||
*/
|
||||
private String deviceType;
|
||||
|
||||
/**
|
||||
* 注销类型
|
||||
* 注销类型 (LOGOUT=注销下线、KICKOUT=踢人下线,REPLACED=顶人下线)
|
||||
*/
|
||||
private SaLogoutMode mode = SaLogoutMode.LOGOUT;
|
||||
|
||||
|
||||
// --------- 覆盖性参数
|
||||
|
||||
/**
|
||||
* 注销范围 (此参数只在调用 StpUtil.logout(new SaLogoutParameter()) 时有效)
|
||||
* 注销范围 (TOKEN=只注销当前 token 的会话,ACCOUNT=注销当前 token 指向的 loginId 其所有客户端会话)
|
||||
* <br/> (此参数只在调用 StpUtil.logout() 时有效)
|
||||
*/
|
||||
private SaLogoutRange range = SaLogoutRange.TOKEN;
|
||||
private SaLogoutRange range;
|
||||
|
||||
/**
|
||||
* 如果 token 已被冻结,是否保留其操作权 (是否允许此 token 调用注销API)
|
||||
* <br/> (此参数只在调用 StpUtil.[logout/kickout/replaced]ByTokenValue("token") 时有效)
|
||||
*/
|
||||
private Boolean isKeepFreezeOps;
|
||||
|
||||
/**
|
||||
* 在注销 token 后,是否保留其对应的 Token-Session
|
||||
*/
|
||||
private Boolean isKeepTokenSession;
|
||||
|
||||
|
||||
// ------ 附加方法
|
||||
@@ -76,6 +82,9 @@ public class SaLogoutParameter {
|
||||
* @return 对象自身
|
||||
*/
|
||||
public SaLogoutParameter setDefaultValues(SaTokenConfig config) {
|
||||
this.range = config.getLogoutRange();
|
||||
this.isKeepFreezeOps = config.getIsLogoutKeepFreezeOps();
|
||||
this.isKeepTokenSession = config.getIsLogoutKeepTokenSession();
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -92,14 +101,14 @@ public class SaLogoutParameter {
|
||||
// ---------------- get set
|
||||
|
||||
/**
|
||||
* @return 是否保留 Token-Session
|
||||
* @return 在注销 token 后,是否保留其对应的 Token-Session
|
||||
*/
|
||||
public Boolean getIsKeepTokenSession() {
|
||||
return isKeepTokenSession;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param isKeepTokenSession 是否保留 Token-Session
|
||||
* @param isKeepTokenSession 在注销 token 后,是否保留其对应的 Token-Session
|
||||
*
|
||||
* @return 对象自身
|
||||
*/
|
||||
@@ -110,7 +119,7 @@ public class SaLogoutParameter {
|
||||
|
||||
/**
|
||||
* 获取 如果 token 已被冻结,是否保留其操作权 (是否允许此 token 调用注销API)
|
||||
* (此参数只在调用 StpUtil.[logout/kickout/replaced]ByTokenValue("xxxxxxxxxxxxxxxxxxx", new SaLogoutParameter()) 时有效)
|
||||
* <br/> (此参数只在调用 StpUtil.[logout/kickout/replaced]ByTokenValue("token") 时有效)
|
||||
*
|
||||
* @return /
|
||||
*/
|
||||
@@ -120,7 +129,7 @@ public class SaLogoutParameter {
|
||||
|
||||
/**
|
||||
* 设置 如果 token 已被冻结,是否保留其操作权 (是否允许此 token 调用注销API)
|
||||
* (此参数只在调用 StpUtil.[logout/kickout/replaced]ByTokenValue("xxxxxxxxxxxxxxxxxxx", new SaLogoutParameter()) 时有效)
|
||||
* <br/> (此参数只在调用 StpUtil.[logout/kickout/replaced]ByTokenValue("token") 时有效)
|
||||
*
|
||||
* @param isKeepFreezeOps /
|
||||
* @return 对象自身
|
||||
@@ -129,8 +138,9 @@ public class SaLogoutParameter {
|
||||
this.isKeepFreezeOps = isKeepFreezeOps;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 设备类型 (如果不指定,则默认注销所有客户端)
|
||||
* 需要注销的设备类型 (如果不指定,则默认注销所有客户端)
|
||||
*
|
||||
* @return deviceType /
|
||||
*/
|
||||
@@ -139,7 +149,7 @@ public class SaLogoutParameter {
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置 设备类型 (如果不指定,则默认注销所有客户端)
|
||||
* 需要注销的设备类型 (如果不指定,则默认注销所有客户端)
|
||||
*
|
||||
* @param deviceType /
|
||||
* @return /
|
||||
@@ -150,7 +160,7 @@ public class SaLogoutParameter {
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 注销类型
|
||||
* 注销类型 (LOGOUT=注销下线、KICKOUT=踢人下线,REPLACED=顶人下线)
|
||||
*
|
||||
* @return logoutMode 注销类型
|
||||
*/
|
||||
@@ -159,7 +169,7 @@ public class SaLogoutParameter {
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置 注销类型
|
||||
* 注销类型 (LOGOUT=注销下线、KICKOUT=踢人下线,REPLACED=顶人下线)
|
||||
*
|
||||
* @param mode 注销类型
|
||||
* @return /
|
||||
@@ -170,7 +180,8 @@ public class SaLogoutParameter {
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 注销范围 (此参数只在调用 StpUtil.logout(new SaLogoutParameter()) 时有效)
|
||||
* 注销范围 (TOKEN=只注销当前 token 的会话,ACCOUNT=注销当前 token 指向的 loginId 其所有客户端会话)
|
||||
* <br/> (此参数只在调用 StpUtil.logout() 时有效)
|
||||
*
|
||||
* @return /
|
||||
*/
|
||||
@@ -179,7 +190,8 @@ public class SaLogoutParameter {
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置 注销范围 (此参数只在调用 StpUtil.logout(new SaLogoutParameter()) 时有效)
|
||||
* 注销范围 (TOKEN=只注销当前 token 的会话,ACCOUNT=注销当前 token 指向的 loginId 其所有客户端会话)
|
||||
* <br/> (此参数只在调用 StpUtil.logout() 时有效)
|
||||
*
|
||||
* @param range /
|
||||
* @return /
|
||||
|
Reference in New Issue
Block a user