Package dev.relism.flash.ext.oidc
Class JwtValidator
java.lang.Object
dev.relism.flash.ext.oidc.JwtValidator
Validates JWTs against a remote JWKS endpoint using Nimbus JOSE+JWT.
Two validation modes:
validate(String)— access token bearer validation per request (hot path). Checks signature,iss,exp,iat,sub. ThrowsHttpException401 so the middleware can short-circuit.validateIdToken(String, String)— ID token validation at callback time. Checks signature,iss,aud== clientId,exp,iat,sub, andnonce(if provided). ThrowsOidcValidationException(not 401 — it is a provider/protocol error).
JWKS handling: the shared JWKSource uses caching + rate-limiting + automatic
retry-on-key-miss (key rotation). Both processors share the same source — one JWKS
fetch serves both token types.
-
Constructor Summary
ConstructorsConstructorDescriptionJwtValidator(String jwksUri, String issuer, String clientId, String algorithm, HttpClient http) -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanReturnstrueiftokenis a signed JWT (three dot-separated Base64URL parts).Validates a JWT access token (bearer on incoming request).validateIdToken(String idToken, String nonce) Validates an ID token received directly from the token endpoint.
-
Constructor Details
-
JwtValidator
public JwtValidator(String jwksUri, String issuer, String clientId, String algorithm, HttpClient http) - Parameters:
jwksUri- JWKS endpoint URIissuer- ExpectedissclaimclientId- OAuth2 client ID — used as expectedaudin ID tokensalgorithm- JWS algorithm (e.g."RS256")http- SharedHttpClientused for all JWKS fetches — already configured with the correct TLS policy (trust-all or default trust store).
-
-
Method Details
-
validate
Validates a JWT access token (bearer on incoming request). Returns claims on success; throwsHttpException401 on any failure. -
validateIdToken
Validates an ID token received directly from the token endpoint.Checks: signature (JWKS),
iss,aud== clientId,exp,iat,sub, andnonceif provided.- Parameters:
idToken- Raw ID token stringnonce- Nonce sent in the authorization request;nullto skip check- Throws:
OidcValidationException- on any validation failure
-
isJwt
Returnstrueiftokenis a signed JWT (three dot-separated Base64URL parts). Used to detect opaque access tokens before attempting JWKS validation.
-