Class OAuthTokenValidationResult

java.lang.Object
org.apache.camel.spi.OAuthTokenValidationResult

public final class OAuthTokenValidationResult extends Object
Result of validating an incoming OAuth 2.0 bearer token.

Contains the validation outcome (valid/invalid), extracted claims from the token, and an error message when the token is invalid.

Since:
4.21
  • Method Details

    • valid

      public static OAuthTokenValidationResult valid(@Nullable String subject, @Nullable String issuer, @Nullable List<String> audience, @Nullable List<String> scopes, @Nullable Map<String,Object> claims, long expiresAt)
      Creates a result for a successfully validated token.
      Since:
      4.21
    • invalid

      public static OAuthTokenValidationResult invalid(String error)
      Creates a result for a token that failed validation.
      Since:
      4.21
    • invalid

      public static OAuthTokenValidationResult invalid(OAuthTokenValidationResult.ErrorCode errorCode, String error)
      Creates a result for a token that failed validation.
      Since:
      4.21
    • isValid

      public boolean isValid()
      Whether the token passed validation.
      Since:
      4.21
    • getSubject

      public @Nullable String getSubject()
      The sub claim from the token, or null if not present.
      Since:
      4.21
    • getName

      public @Nullable String getName()
      The principal name for route-level decisions.

      This implementation returns the sub claim.

      Since:
      4.21
    • getIssuer

      public @Nullable String getIssuer()
      The iss claim from the token, or null if not present.
      Since:
      4.21
    • getAudience

      public List<String> getAudience()
      The aud claim(s) from the token.
      Since:
      4.21
    • getScopes

      public List<String> getScopes()
      The scope claim from the token, split into individual scopes.
      Since:
      4.21
    • hasScope

      public boolean hasScope(String scope)
      Whether the token has the given OAuth scope.
      Since:
      4.21
    • getClaims

      public Map<String,Object> getClaims()
      All claims from the token payload (JWT) or introspection response.
      Since:
      4.21
    • getAttributes

      public Map<String,Object> getAttributes()
      All attributes extracted from the token payload (JWT) or introspection response.

      This is an alias for getClaims() using principal-oriented terminology.

      Since:
      4.21
    • getAttribute

      public @Nullable Object getAttribute(String name)
      Gets an attribute extracted from the token payload (JWT) or introspection response.
      Since:
      4.21
    • getAttribute

      public <T> @Nullable T getAttribute(String name, Class<T> type)
      Gets an attribute extracted from the token payload (JWT) or introspection response and casts it to the requested type.
      Throws:
      ClassCastException - if the attribute exists but is not assignable to the requested type
      Since:
      4.21
    • getClaim

      public @Nullable Object getClaim(String name)
      Gets a claim extracted from the token payload (JWT) or introspection response.
      Since:
      4.21
    • getClaim

      public <T> @Nullable T getClaim(String name, Class<T> type)
      Gets a claim extracted from the token payload (JWT) or introspection response and casts it to the requested type.
      Throws:
      ClassCastException - if the claim exists but is not assignable to the requested type
      Since:
      4.21
    • getExpiresAt

      public long getExpiresAt()
      The exp claim as epoch seconds, or 0 if not present.
      Since:
      4.21
    • getErrorCode

      public @Nullable OAuthTokenValidationResult.ErrorCode getErrorCode()
      Stable validation failure category when the token is invalid, or null when valid.
      Since:
      4.21
    • getError

      public @Nullable String getError()
      Human-readable error message when the token is invalid, or null when valid.
      Since:
      4.21