File tree Expand file tree Collapse file tree
simple-application/src/main/resources
simple-framework/src/main/java/top/cadecode/sra/framework/security Expand file tree Collapse file tree Original file line number Diff line number Diff line change 6868 # security 配置
6969 security :
7070 auth-model : redis
71- jwt :
71+ token :
7272 header : token
73- refresh-header : refresh-token
7473 expiration : 86400
75- refresh-expiration : 86400
7674 secret : 12345678123456781234567812345678
7775
Original file line number Diff line number Diff line change 11package top .cadecode .sra .framework .security ;
22
3+ import cn .hutool .core .lang .UUID ;
34import cn .hutool .json .JSONObject ;
45import cn .hutool .jwt .JWT ;
56import lombok .Data ;
1617 */
1718@ Data
1819@ Component
19- @ ConfigurationProperties ("sra.security.jwt " )
20- public class JwtTokenHolder {
20+ @ ConfigurationProperties ("sra.security.token " )
21+ public class TokenAuthHolder {
2122
2223 /**
2324 * token 请求头字段
2425 */
2526 private String header ;
2627
27- /**
28- * refresh token 请求头字段
29- */
30- private String refreshHeader ;
31-
3228 /**
3329 * token 过期时间,单位秒
3430 */
3531 private Long expiration ;
3632
37- /**
38- * refresh token 过期时间,单位秒
39- */
40- private Long refreshExpiration ;
41-
4233 /**
4334 * 密钥
4435 */
@@ -49,7 +40,7 @@ public class JwtTokenHolder {
4940 private static final String ROLES_KEY = "roles" ;
5041
5142 /**
52- * 生成 token
43+ * 生成 Jwt token
5344 *
5445 * @param id 用户 ID
5546 * @param roles 角色
@@ -109,4 +100,14 @@ public JSONObject getPayload(String token) {
109100 public String getPayloadStr (String token ) {
110101 return JWT .of (token ).getPayloads ().toString ();
111102 }
103+
104+ /**
105+ * 生成 UUID token,用作 redis key
106+ *
107+ * @return UUID 字符串
108+ */
109+ public String generateUUID () {
110+ // 使用两个 UUID 拼接
111+ return UUID .fastUUID ().toString (true ) + UUID .fastUUID ().toString (true );
112+ }
112113}
You can’t perform that action at this time.
0 commit comments