Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
D
dataease
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
zhu
dataease
Commits
1359a673
Unverified
提交
1359a673
authored
11月 26, 2021
作者:
fit2cloud-chenyw
提交者:
GitHub
11月 26, 2021
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1286 from dataease/pr@dev@fix_token_security
fix: token验签逻辑错误
上级
13198c7c
7a0aebcd
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
11 行增加
和
2 行删除
+11
-2
JWTFilter.java
backend/src/main/java/io/dataease/auth/filter/JWTFilter.java
+3
-2
JWTUtils.java
backend/src/main/java/io/dataease/auth/util/JWTUtils.java
+8
-0
没有找到文件。
backend/src/main/java/io/dataease/auth/filter/JWTFilter.java
浏览文件 @
1359a673
package
io
.
dataease
.
auth
.
filter
;
package
io
.
dataease
.
auth
.
filter
;
import
com.auth0.jwt.algorithms.Algorithm
;
import
io.dataease.auth.entity.ASKToken
;
import
io.dataease.auth.entity.ASKToken
;
import
io.dataease.auth.entity.JWTToken
;
import
io.dataease.auth.entity.JWTToken
;
import
io.dataease.auth.entity.SysUserEntity
;
import
io.dataease.auth.entity.SysUserEntity
;
...
@@ -115,9 +116,9 @@ public class JWTFilter extends BasicHttpAuthenticationFilter {
...
@@ -115,9 +116,9 @@ public class JWTFilter extends BasicHttpAuthenticationFilter {
DataEaseException
.
throwException
(
Translator
.
get
(
"i18n_not_find_user"
));
DataEaseException
.
throwException
(
Translator
.
get
(
"i18n_not_find_user"
));
}
}
String
password
=
user
.
getPassword
();
String
password
=
user
.
getPassword
();
Algorithm
algorithm
=
Algorithm
.
HMAC256
(
password
);
JWTUtils
.
verifySign
(
algorithm
,
token
);
String
newToken
=
JWTUtils
.
sign
(
tokenInfo
,
password
);
String
newToken
=
JWTUtils
.
sign
(
tokenInfo
,
password
);
// 设置响应的Header头新Token
// 设置响应的Header头新Token
HttpServletResponse
httpServletResponse
=
(
HttpServletResponse
)
response
;
HttpServletResponse
httpServletResponse
=
(
HttpServletResponse
)
response
;
httpServletResponse
.
addHeader
(
"Access-Control-Expose-Headers"
,
"RefreshAuthorization"
);
httpServletResponse
.
addHeader
(
"Access-Control-Expose-Headers"
,
"RefreshAuthorization"
);
...
...
backend/src/main/java/io/dataease/auth/util/JWTUtils.java
浏览文件 @
1359a673
...
@@ -35,15 +35,23 @@ public class JWTUtils {
...
@@ -35,15 +35,23 @@ public class JWTUtils {
* @return 是否正确
* @return 是否正确
*/
*/
public
static
boolean
verify
(
String
token
,
TokenInfo
tokenInfo
,
String
secret
)
{
public
static
boolean
verify
(
String
token
,
TokenInfo
tokenInfo
,
String
secret
)
{
Algorithm
algorithm
=
Algorithm
.
HMAC256
(
secret
);
Algorithm
algorithm
=
Algorithm
.
HMAC256
(
secret
);
Verification
verification
=
JWT
.
require
(
algorithm
)
Verification
verification
=
JWT
.
require
(
algorithm
)
.
withClaim
(
"username"
,
tokenInfo
.
getUsername
())
.
withClaim
(
"username"
,
tokenInfo
.
getUsername
())
.
withClaim
(
"userId"
,
tokenInfo
.
getUserId
());
.
withClaim
(
"userId"
,
tokenInfo
.
getUserId
());
JWTVerifier
verifier
=
verification
.
build
();
JWTVerifier
verifier
=
verification
.
build
();
verifySign
(
algorithm
,
token
);
verifier
.
verify
(
token
);
verifier
.
verify
(
token
);
return
true
;
return
true
;
}
}
public
static
void
verifySign
(
Algorithm
algorithm
,
String
token
)
{
DecodedJWT
decode
=
JWT
.
decode
(
token
);
algorithm
.
verify
(
decode
);
}
/**
/**
* 获得token中的信息无需secret解密也能获得
* 获得token中的信息无需secret解密也能获得
*
*
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论