Class UserContext

Object
org.apache.spark.security.UserContext

@DeveloperApi public final class UserContext extends Object
:: DeveloperApi :: Represents the authenticated user's identity context on the driver side.

This class holds the OIDC token information used to derive short-lived ServiceCredential instances via credential providers. It is intentionally not Serializable and must never be transmitted to executors. The rawToken field is always redacted in toString().

Since:
4.4.0
  • Constructor Details

    • UserContext

      public UserContext(String principal, String issuer, String rawToken, Instant issuedAt, Instant expiresAt)
      Constructs a new UserContext.
      Parameters:
      principal - the sub claim from the JWT (must not be null)
      issuer - the iss claim from the JWT (must not be null)
      rawToken - the raw OIDC JWT string (must not be null)
      issuedAt - token issue time (may be null)
      expiresAt - token expiry time (may be null)
  • Method Details

    • getPrincipal

      public String getPrincipal()
      Returns the sub claim (principal identifier).
    • getIssuer

      public String getIssuer()
      Returns the iss claim (token issuer).
    • getRawToken

      public String getRawToken()
      Returns the raw OIDC JWT. This value must never be logged or transmitted to executors.
    • getIssuedAt

      public Instant getIssuedAt()
      Returns the token issue time, or null if not set.
    • getExpiresAt

      public Instant getExpiresAt()
      Returns the token expiry time, or null if not set.
    • isExpired

      public boolean isExpired(Instant now)
      Returns true if this context's token has expired relative to the given instant. If expiresAt is null, this method returns false.
      Parameters:
      now - the current time to compare against (must not be null)
      Returns:
      whether the token is expired
    • toString

      public String toString()
      Returns a string representation with the rawToken redacted as [REDACTED].
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object o)
      Equality is based on identity fields (principal, issuer) and token validity window (issuedAt, expiresAt). The secret rawToken is intentionally excluded: UserContext is driver-only and never used as a map key, so there is no need to compare secret material.
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object