feat: 新增配置项 cookieAutoFillPrefix:cookie 模式是否自动填充 token 前缀

This commit is contained in:
click33
2025-04-02 00:17:56 +08:00
parent 68939084a2
commit 92f48256e9
3 changed files with 28 additions and 2 deletions

View File

@@ -153,6 +153,11 @@ public class SaTokenConfig implements Serializable {
*/
private String tokenPrefix;
/**
* cookie 模式是否自动填充 token 前缀
*/
private Boolean cookieAutoFillPrefix = false;
/**
* 是否在初始化配置时在控制台打印版本字符画
*/
@@ -517,7 +522,23 @@ public class SaTokenConfig implements Serializable {
this.tokenPrefix = tokenPrefix;
return this;
}
/**
* @return cookie 模式是否自动填充 token 前缀
*/
public Boolean getCookieAutoFillPrefix() {
return cookieAutoFillPrefix;
}
/**
* @param cookieAutoFillPrefix cookie 模式是否自动填充 token 前缀
* @return 对象自身
*/
public SaTokenConfig setCookieAutoFillPrefix(Boolean cookieAutoFillPrefix) {
this.cookieAutoFillPrefix = cookieAutoFillPrefix;
return this;
}
/**
* @return 是否在初始化配置时在控制台打印版本字符画
*/
@@ -877,8 +898,9 @@ public class SaTokenConfig implements Serializable {
+ ", tokenStyle=" + tokenStyle
+ ", dataRefreshPeriod=" + dataRefreshPeriod
+ ", tokenSessionCheckLogin=" + tokenSessionCheckLogin
+ ", autoRenew=" + autoRenew
+ ", autoRenew=" + autoRenew
+ ", tokenPrefix=" + tokenPrefix
+ ", cookieAutoFillPrefix=" + cookieAutoFillPrefix
+ ", isPrint=" + isPrint
+ ", isLog=" + isLog
+ ", logLevel=" + logLevel

View File

@@ -351,6 +351,9 @@ public class StpLogic {
// 4. 最后尝试从 cookie 里读取
if(SaFoxUtil.isEmpty(tokenValue) && config.getIsReadCookie()){
tokenValue = request.getCookieValue(keyTokenName);
if(SaFoxUtil.isNotEmpty(tokenValue) && config.getCookieAutoFillPrefix()) {
tokenValue = config.getTokenPrefix() + SaTokenConsts.TOKEN_CONNECTOR_CHAT + tokenValue;
}
}
// 5. 至此,不管有没有读取到,都不再尝试了,直接返回