mirror of
https://gitee.com/dromara/sa-token.git
synced 2025-06-28 13:34:18 +08:00
feat: 新增配置项 cookieAutoFillPrefix:cookie 模式是否自动填充 token 前缀
This commit is contained in:
parent
68939084a2
commit
92f48256e9
@ -153,6 +153,11 @@ public class SaTokenConfig implements Serializable {
|
|||||||
*/
|
*/
|
||||||
private String tokenPrefix;
|
private String tokenPrefix;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* cookie 模式是否自动填充 token 前缀
|
||||||
|
*/
|
||||||
|
private Boolean cookieAutoFillPrefix = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 是否在初始化配置时在控制台打印版本字符画
|
* 是否在初始化配置时在控制台打印版本字符画
|
||||||
*/
|
*/
|
||||||
@ -517,7 +522,23 @@ public class SaTokenConfig implements Serializable {
|
|||||||
this.tokenPrefix = tokenPrefix;
|
this.tokenPrefix = tokenPrefix;
|
||||||
return this;
|
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 是否在初始化配置时在控制台打印版本字符画
|
* @return 是否在初始化配置时在控制台打印版本字符画
|
||||||
*/
|
*/
|
||||||
@ -877,8 +898,9 @@ public class SaTokenConfig implements Serializable {
|
|||||||
+ ", tokenStyle=" + tokenStyle
|
+ ", tokenStyle=" + tokenStyle
|
||||||
+ ", dataRefreshPeriod=" + dataRefreshPeriod
|
+ ", dataRefreshPeriod=" + dataRefreshPeriod
|
||||||
+ ", tokenSessionCheckLogin=" + tokenSessionCheckLogin
|
+ ", tokenSessionCheckLogin=" + tokenSessionCheckLogin
|
||||||
+ ", autoRenew=" + autoRenew
|
+ ", autoRenew=" + autoRenew
|
||||||
+ ", tokenPrefix=" + tokenPrefix
|
+ ", tokenPrefix=" + tokenPrefix
|
||||||
|
+ ", cookieAutoFillPrefix=" + cookieAutoFillPrefix
|
||||||
+ ", isPrint=" + isPrint
|
+ ", isPrint=" + isPrint
|
||||||
+ ", isLog=" + isLog
|
+ ", isLog=" + isLog
|
||||||
+ ", logLevel=" + logLevel
|
+ ", logLevel=" + logLevel
|
||||||
|
@ -351,6 +351,9 @@ public class StpLogic {
|
|||||||
// 4. 最后尝试从 cookie 里读取
|
// 4. 最后尝试从 cookie 里读取
|
||||||
if(SaFoxUtil.isEmpty(tokenValue) && config.getIsReadCookie()){
|
if(SaFoxUtil.isEmpty(tokenValue) && config.getIsReadCookie()){
|
||||||
tokenValue = request.getCookieValue(keyTokenName);
|
tokenValue = request.getCookieValue(keyTokenName);
|
||||||
|
if(SaFoxUtil.isNotEmpty(tokenValue) && config.getCookieAutoFillPrefix()) {
|
||||||
|
tokenValue = config.getTokenPrefix() + SaTokenConsts.TOKEN_CONNECTOR_CHAT + tokenValue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 5. 至此,不管有没有读取到,都不再尝试了,直接返回
|
// 5. 至此,不管有没有读取到,都不再尝试了,直接返回
|
||||||
|
@ -139,6 +139,7 @@ public class SaTokenConfigure {
|
|||||||
| tokenSessionCheckLogin | Boolean | true | 获取 `Token-Session` 时是否必须登录 (如果配置为true,会在每次获取 `Token-Session` 时校验是否登录),[详解](/use/config?id=配置项详解:tokenSessionCheckLogin) |
|
| tokenSessionCheckLogin | Boolean | true | 获取 `Token-Session` 时是否必须登录 (如果配置为true,会在每次获取 `Token-Session` 时校验是否登录),[详解](/use/config?id=配置项详解:tokenSessionCheckLogin) |
|
||||||
| autoRenew | Boolean | true | 是否打开自动续签 (如果此值为true,框架会在每次直接或间接调用 `getLoginId()` 时进行一次过期检查与续签操作),[参考:token有效期详解](/fun/token-timeout) |
|
| autoRenew | Boolean | true | 是否打开自动续签 (如果此值为true,框架会在每次直接或间接调用 `getLoginId()` 时进行一次过期检查与续签操作),[参考:token有效期详解](/fun/token-timeout) |
|
||||||
| tokenPrefix | String | null | token前缀,例如填写 `Bearer` 实际传参 `satoken: Bearer xxxx-xxxx-xxxx-xxxx` [参考:自定义Token前缀](/up/token-prefix) |
|
| tokenPrefix | String | null | token前缀,例如填写 `Bearer` 实际传参 `satoken: Bearer xxxx-xxxx-xxxx-xxxx` [参考:自定义Token前缀](/up/token-prefix) |
|
||||||
|
| cookieAutoFillPrefix | Boolean | false | cookie 模式是否自动填充 token 前缀 |
|
||||||
| isPrint | Boolean | true | 是否在初始化配置时打印版本字符画 |
|
| isPrint | Boolean | true | 是否在初始化配置时打印版本字符画 |
|
||||||
| isLog | Boolean | false | 是否打印操作日志 |
|
| isLog | Boolean | false | 是否打印操作日志 |
|
||||||
| logLevel | String | trace | 日志等级(trace、debug、info、warn、error、fatal),此值与 logLevelInt 联动 |
|
| logLevel | String | trace | 日志等级(trace、debug、info、warn、error、fatal),此值与 logLevelInt 联动 |
|
||||||
|
Loading…
Reference in New Issue
Block a user