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:
  • Constructor Details

  • 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

      public boolean hasScope(String requiredScope)
      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

      public Set<String> scopes()
      Parse the scope string into a set of individual scopes. 将权限范围字符串解析为单独权限范围的集合。
      Returns:
      unmodifiable set of scopes, empty set if scope is null or blank | 不可修改的权限范围集合,如果 scope 为 null 或空白则返回空集合
    • builder

      public static IntrospectionResult.Builder builder()
      Create a new builder. 创建新的构建器。
      Returns:
      the builder | 构建器
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      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 with Objects::equals(Object,Object); primitive components are compared with the compare method from their corresponding wrapper classes.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • active

      public boolean active()
      Returns the value of the active record component.
      Returns:
      the value of the active record component
    • scope

      public String scope()
      Returns the value of the scope record component.
      Returns:
      the value of the scope record component
    • clientId

      public String clientId()
      Returns the value of the clientId record component.
      Returns:
      the value of the clientId record component
    • username

      public String username()
      Returns the value of the username record component.
      Returns:
      the value of the username record component
    • tokenType

      public String tokenType()
      Returns the value of the tokenType record component.
      Returns:
      the value of the tokenType record component
    • exp

      public Instant exp()
      Returns the value of the exp record component.
      Returns:
      the value of the exp record component
    • iat

      public Instant iat()
      Returns the value of the iat record component.
      Returns:
      the value of the iat record component
    • nbf

      public Instant nbf()
      Returns the value of the nbf record component.
      Returns:
      the value of the nbf record component
    • sub

      public String sub()
      Returns the value of the sub record component.
      Returns:
      the value of the sub record component
    • aud

      public String aud()
      Returns the value of the aud record component.
      Returns:
      the value of the aud record component
    • iss

      public String iss()
      Returns the value of the iss record component.
      Returns:
      the value of the iss record component
    • jti

      public String jti()
      Returns the value of the jti record component.
      Returns:
      the value of the jti record component
    • claims

      public Map<String,Object> claims()
      Returns the value of the claims record component.
      Returns:
      the value of the claims record component