mirror of
https://gitee.com/dromara/sa-token.git
synced 2026-02-27 16:50:24 +08:00
feat: 新增配置项 rightNowCreateTokenSession:在登录时,是否立即创建对应的 Token-Session (true=在登录时立即创建,false=在第一次调用 getTokenSession() 时创建)
This commit is contained in:
@@ -128,6 +128,11 @@ public class SaTokenConfig implements Serializable {
|
|||||||
*/
|
*/
|
||||||
private Boolean isLogoutKeepTokenSession = false;
|
private Boolean isLogoutKeepTokenSession = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 在登录时,是否立即创建对应的 Token-Session (true=在登录时立即创建,false=在第一次调用 getTokenSession() 时创建)
|
||||||
|
*/
|
||||||
|
private Boolean rightNowCreateTokenSession = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* token 风格(默认可取值:uuid、simple-uuid、random-32、random-64、random-128、tik)
|
* token 风格(默认可取值:uuid、simple-uuid、random-32、random-64、random-128、tik)
|
||||||
*/
|
*/
|
||||||
@@ -821,6 +826,26 @@ public class SaTokenConfig implements Serializable {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取 在登录时,是否立即创建对应的 Token-Session (true=在登录时立即创建,false=在第一次调用 getTokenSession() 时创建)
|
||||||
|
*
|
||||||
|
* @return /
|
||||||
|
*/
|
||||||
|
public Boolean getRightNowCreateTokenSession() {
|
||||||
|
return this.rightNowCreateTokenSession;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置 在登录时,是否立即创建对应的 Token-Session (true=在登录时立即创建,false=在第一次调用 getTokenSession() 时创建)
|
||||||
|
*
|
||||||
|
* @param rightNowCreateTokenSession /
|
||||||
|
* @return 对象自身
|
||||||
|
*/
|
||||||
|
public SaTokenConfig setRightNowCreateTokenSession(Boolean rightNowCreateTokenSession) {
|
||||||
|
this.rightNowCreateTokenSession = rightNowCreateTokenSession;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Cookie 全局配置对象
|
* @return Cookie 全局配置对象
|
||||||
*/
|
*/
|
||||||
@@ -895,6 +920,7 @@ public class SaTokenConfig implements Serializable {
|
|||||||
+ ", logoutRange=" + logoutRange
|
+ ", logoutRange=" + logoutRange
|
||||||
+ ", isLogoutKeepFreezeOps=" + isLogoutKeepFreezeOps
|
+ ", isLogoutKeepFreezeOps=" + isLogoutKeepFreezeOps
|
||||||
+ ", isLogoutKeepTokenSession=" + isLogoutKeepTokenSession
|
+ ", isLogoutKeepTokenSession=" + isLogoutKeepTokenSession
|
||||||
|
+ ", rightNowCreateTokenSession=" + rightNowCreateTokenSession
|
||||||
+ ", tokenStyle=" + tokenStyle
|
+ ", tokenStyle=" + tokenStyle
|
||||||
+ ", dataRefreshPeriod=" + dataRefreshPeriod
|
+ ", dataRefreshPeriod=" + dataRefreshPeriod
|
||||||
+ ", tokenSessionCheckLogin=" + tokenSessionCheckLogin
|
+ ", tokenSessionCheckLogin=" + tokenSessionCheckLogin
|
||||||
|
|||||||
@@ -498,7 +498,7 @@ public class StpLogic {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 7、如果该 token 对应的 Token-Session 已经存在,则需要给其续期
|
// 7、如果该 token 对应的 Token-Session 已经存在,则需要给其续期
|
||||||
SaSession tokenSession = getTokenSessionByToken(tokenValue, false);
|
SaSession tokenSession = getTokenSessionByToken(tokenValue, loginParameter.getRightNowCreateTokenSession());
|
||||||
if(tokenSession != null) {
|
if(tokenSession != null) {
|
||||||
tokenSession.updateMinTimeout(loginParameter.getTimeout());
|
tokenSession.updateMinTimeout(loginParameter.getTimeout());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -118,6 +118,11 @@ public class SaLoginParameter {
|
|||||||
*/
|
*/
|
||||||
private SaLogoutMode overflowLogoutMode;
|
private SaLogoutMode overflowLogoutMode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 在登录时,是否立即创建对应的 Token-Session (true=在登录时立即创建,false=在第一次调用 getTokenSession() 时创建)
|
||||||
|
*/
|
||||||
|
private Boolean rightNowCreateTokenSession;
|
||||||
|
|
||||||
|
|
||||||
// ------ 附加方法
|
// ------ 附加方法
|
||||||
|
|
||||||
@@ -145,6 +150,7 @@ public class SaLoginParameter {
|
|||||||
this.isWriteHeader = config.getIsWriteHeader();
|
this.isWriteHeader = config.getIsWriteHeader();
|
||||||
this.replacedRange = config.getReplacedRange();
|
this.replacedRange = config.getReplacedRange();
|
||||||
this.overflowLogoutMode = config.getOverflowLogoutMode();
|
this.overflowLogoutMode = config.getOverflowLogoutMode();
|
||||||
|
this.rightNowCreateTokenSession = config.getRightNowCreateTokenSession();
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -498,6 +504,26 @@ public class SaLoginParameter {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取 在登录时,是否立即创建对应的 Token-Session (true=在登录时立即创建,false=在第一次调用 getTokenSession() 时创建)
|
||||||
|
*
|
||||||
|
* @return /
|
||||||
|
*/
|
||||||
|
public Boolean getRightNowCreateTokenSession() {
|
||||||
|
return this.rightNowCreateTokenSession;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置 在登录时,是否立即创建对应的 Token-Session (true=在登录时立即创建,false=在第一次调用 getTokenSession() 时创建)
|
||||||
|
*
|
||||||
|
* @param rightNowCreateTokenSession /
|
||||||
|
* @return 对象自身
|
||||||
|
*/
|
||||||
|
public SaLoginParameter setRightNowCreateTokenSession(Boolean rightNowCreateTokenSession) {
|
||||||
|
this.rightNowCreateTokenSession = rightNowCreateTokenSession;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* toString
|
* toString
|
||||||
*/
|
*/
|
||||||
@@ -519,6 +545,7 @@ public class SaLoginParameter {
|
|||||||
+ ", token=" + token
|
+ ", token=" + token
|
||||||
+ ", isWriteHeader=" + isWriteHeader
|
+ ", isWriteHeader=" + isWriteHeader
|
||||||
+ ", terminalTag=" + terminalExtraData
|
+ ", terminalTag=" + terminalExtraData
|
||||||
|
+ ", rightNowCreateTokenSession=" + rightNowCreateTokenSession
|
||||||
+ "]";
|
+ "]";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ StpUtil.login(10001, new SaLoginParameter()
|
|||||||
.setTerminalExtra("key", "value")// 本次登录挂载到 SaTerminalInfo 的自定义扩展数据
|
.setTerminalExtra("key", "value")// 本次登录挂载到 SaTerminalInfo 的自定义扩展数据
|
||||||
.setReplacedRange(SaReplacedRange.CURR_DEVICE_TYPE) // 顶人下线的范围: CURR_DEVICE_TYPE=当前指定的设备类型端, ALL_DEVICE_TYPE=所有设备类型端
|
.setReplacedRange(SaReplacedRange.CURR_DEVICE_TYPE) // 顶人下线的范围: CURR_DEVICE_TYPE=当前指定的设备类型端, ALL_DEVICE_TYPE=所有设备类型端
|
||||||
.setOverflowLogoutMode(SaLogoutMode.LOGOUT) // 溢出 maxLoginCount 的客户端,将以何种方式注销下线: LOGOUT=注销下线, KICKOUT=踢人下线, REPLACED=顶人下线
|
.setOverflowLogoutMode(SaLogoutMode.LOGOUT) // 溢出 maxLoginCount 的客户端,将以何种方式注销下线: LOGOUT=注销下线, KICKOUT=踢人下线, REPLACED=顶人下线
|
||||||
|
.setRightNowCreateTokenSession(true) // 是否立即创建对应的 Token-Session (true=在登录时立即创建,false=在第一次调用 getTokenSession() 时创建)
|
||||||
);
|
);
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -134,6 +134,7 @@ public class SaTokenConfigure {
|
|||||||
| logoutRange | SaLogoutRange | TOKEN | 注销范围 (TOKEN=只注销当前 token 的会话,ACCOUNT=注销当前 token 指向的 loginId 其所有客户端会话) (此参数只在调用 StpUtil.logout() 时有效) |
|
| logoutRange | SaLogoutRange | TOKEN | 注销范围 (TOKEN=只注销当前 token 的会话,ACCOUNT=注销当前 token 指向的 loginId 其所有客户端会话) (此参数只在调用 StpUtil.logout() 时有效) |
|
||||||
| isLogoutKeepFreezeOps | Boolean | false | 如果 token 已被冻结,是否保留其操作权 (是否允许此 token 调用注销API) (此参数只在调用 StpUtil.[logout/kickout/replaced]ByTokenValue("token") 时有效) |
|
| isLogoutKeepFreezeOps | Boolean | false | 如果 token 已被冻结,是否保留其操作权 (是否允许此 token 调用注销API) (此参数只在调用 StpUtil.[logout/kickout/replaced]ByTokenValue("token") 时有效) |
|
||||||
| isLogoutKeepTokenSession | Boolean | false | 在注销 token 后,是否保留其对应的 Token-Session |
|
| isLogoutKeepTokenSession | Boolean | false | 在注销 token 后,是否保留其对应的 Token-Session |
|
||||||
|
| rightNowCreateTokenSession| Boolean | false | 在登录时,是否立即创建对应的 Token-Session (true=在登录时立即创建,false=在第一次调用 getTokenSession() 时创建) |
|
||||||
| tokenStyle | String | uuid | token风格, [参考:自定义Token风格](/up/token-style) |
|
| tokenStyle | String | uuid | token风格, [参考:自定义Token风格](/up/token-style) |
|
||||||
| dataRefreshPeriod | int | 30 | 默认数据持久组件实现类中,每次清理过期数据间隔的时间 (单位: 秒) ,默认值30秒,设置为-1代表不启动定时清理 |
|
| dataRefreshPeriod | int | 30 | 默认数据持久组件实现类中,每次清理过期数据间隔的时间 (单位: 秒) ,默认值30秒,设置为-1代表不启动定时清理 |
|
||||||
| tokenSessionCheckLogin | Boolean | true | 获取 `Token-Session` 时是否必须登录 (如果配置为true,会在每次获取 `Token-Session` 时校验是否登录),[详解](/use/config?id=配置项详解:tokenSessionCheckLogin) |
|
| tokenSessionCheckLogin | Boolean | true | 获取 `Token-Session` 时是否必须登录 (如果配置为true,会在每次获取 `Token-Session` 时校验是否登录),[详解](/use/config?id=配置项详解:tokenSessionCheckLogin) |
|
||||||
|
|||||||
Reference in New Issue
Block a user