From 66c431bb3e443dbab7d73765024eee1eee540ac3 Mon Sep 17 00:00:00 2001 From: click33 <2393584716@qq.com> Date: Wed, 30 Apr 2025 07:30:11 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20SaLogoutParameter=20=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=20deviceId=20=E5=8F=82=E6=95=B0=EF=BC=8C=E7=94=A8=E4=BA=8E?= =?UTF-8?q?=E6=8E=A7=E5=88=B6=E6=8C=87=E5=AE=9A=E8=AE=BE=E5=A4=87=20id=20?= =?UTF-8?q?=E7=9A=84=E6=B3=A8=E9=94=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/cn/dev33/satoken/stp/StpLogic.java | 10 +++- .../stp/parameter/SaLogoutParameter.java | 50 +++++++++++++++---- 2 files changed, 50 insertions(+), 10 deletions(-) diff --git a/sa-token-core/src/main/java/cn/dev33/satoken/stp/StpLogic.java b/sa-token-core/src/main/java/cn/dev33/satoken/stp/StpLogic.java index 2fd25771..c34a578a 100644 --- a/sa-token-core/src/main/java/cn/dev33/satoken/stp/StpLogic.java +++ b/sa-token-core/src/main/java/cn/dev33/satoken/stp/StpLogic.java @@ -916,8 +916,16 @@ public class StpLogic { if(session != null) { // 2、遍历此 SaTerminalInfo 客户端列表,清除相关数据 - List terminalList = session.getTerminalListByDeviceType(logoutParameter.getDeviceType()); + List terminalList = session.terminalListCopy(); for (SaTerminalInfo terminal: terminalList) { + // 不符合 deviceType 的跳过 + if( ! SaFoxUtil.isEmpty(logoutParameter.getDeviceType()) && ! logoutParameter.getDeviceType().equals(terminal.getDeviceType())) { + continue; + } + // 不符合 deviceId 的跳过 + if( ! SaFoxUtil.isEmpty(logoutParameter.getDeviceId()) && ! logoutParameter.getDeviceId().equals(terminal.getDeviceId())) { + continue; + } _removeTerminal(session, terminal, logoutParameter); } diff --git a/sa-token-core/src/main/java/cn/dev33/satoken/stp/parameter/SaLogoutParameter.java b/sa-token-core/src/main/java/cn/dev33/satoken/stp/parameter/SaLogoutParameter.java index 2ab93961..2404f46e 100644 --- a/sa-token-core/src/main/java/cn/dev33/satoken/stp/parameter/SaLogoutParameter.java +++ b/sa-token-core/src/main/java/cn/dev33/satoken/stp/parameter/SaLogoutParameter.java @@ -36,10 +36,17 @@ public class SaLogoutParameter { // --------- 单独参数 /** - * 需要注销的设备类型 (如果不指定,则默认注销所有客户端) + * 需要注销的设备类型 (为 null 代表不限制,为具体值代表只注销此设备类型的会话) + *
(此参数只在调用 StpUtil.logout(id, parame) 时有效) */ private String deviceType; + /** + * 需要注销的设备ID (为 null 代表不限制,为具体值代表只注销此设备ID的会话) + *
(此参数只在调用 StpUtil.logout(id, param) 时有效) + */ + private String deviceId; + /** * 注销类型 (LOGOUT=注销下线、KICKOUT=踢人下线,REPLACED=顶人下线) */ @@ -50,13 +57,13 @@ public class SaLogoutParameter { /** * 注销范围 (TOKEN=只注销当前 token 的会话,ACCOUNT=注销当前 token 指向的 loginId 其所有客户端会话) - *
(此参数只在调用 StpUtil.logout() 时有效) + *
(此参数只在调用 StpUtil.logout(param) 时有效) */ private SaLogoutRange range; /** * 如果 token 已被冻结,是否保留其操作权 (是否允许此 token 调用注销API) - *
(此参数只在调用 StpUtil.[logout/kickout/replaced]ByTokenValue("token") 时有效) + *
(此参数只在调用 StpUtil.[logout/kickout/replaced]ByTokenValue("token", param) 时有效) */ private Boolean isKeepFreezeOps; @@ -119,7 +126,7 @@ public class SaLogoutParameter { /** * 获取 如果 token 已被冻结,是否保留其操作权 (是否允许此 token 调用注销API) - *
(此参数只在调用 StpUtil.[logout/kickout/replaced]ByTokenValue("token") 时有效) + *
(此参数只在调用 StpUtil.[logout/kickout/replaced]ByTokenValue("token", param) 时有效) * * @return / */ @@ -129,7 +136,7 @@ public class SaLogoutParameter { /** * 设置 如果 token 已被冻结,是否保留其操作权 (是否允许此 token 调用注销API) - *
(此参数只在调用 StpUtil.[logout/kickout/replaced]ByTokenValue("token") 时有效) + *
(此参数只在调用 StpUtil.[logout/kickout/replaced]ByTokenValue("token", param) 时有效) * * @param isKeepFreezeOps / * @return 对象自身 @@ -140,7 +147,8 @@ public class SaLogoutParameter { } /** - * 需要注销的设备类型 (如果不指定,则默认注销所有客户端) + * 需要注销的设备类型 (为 null 代表不限制,为具体值代表只注销此设备类型的会话) + *
(此参数只在调用 StpUtil.logout(id, parame) 时有效) * * @return deviceType / */ @@ -149,7 +157,8 @@ public class SaLogoutParameter { } /** - * 需要注销的设备类型 (如果不指定,则默认注销所有客户端) + * 需要注销的设备类型 (为 null 代表不限制,为具体值代表只注销此设备类型的会话) + *
(此参数只在调用 StpUtil.logout(id, parame) 时有效) * * @param deviceType / * @return / @@ -159,6 +168,28 @@ public class SaLogoutParameter { return this; } + /** + * 需要注销的设备ID (为 null 代表不限制,为具体值代表只注销此设备 ID 的会话) + *
(此参数只在调用 StpUtil.logout(id, parame) 时有效) + * + * @return / + */ + public String getDeviceId() { + return this.deviceId; + } + + /** + * 需要注销的设备类型 (为 null 代表不限制,为具体值代表只注销此设备 ID 的会话) + *
(此参数只在调用 StpUtil.logout(id, parame) 时有效) + * + * @param deviceId / + * @return / + */ + public SaLogoutParameter setDeviceId(String deviceId) { + this.deviceId = deviceId; + return this; + } + /** * 注销类型 (LOGOUT=注销下线、KICKOUT=踢人下线,REPLACED=顶人下线) * @@ -181,7 +212,7 @@ public class SaLogoutParameter { /** * 注销范围 (TOKEN=只注销当前 token 的会话,ACCOUNT=注销当前 token 指向的 loginId 其所有客户端会话) - *
(此参数只在调用 StpUtil.logout() 时有效) + *
(此参数只在调用 StpUtil.logout(param) 时有效) * * @return / */ @@ -191,7 +222,7 @@ public class SaLogoutParameter { /** * 注销范围 (TOKEN=只注销当前 token 的会话,ACCOUNT=注销当前 token 指向的 loginId 其所有客户端会话) - *
(此参数只在调用 StpUtil.logout() 时有效) + *
(此参数只在调用 StpUtil.logout(param) 时有效) * * @param range / * @return / @@ -208,6 +239,7 @@ public class SaLogoutParameter { public String toString() { return "SaLoginParameter [" + "deviceType=" + deviceType + + ", deviceId=" + deviceId + ", isKeepTokenSession=" + isKeepTokenSession + ", isKeepFreezeOps=" + isKeepFreezeOps + ", mode=" + mode