Record Class IntrospectionResult
java.lang.Object
java.lang.Record
cloud.opencode.base.oauth2.introspection.IntrospectionResult
public record IntrospectionResult(boolean active, String scope, String clientId, String username, String tokenType, Instant exp, Instant iat, Instant nbf, String sub, String aud, String iss, String jti, Map<String,Object> claims)
extends Record
Token Introspection Result (RFC 7662)
Token 内省结果(RFC 7662)
Immutable record representing the response from an OAuth2 token introspection endpoint as defined in RFC 7662. Contains information about the active state of a token and its associated metadata.
不可变记录,表示 RFC 7662 定义的 OAuth2 Token 内省端点的响应。包含 Token 的活跃状态及其 关联的元数据信息。
Features | 主要功能:
- RFC 7662 compliant introspection result - 符合 RFC 7662 的内省结果
- Immutable with defensive copy of claims map - 不可变,对 claims map 进行防御性拷贝
- Convenience methods for expiration and scope checking - 便捷的过期和权限范围检查方法
- Builder pattern for flexible construction - 构建器模式支持灵活构建
Usage Examples | 使用示例:
// Check if token is active and has required scope
// 检查 Token 是否活跃且具有所需权限范围
IntrospectionResult result = tokenIntrospection.introspect(token);
if (result.active() && result.hasScope("read")) {
// Token is valid and has read scope
}
// Build result manually
// 手动构建结果
IntrospectionResult result = IntrospectionResult.builder()
.active(true)
.scope("read write")
.clientId("my-client")
.sub("user123")
.build();
Security | 安全性:
- Thread-safe: Yes (immutable record) - 线程安全: 是(不可变记录)
- Null-safe: Yes (claims defensively copied) - 空值安全: 是(claims 进行防御性拷贝)
- Since:
- JDK 25, opencode-base-oauth2 V1.0.3
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classIntrospectionResult Builder IntrospectionResult 构建器 -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanactive()Returns the value of theactiverecord component.aud()Returns the value of theaudrecord component.static IntrospectionResult.Builderbuilder()Create a new builder.claims()Returns the value of theclaimsrecord component.clientId()Returns the value of theclientIdrecord component.final booleanIndicates whether some other object is "equal to" this one.exp()Returns the value of theexprecord component.final inthashCode()Returns a hash code value for this object.booleanCheck if the token has a specific scope.iat()Returns the value of theiatrecord component.booleanCheck if the token has expired based on the exp claim.iss()Returns the value of theissrecord component.jti()Returns the value of thejtirecord component.nbf()Returns the value of thenbfrecord component.scope()Returns the value of thescoperecord component.scopes()Parse the scope string into a set of individual scopes.sub()Returns the value of thesubrecord component.Returns the value of thetokenTyperecord component.final StringtoString()Returns a string representation of this record class.username()Returns the value of theusernamerecord component.
-
Constructor Details
-
IntrospectionResult
-
-
Method Details
-
isExpired
public boolean isExpired()Check if the token has expired based on the exp claim. 根据 exp 声明检查 Token 是否已过期。- Returns:
- true if the token has expired, false if exp is null or not yet expired | 如果 Token 已过期返回 true,如果 exp 为 null 或尚未过期返回 false
-
hasScope
Check if the token has a specific scope. 检查 Token 是否具有特定的权限范围。- Parameters:
requiredScope- the scope to check | 要检查的权限范围- Returns:
- true if the scope is present | 如果存在该权限范围返回 true
- Throws:
NullPointerException- if requiredScope is null | 如果 requiredScope 为 null 则抛出
-
scopes
-
builder
Create a new builder. 创建新的构建器。- Returns:
- the builder | 构建器
-
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. Reference components are compared withObjects::equals(Object,Object); primitive components are compared with thecomparemethod from their corresponding wrapper classes. -
active
public boolean active()Returns the value of theactiverecord component.- Returns:
- the value of the
activerecord component
-
scope
Returns the value of thescoperecord component.- Returns:
- the value of the
scoperecord component
-
clientId
Returns the value of theclientIdrecord component.- Returns:
- the value of the
clientIdrecord component
-
username
Returns the value of theusernamerecord component.- Returns:
- the value of the
usernamerecord component
-
tokenType
Returns the value of thetokenTyperecord component.- Returns:
- the value of the
tokenTyperecord component
-
exp
Returns the value of theexprecord component.- Returns:
- the value of the
exprecord component
-
iat
Returns the value of theiatrecord component.- Returns:
- the value of the
iatrecord component
-
nbf
Returns the value of thenbfrecord component.- Returns:
- the value of the
nbfrecord component
-
sub
Returns the value of thesubrecord component.- Returns:
- the value of the
subrecord component
-
aud
Returns the value of theaudrecord component.- Returns:
- the value of the
audrecord component
-
iss
Returns the value of theissrecord component.- Returns:
- the value of the
issrecord component
-
jti
Returns the value of thejtirecord component.- Returns:
- the value of the
jtirecord component
-
claims
-