Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
shengzhang_
sa-token
提交
36afaf74
sa-token
项目概览
shengzhang_
/
sa-token
通知
68
Star
16
Fork
4
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
sa-token
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
36afaf74
编写于
3月 22, 2021
作者:
shengzhang_
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
token前缀校验改为强制模式,如果配置了前缀,则前端提交token时必须带有前缀
上级
55b9c87d
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
34 addition
and
9 deletion
+34
-9
sa-token-core/src/main/java/cn/dev33/satoken/session/SaSession.java
...ore/src/main/java/cn/dev33/satoken/session/SaSession.java
+10
-0
sa-token-core/src/main/java/cn/dev33/satoken/stp/StpLogic.java
...ken-core/src/main/java/cn/dev33/satoken/stp/StpLogic.java
+15
-5
sa-token-core/src/main/java/cn/dev33/satoken/util/SaTokenConsts.java
...re/src/main/java/cn/dev33/satoken/util/SaTokenConsts.java
+9
-2
sa-token-demo-springboot/src/main/java/com/pj/test/TestController.java
...-springboot/src/main/java/com/pj/test/TestController.java
+0
-1
sa-token-demo-springboot/src/main/resources/application.yml
sa-token-demo-springboot/src/main/resources/application.yml
+0
-1
未找到文件。
sa-token-core/src/main/java/cn/dev33/satoken/session/SaSession.java
浏览文件 @
36afaf74
...
...
@@ -283,6 +283,16 @@ public class SaSession implements Serializable {
SaTokenManager
.
getSaTokenDao
().
updateSessionTimeout
(
this
.
id
,
minTimeout
);
}
}
/**
* 修改此Session的最大剩余存活时间 (只有在Session的过期时间高于指定的maxTimeout时才会进行修改)
* @param maxTimeout 过期时间 (单位: 秒)
*/
public
void
updateMaxTimeout
(
long
maxTimeout
)
{
if
(
getTimeout
()
>
maxTimeout
)
{
SaTokenManager
.
getSaTokenDao
().
updateSessionTimeout
(
this
.
id
,
maxTimeout
);
}
}
...
...
sa-token-core/src/main/java/cn/dev33/satoken/stp/StpLogic.java
浏览文件 @
36afaf74
...
...
@@ -92,11 +92,19 @@ public class StpLogic {
* @param tokenValue token值
*/
public
void
setTokenValue
(
String
tokenValue
,
int
cookieTimeout
){
SaTokenConfig
config
=
getConfig
();
// 将token保存到本次request里
HttpServletRequest
request
=
SaTokenManager
.
getSaTokenServlet
().
getRequest
();
request
.
setAttribute
(
splicingKeyJustCreatedSave
(),
tokenValue
);
// 判断是否配置了token前缀
String
tokenPrefix
=
config
.
getTokenPrefix
();
if
(
SaTokenInsideUtil
.
isEmpty
(
tokenPrefix
))
{
request
.
setAttribute
(
splicingKeyJustCreatedSave
(),
tokenValue
);
}
else
{
// 如果配置了token前缀,则拼接上前缀一起写入
request
.
setAttribute
(
splicingKeyJustCreatedSave
(),
tokenPrefix
+
SaTokenConsts
.
TOKEN_CONNECTOR_CHAT
+
tokenValue
);
}
// 注入Cookie
SaTokenConfig
config
=
getConfig
();
if
(
config
.
getIsReadCookie
()
==
true
){
HttpServletResponse
response
=
SaTokenManager
.
getSaTokenServlet
().
getResponse
();
SaTokenManager
.
getSaTokenCookie
().
addCookie
(
response
,
getTokenName
(),
tokenValue
,
...
...
@@ -138,9 +146,11 @@ public class StpLogic {
// 5. 如果打开了前缀模式
String
tokenPrefix
=
getConfig
().
getTokenPrefix
();
if
(
SaTokenInsideUtil
.
isEmpty
(
tokenPrefix
)
==
false
&&
SaTokenInsideUtil
.
isEmpty
(
tokenValue
)
==
false
)
{
// 如果token以指定的前缀开头, 则裁剪掉它
if
(
tokenValue
.
startsWith
(
tokenPrefix
+
" "
))
{
tokenValue
=
tokenValue
.
substring
(
tokenPrefix
.
length
()
+
1
);
// 如果token以指定的前缀开头, 则裁剪掉它, 否则视为未提供token
if
(
tokenValue
.
startsWith
(
tokenPrefix
+
SaTokenConsts
.
TOKEN_CONNECTOR_CHAT
))
{
tokenValue
=
tokenValue
.
substring
(
tokenPrefix
.
length
()
+
SaTokenConsts
.
TOKEN_CONNECTOR_CHAT
.
length
());
}
else
{
tokenValue
=
null
;
}
}
...
...
sa-token-core/src/main/java/cn/dev33/satoken/util/SaTokenConsts.java
浏览文件 @
36afaf74
...
...
@@ -42,8 +42,8 @@ public class SaTokenConsts {
* 常量key标记: 在进行临时身份切换时使用的key
*/
public
static
final
String
SWITCH_TO_SAVE_KEY
=
"SWITCH_TO_SAVE_KEY_"
;
// =================== token-style 相关 ===================
/**
...
...
@@ -75,6 +75,13 @@ public class SaTokenConsts {
* token风格: tik风格 (2_14_16)
*/
public
static
final
String
TOKEN_STYLE_RANDOM_TIK
=
"tik"
;
// =================== 其它 ===================
/**
* 连接token前缀和token值的字符
*/
public
static
final
String
TOKEN_CONNECTOR_CHAT
=
" "
;
}
sa-token-demo-springboot/src/main/java/com/pj/test/TestController.java
浏览文件 @
36afaf74
...
...
@@ -248,7 +248,6 @@ public class TestController {
// .setIsLastingCookie(true) // 是否为持久Cookie(临时Cookie在浏览器关闭时会自动删除,持久Cookie在重新打开后依然存在)
// .setTimeout(60 * 60 * 24 * 7) // 指定此次登录token的有效期, 单位:秒 (如未指定,自动取全局配置的timeout值)
// );
StpUtil
.
getTokenSession
();
return
AjaxJson
.
getSuccess
(
"访问成功"
);
}
...
...
sa-token-demo-springboot/src/main/resources/application.yml
浏览文件 @
36afaf74
...
...
@@ -19,7 +19,6 @@ spring:
token-style
:
uuid
# redis配置
redis
:
# Redis数据库索引(默认为0)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录