mirror of
https://gitee.com/dromara/sa-token.git
synced 2025-04-05 17:37:53 +08:00
feat: SaLoginParameter 支持配置 isConcurrent
This commit is contained in:
parent
0743b67cf8
commit
16cf2db334
@ -76,6 +76,11 @@ public class SaLoginParameter {
|
|||||||
*/
|
*/
|
||||||
private Long activeTimeout;
|
private Long activeTimeout;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否允许同一账号多地同时登录 (为 true 时允许一起登录, 为 false 时新登录挤掉旧登录)
|
||||||
|
*/
|
||||||
|
private Boolean isConcurrent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 是否为持久Cookie(临时Cookie在浏览器关闭时会自动删除,持久Cookie在重新打开后依然存在)
|
* 是否为持久Cookie(临时Cookie在浏览器关闭时会自动删除,持久Cookie在重新打开后依然存在)
|
||||||
*/
|
*/
|
||||||
@ -104,8 +109,9 @@ public class SaLoginParameter {
|
|||||||
*/
|
*/
|
||||||
public SaLoginParameter setDefaultValues(SaTokenConfig config) {
|
public SaLoginParameter setDefaultValues(SaTokenConfig config) {
|
||||||
this.device = SaTokenConsts.DEFAULT_LOGIN_DEVICE;
|
this.device = SaTokenConsts.DEFAULT_LOGIN_DEVICE;
|
||||||
this.isLastingCookie = config.getIsLastingCookie();
|
|
||||||
this.timeout = config.getTimeout();
|
this.timeout = config.getTimeout();
|
||||||
|
this.isConcurrent = config.getIsConcurrent();
|
||||||
|
this.isLastingCookie = config.getIsLastingCookie();
|
||||||
this.isWriteHeader = config.getIsWriteHeader();
|
this.isWriteHeader = config.getIsWriteHeader();
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@ -240,7 +246,6 @@ public class SaLoginParameter {
|
|||||||
return activeTimeout;
|
return activeTimeout;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param activeTimeout 指定此次登录 token 最低活跃频率,单位:秒(如未指定,则使用全局配置的 activeTimeout 值)
|
* @param activeTimeout 指定此次登录 token 最低活跃频率,单位:秒(如未指定,则使用全局配置的 activeTimeout 值)
|
||||||
* @return 对象自身
|
* @return 对象自身
|
||||||
@ -250,6 +255,22 @@ public class SaLoginParameter {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return 是否允许同一账号多地同时登录 (为 true 时允许一起登录, 为 false 时新登录挤掉旧登录)
|
||||||
|
*/
|
||||||
|
public Boolean getIsConcurrent() {
|
||||||
|
return isConcurrent;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param isConcurrent 是否允许同一账号多地同时登录 (为 true 时允许一起登录, 为 false 时新登录挤掉旧登录)
|
||||||
|
* @return 对象自身
|
||||||
|
*/
|
||||||
|
public SaLoginParameter setIsConcurrent(Boolean isConcurrent) {
|
||||||
|
this.isConcurrent = isConcurrent;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return 扩展信息(只在jwt模式下生效)
|
* @return 扩展信息(只在jwt模式下生效)
|
||||||
*/
|
*/
|
||||||
|
@ -515,8 +515,7 @@ public class StpLogic {
|
|||||||
|
|
||||||
// 1、获取全局配置的 isConcurrent 参数
|
// 1、获取全局配置的 isConcurrent 参数
|
||||||
// 如果配置为:不允许一个账号多地同时登录,则需要先将这个账号的历史登录会话标记为:被顶下线
|
// 如果配置为:不允许一个账号多地同时登录,则需要先将这个账号的历史登录会话标记为:被顶下线
|
||||||
Boolean isConcurrent = getConfigOrGlobal().getIsConcurrent();
|
if( ! loginParameter.getIsConcurrent()) {
|
||||||
if( ! isConcurrent) {
|
|
||||||
// TODO 此处应该加一个配置决定是只顶掉当前设备类型,还是所有类型
|
// TODO 此处应该加一个配置决定是只顶掉当前设备类型,还是所有类型
|
||||||
replaced(id, loginParameter.getDevice());
|
replaced(id, loginParameter.getDevice());
|
||||||
}
|
}
|
||||||
@ -527,7 +526,7 @@ public class StpLogic {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 3、只有在配置了 [ 允许一个账号多地同时登录 ] 时,才尝试复用旧 token,这样可以避免不必要地查询,节省开销
|
// 3、只有在配置了 [ 允许一个账号多地同时登录 ] 时,才尝试复用旧 token,这样可以避免不必要地查询,节省开销
|
||||||
if(isConcurrent) {
|
if(loginParameter.getIsConcurrent()) {
|
||||||
|
|
||||||
// 3.1、看看全局配置的 IsShare 参数,配置为 true 才是允许复用旧 token
|
// 3.1、看看全局配置的 IsShare 参数,配置为 true 才是允许复用旧 token
|
||||||
if(getConfigOfIsShare()) {
|
if(getConfigOfIsShare()) {
|
||||||
|
@ -26,7 +26,7 @@ public class TestController {
|
|||||||
// 测试登录 ---- http://localhost:8081/test/login
|
// 测试登录 ---- http://localhost:8081/test/login
|
||||||
@RequestMapping("login")
|
@RequestMapping("login")
|
||||||
public SaResult login(@RequestParam(defaultValue = "10001") long id) {
|
public SaResult login(@RequestParam(defaultValue = "10001") long id) {
|
||||||
StpUtil.login(id, new SaLoginParameter().setActiveTimeout(-1));
|
StpUtil.login(id, new SaLoginParameter().setIsConcurrent(true));
|
||||||
return SaResult.ok("登录成功");
|
return SaResult.ok("登录成功");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user