Class JwtClaims
java.lang.Object
cloud.opencode.base.crypto.jwt.JwtClaims
JWT Claims - Container for JWT claims (payload)
JWT 声明 - JWT 声明(载荷)容器
Provides a fluent builder API for constructing JWT claims with both standard registered claims and custom claims.
提供流式构建器 API 用于构造 JWT 声明,支持标准注册声明和自定义声明。
Standard Claims (RFC 7519) | 标准声明:
- iss (issuer) - 签发者
- sub (subject) - 主题
- aud (audience) - 受众
- exp (expiration time) - 过期时间
- nbf (not before) - 生效时间
- iat (issued at) - 签发时间
- jti (JWT ID) - JWT 唯一标识
Usage Examples | 使用示例:
JwtClaims claims = JwtClaims.builder()
.issuer("auth-service")
.subject("user123")
.audience("api-service")
.expiresIn(Duration.ofHours(1))
.claim("role", "admin")
.claim("permissions", List.of("read", "write"))
.build();
Features | 主要功能:
- See class description for details - 详见类描述
Security | 安全性:
- Thread-safe: Yes - 线程安全: 是
- Null-safe: Yes - 空值安全: 是
- Since:
- JDK 25, opencode-base-crypto V1.2.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionasMap()Returns the claims as a map.audience()Returns the audience claim.static JwtClaims.Builderbuilder()Creates a new claims builder.booleanChecks if a claim is present.static JwtClaimsempty()Creates empty claims.booleanReturns the expiration time.Returns a claim value.getBoolean(String name) Returns a claim value as Boolean.getInstant(String name) Returns a claim value as Instant.Returns a claim value as Integer.<T> List<T> Returns a claim value as List.Returns a claim value as Long.Returns a claim value as String.inthashCode()booleanChecks if the token has expired.booleanChecks if the token is not yet valid.issuedAt()Returns the issued-at time.issuer()Returns the issuer claim.jwtId()Returns the JWT ID.names()Returns all claim names.Returns the not-before time.static JwtClaimsCreates claims from a map.subject()Returns the subject claim.toString()
-
Field Details
-
ISSUER
- See Also:
-
SUBJECT
- See Also:
-
AUDIENCE
- See Also:
-
EXPIRATION
- See Also:
-
NOT_BEFORE
- See Also:
-
ISSUED_AT
- See Also:
-
JWT_ID
- See Also:
-
-
Method Details
-
builder
Creates a new claims builder. 创建新的声明构建器。- Returns:
- a new builder
-
of
-
empty
-
issuer
Returns the issuer claim. 返回签发者声明。- Returns:
- the issuer, or null if not present
-
subject
Returns the subject claim. 返回主题声明。- Returns:
- the subject, or null if not present
-
audience
-
expiration
Returns the expiration time. 返回过期时间。- Returns:
- the expiration instant, or null if not present
-
notBefore
Returns the not-before time. 返回生效时间。- Returns:
- the not-before instant, or null if not present
-
issuedAt
Returns the issued-at time. 返回签发时间。- Returns:
- the issued-at instant, or null if not present
-
jwtId
-
get
-
getString
-
getInt
-
getLong
-
getBoolean
-
getInstant
-
getList
-
contains
Checks if a claim is present. 检查声明是否存在。- Parameters:
name- the claim name- Returns:
- true if the claim exists
-
names
-
asMap
-
isExpired
public boolean isExpired()Checks if the token has expired. 检查令牌是否已过期。- Returns:
- true if expired
-
isNotYetValid
public boolean isNotYetValid()Checks if the token is not yet valid. 检查令牌是否尚未生效。- Returns:
- true if not yet valid
-
equals
-
hashCode
-
toString
-