Record Class JwtClaims
java.lang.Object
java.lang.Record
cloud.opencode.base.oauth2.oidc.JwtClaims
public record JwtClaims(String iss, String sub, List<String> aud, Instant exp, Instant nbf, Instant iat, String jti, String nonce, String azp, Map<String,Object> claims)
extends Record
JWT Claims
JWT 声明
Represents decoded JWT claims from an ID token or access token.
表示从 ID 令牌或访问令牌解码的 JWT 声明。
Note | 注意:
This parser does NOT verify the JWT signature. For security-critical applications, use a proper JWT library with signature verification.
此解析器不验证 JWT 签名。对于安全关键的应用程序,请使用具有签名验证的正式 JWT 库。
Usage Examples | 使用示例:
// Parse JWT without verification
JwtClaims claims = JwtClaims.parse(idToken);
String subject = claims.sub();
String issuer = claims.iss();
Instant expiry = claims.exp();
// Check if expired
if (claims.isExpired()) {
// Token is expired
}
Features | 主要功能:
- JWT claims representation for OIDC tokens - OIDC令牌的JWT声明表示
- Standard claim accessors (sub, iss, exp, iat) - 标准声明访问器(sub、iss、exp、iat)
Security | 安全性:
- Thread-safe: Yes (immutable record) - 线程安全: 是(不可变记录)
- Null-safe: Yes (validates inputs) - 空值安全: 是(验证输入)
- Since:
- JDK 25, opencode-base-oauth2 V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaud()Returns the value of theaudrecord component.audience()Get the first audience 获取第一个受众azp()Returns the value of theazprecord component.claims()Returns the value of theclaimsrecord component.final booleanIndicates whether some other object is "equal to" this one.exp()Returns the value of theexprecord component.Get a custom claim value 获取自定义声明值getClaimAsString(String name) Get a custom claim value as string 获取自定义声明值作为字符串booleanhasAudience(String audience) Check if the token has the specified audience 检查令牌是否具有指定的受众final inthashCode()Returns a hash code value for this object.iat()Returns the value of theiatrecord component.booleanCheck if the token is expired 检查令牌是否已过期booleanCheck if the token is not yet valid 检查令牌是否尚未生效iss()Returns the value of theissrecord component.booleanisValid()Check if the token is currently valid (not expired and not before nbf) 检查令牌当前是否有效(未过期且不在 nbf 之前)jti()Returns the value of thejtirecord component.nbf()Returns the value of thenbfrecord component.nonce()Returns the value of thenoncerecord component.static JwtClaimsParse a JWT token (without signature verification) 解析 JWT 令牌(不验证签名)sub()Returns the value of thesubrecord component.final StringtoString()Returns a string representation of this record class.
-
Constructor Details
-
JwtClaims
-
-
Method Details
-
isExpired
public boolean isExpired()Check if the token is expired 检查令牌是否已过期- Returns:
- true if expired | 已过期返回 true
-
isNotYetValid
public boolean isNotYetValid()Check if the token is not yet valid 检查令牌是否尚未生效- Returns:
- true if not yet valid | 尚未生效返回 true
-
isValid
public boolean isValid()Check if the token is currently valid (not expired and not before nbf) 检查令牌当前是否有效(未过期且不在 nbf 之前)- Returns:
- true if valid | 有效返回 true
-
getClaim
-
getClaimAsString
-
audience
Get the first audience 获取第一个受众- Returns:
- the first audience or null | 第一个受众或 null
-
hasAudience
Check if the token has the specified audience 检查令牌是否具有指定的受众- Parameters:
audience- the audience to check | 要检查的受众- Returns:
- true if has audience | 有受众返回 true
-
parse
Parse a JWT token (without signature verification) 解析 JWT 令牌(不验证签名)- Parameters:
token- the JWT token | JWT 令牌- Returns:
- the claims | 声明
- Throws:
OAuth2Exception- if parsing fails | 如果解析失败
-
toString
-
hashCode
-
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared withObjects::equals(Object,Object). -
iss
Returns the value of theissrecord component.- Returns:
- the value of the
issrecord component
-
sub
Returns the value of thesubrecord component.- Returns:
- the value of the
subrecord component
-
aud
-
exp
Returns the value of theexprecord component.- Returns:
- the value of the
exprecord component
-
nbf
Returns the value of thenbfrecord component.- Returns:
- the value of the
nbfrecord component
-
iat
Returns the value of theiatrecord component.- Returns:
- the value of the
iatrecord component
-
jti
Returns the value of thejtirecord component.- Returns:
- the value of the
jtirecord component
-
nonce
Returns the value of thenoncerecord component.- Returns:
- the value of the
noncerecord component
-
azp
Returns the value of theazprecord component.- Returns:
- the value of the
azprecord component
-
claims
-