mirror of
https://gitee.com/dromara/sa-token.git
synced 2025-05-03 20:27:54 +08:00
feat: 新增 isTrustDeviceId 方法,用于判断指定设备是否为可信任设备
This commit is contained in:
parent
4e78cc8fee
commit
6c3dd1f222
@ -361,6 +361,23 @@ public class SaSession implements SaSetValueInterface, Serializable {
|
||||
return max;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断指定设备 id 是否为可信任设备
|
||||
* @param deviceId /
|
||||
* @return /
|
||||
*/
|
||||
public boolean isTrustDeviceId(String deviceId) {
|
||||
if(SaFoxUtil.isEmpty(deviceId)) {
|
||||
return false;
|
||||
}
|
||||
for (SaTerminalInfo terminal : terminalListCopy()) {
|
||||
if (SaFoxUtil.equals(terminal.getDeviceId(), deviceId)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// ----------------------- 一些操作
|
||||
|
||||
|
@ -24,13 +24,13 @@ import cn.dev33.satoken.context.model.SaRequest;
|
||||
import cn.dev33.satoken.context.model.SaResponse;
|
||||
import cn.dev33.satoken.context.model.SaStorage;
|
||||
import cn.dev33.satoken.dao.SaTokenDao;
|
||||
import cn.dev33.satoken.session.SaTerminalInfo;
|
||||
import cn.dev33.satoken.error.SaErrorCode;
|
||||
import cn.dev33.satoken.exception.*;
|
||||
import cn.dev33.satoken.fun.SaFunction;
|
||||
import cn.dev33.satoken.listener.SaTokenEventCenter;
|
||||
import cn.dev33.satoken.model.wrapperInfo.SaDisableWrapperInfo;
|
||||
import cn.dev33.satoken.session.SaSession;
|
||||
import cn.dev33.satoken.session.SaTerminalInfo;
|
||||
import cn.dev33.satoken.strategy.SaStrategy;
|
||||
import cn.dev33.satoken.util.SaFoxUtil;
|
||||
import cn.dev33.satoken.util.SaTokenConsts;
|
||||
@ -2210,6 +2210,22 @@ public class StpLogic {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断对于指定 loginId 来讲,指定设备 id 是否为可信任设备
|
||||
* @param deviceId /
|
||||
* @return /
|
||||
*/
|
||||
public boolean isTrustDeviceId(Object userId, String deviceId) {
|
||||
// 先查询此账号的 Account-Session,如果连 Account-Session 都没有,那么此账号尚未登录,直接返回 false
|
||||
SaSession session = getSessionByLoginId(userId, false);
|
||||
if(session == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 判断
|
||||
return session.isTrustDeviceId(deviceId);
|
||||
}
|
||||
|
||||
|
||||
// ------------------- 会话管理 -------------------
|
||||
|
||||
|
@ -16,10 +16,10 @@
|
||||
package cn.dev33.satoken.stp;
|
||||
|
||||
import cn.dev33.satoken.SaManager;
|
||||
import cn.dev33.satoken.session.SaTerminalInfo;
|
||||
import cn.dev33.satoken.fun.SaFunction;
|
||||
import cn.dev33.satoken.listener.SaTokenEventCenter;
|
||||
import cn.dev33.satoken.session.SaSession;
|
||||
import cn.dev33.satoken.session.SaTerminalInfo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -873,6 +873,15 @@ public class StpUtil {
|
||||
return stpLogic.getTokenLastActiveTime();
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断对于指定 loginId 来讲,指定设备 id 是否为可信任设备
|
||||
* @param deviceId /
|
||||
* @return /
|
||||
*/
|
||||
public static boolean isTrustDeviceId(Object userId, String deviceId) {
|
||||
return stpLogic.isTrustDeviceId(userId, deviceId);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ------------------- 会话管理 -------------------
|
||||
|
Loading…
Reference in New Issue
Block a user