mirror of
https://gitee.com/dromara/sa-token.git
synced 2025-05-04 04:37:56 +08:00
feat: SaLoginParameter 支持 maxLoginCount 配置
This commit is contained in:
parent
3bc9e88645
commit
0b85c7d094
@ -46,17 +46,17 @@ public class SaLoginParameter {
|
||||
/**
|
||||
* 此次登录的客户端设备类型
|
||||
*/
|
||||
public String device;
|
||||
private String device;
|
||||
|
||||
/**
|
||||
* 扩展信息(只在 jwt 模式下生效)
|
||||
*/
|
||||
public Map<String, Object> extraData;
|
||||
private Map<String, Object> extraData;
|
||||
|
||||
/**
|
||||
* 预定Token(预定本次登录生成的Token值)
|
||||
*/
|
||||
public String token;
|
||||
private String token;
|
||||
|
||||
/**
|
||||
* 本次登录挂载到 TokenSign 的数据
|
||||
@ -69,7 +69,7 @@ public class SaLoginParameter {
|
||||
/**
|
||||
* 指定此次登录 token 有效期,单位:秒 (如未指定,自动取全局配置的 timeout 值)
|
||||
*/
|
||||
public Long timeout;
|
||||
private Long timeout;
|
||||
|
||||
/**
|
||||
* 指定此次登录 token 最低活跃频率,单位:秒(如未指定,则使用全局配置的 activeTimeout 值)
|
||||
@ -86,10 +86,15 @@ public class SaLoginParameter {
|
||||
*/
|
||||
private Boolean isShare = true;
|
||||
|
||||
/**
|
||||
* 同一账号最大登录数量,-1代表不限 (只有在 isConcurrent=true, isShare=false 时此配置项才有意义)
|
||||
*/
|
||||
private int maxLoginCount = 12;
|
||||
|
||||
/**
|
||||
* 是否为持久Cookie(临时Cookie在浏览器关闭时会自动删除,持久Cookie在重新打开后依然存在)
|
||||
*/
|
||||
public Boolean isLastingCookie;
|
||||
private Boolean isLastingCookie;
|
||||
|
||||
/**
|
||||
* 是否在登录后将 Token 写入到响应头
|
||||
@ -293,6 +298,22 @@ public class SaLoginParameter {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return 同一账号最大登录数量,-1代表不限 (只有在 isConcurrent=true, isShare=false 时此配置项才有意义)
|
||||
*/
|
||||
public int getMaxLoginCount() {
|
||||
return maxLoginCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param maxLoginCount 同一账号最大登录数量,-1代表不限 (只有在 isConcurrent=true, isShare=false 时此配置项才有意义)
|
||||
* @return 对象自身
|
||||
*/
|
||||
public SaLoginParameter setMaxLoginCount(int maxLoginCount) {
|
||||
this.maxLoginCount = maxLoginCount;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return 扩展信息(只在jwt模式下生效)
|
||||
*/
|
||||
@ -373,6 +394,7 @@ public class SaLoginParameter {
|
||||
+ ", activeTimeout=" + activeTimeout
|
||||
+ ", isConcurrent=" + isConcurrent
|
||||
+ ", isShare=" + isShare
|
||||
+ ", maxLoginCount=" + maxLoginCount
|
||||
+ ", extraData=" + extraData
|
||||
+ ", token=" + token
|
||||
+ ", isWriteHeader=" + isWriteHeader
|
||||
|
@ -496,8 +496,8 @@ public class StpLogic {
|
||||
SaTokenEventCenter.doLogin(loginType, id, tokenValue, loginParameter);
|
||||
|
||||
// 9、检查此账号会话数量是否超出最大值,如果超过,则按照登录时间顺序,把最开始登录的给注销掉
|
||||
if(config.getMaxLoginCount() != -1) {
|
||||
logoutByMaxLoginCount(id, session, null, config.getMaxLoginCount());
|
||||
if(loginParameter.getMaxLoginCount() != -1) {
|
||||
logoutByMaxLoginCount(id, session, null, loginParameter.getMaxLoginCount());
|
||||
}
|
||||
|
||||
// 10、一切处理完毕,返回会话凭证 token
|
||||
|
@ -29,6 +29,7 @@ public class TestController {
|
||||
StpUtil.login(id, new SaLoginParameter()
|
||||
.setIsConcurrent(true)
|
||||
.setIsShare(false)
|
||||
.setMaxLoginCount(4)
|
||||
);
|
||||
return SaResult.ok("登录成功");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user