Commit f3f803e5 authored by ZhengJie's avatar ZhengJie
Browse files

[代码完善](v2.5): v2.5 beta Token 生成时加入 ID,确保每次生成的 Token 唯一

可修复同一用户登录多次,但是 Token 都没变化的问题

2.5 Beta 详情:https://www.ydyno.com/archives/1225.html
parent 28ef1091
......@@ -17,6 +17,7 @@ package me.zhengjie.modules.security.security;
import cn.hutool.core.date.DateField;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.ObjectUtil;
import io.jsonwebtoken.*;
import io.jsonwebtoken.io.Decoders;
......@@ -66,10 +67,12 @@ public class TokenProvider implements InitializingBean {
.collect(Collectors.joining(","));
return Jwts.builder()
.setSubject(authentication.getName())
.claim(AUTHORITIES_KEY, authorities)
.signWith(key, SignatureAlgorithm.HS512)
.compact();
.setSubject(authentication.getName())
.claim(AUTHORITIES_KEY, authorities)
.signWith(key, SignatureAlgorithm.HS512)
// 加入ID确保生成的 Token 都不一致
.setId(IdUtil.simpleUUID())
.compact();
}
Authentication getAuthentication(String token) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment