java.lang.Object
org.miaixz.bus.auth.metric.jwt.Claims
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
JWTHeader,JWTPayload
JWT Claims 认证类,用于存储和处理 JWT 的 header 或 payload 数据。
Claims 表示 JWT 中的键值对集合,支持解析 Base64 编码的 JSON 字符串,存储为 Map 结构, 并提供设置、获取和序列化功能。
- Since:
- Java 17+
- Author:
- Kimi Liu
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription获取指定名称的属性值。获取 Claims 的键值对集合。void解析 Base64 编码的 JSON 字符串并存储为 Claims。void批量添加 Claims 属性。void设置 Claims 属性。toString()将 Claims 转换为 JSON 字符串。
-
Constructor Details
-
Claims
public Claims()
-
-
Method Details
-
setClaim
设置 Claims 属性。如果属性值为 null,则移除该属性;否则将属性名和值存入 Map。
- Parameters:
name- 属性名,不能为 nullvalue- 属性值- Throws:
IllegalArgumentException- 如果属性名为空
-
putAll
批量添加 Claims 属性。遍历提供的 Map,将每个键值对添加到 Claims 中。
- Parameters:
headerClaims- 包含多个属性的 Map
-
getClaim
获取指定名称的属性值。- Parameters:
name- 属性名- Returns:
- 属性值,若不存在则返回 null
-
getClaimsJson
获取 Claims 的键值对集合。- Returns:
- Claims 的 Map 表示
-
parse
解析 Base64 编码的 JSON 字符串并存储为 Claims。将 Base64 解码后的 JSON 字符串解析为键值对,存入内部 Map。
- Parameters:
tokenPart- Base64 编码的 JSON 字符串charset- 字符编码- Throws:
IllegalArgumentException- 如果 JSON 格式不正确
-
toString
将 Claims 转换为 JSON 字符串。
-