public class JWTSignatureValidator extends java.lang.Object implements TokenValidator
It performs fast local token validation without the need to immediately contact the authorization server. for that it relies on the JWKS endpoint exposed at authorization server, which is a standard OAuth2 public endpoint containing the information about public keys that can be used to validate JWT signatures.
A single threaded refresh job is run periodically or upon detecting an unknown signing key, that fetches the latest trusted public keys for signature validation from authorization server. If the refresh job is unsuccessful it employs the so called 'exponential back-off' to retry later in order to reduce any out-of-sync time with the authorization server while still not flooding the server with endless consecutive requests.
| Constructor and Description |
|---|
JWTSignatureValidator(java.lang.String validatorId,
java.lang.String clientId,
java.lang.String clientSecret,
TokenProvider bearerTokenProvider,
java.lang.String keysEndpointUri,
javax.net.ssl.SSLSocketFactory socketFactory,
javax.net.ssl.HostnameVerifier verifier,
PrincipalExtractor principalExtractor,
java.lang.String groupsClaimQuery,
java.lang.String groupsClaimDelimiter,
java.lang.String validIssuerUri,
int refreshSeconds,
int refreshMinPauseSeconds,
int expirySeconds,
boolean ignoreKeyUse,
boolean checkAccessTokenType,
java.lang.String audience,
java.lang.String customClaimCheck,
int connectTimeoutSeconds,
int readTimeoutSeconds,
boolean enableMetrics,
boolean failFast,
boolean includeAcceptHeader)
Create a new instance.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Close any allocated resources like background threads
|
java.lang.String |
getValidatorId()
Return the id of this validator
|
TokenInfo |
validate(java.lang.String token)
Validate the passed access token return it wrapped in TokenInfo with
|
public JWTSignatureValidator(java.lang.String validatorId,
java.lang.String clientId,
java.lang.String clientSecret,
TokenProvider bearerTokenProvider,
java.lang.String keysEndpointUri,
javax.net.ssl.SSLSocketFactory socketFactory,
javax.net.ssl.HostnameVerifier verifier,
PrincipalExtractor principalExtractor,
java.lang.String groupsClaimQuery,
java.lang.String groupsClaimDelimiter,
java.lang.String validIssuerUri,
int refreshSeconds,
int refreshMinPauseSeconds,
int expirySeconds,
boolean ignoreKeyUse,
boolean checkAccessTokenType,
java.lang.String audience,
java.lang.String customClaimCheck,
int connectTimeoutSeconds,
int readTimeoutSeconds,
boolean enableMetrics,
boolean failFast,
boolean includeAcceptHeader)
validatorId - A unique id to associate with this validator for the purpose of validator lifecycle and metrics trackingclientId - The clientId of the OAuth2 client representing this Kafka broker - used to authenticate to the introspection endpoint using Basic authenticationclientSecret - The secret of the OAuth2 client representing this Kafka broker - used to authenticate to the introspection endpoint using Basic authenticationbearerTokenProvider - The provider of the bearer token as an alternative to clientId and secret of the OAuth2 client representing this Kafka broker - used to authenticate to the introspection endpoint using Bearer authenticationkeysEndpointUri - The JWKS endpoint url at the authorization serversocketFactory - The optional SSL socket factory to use when establishing the connection to authorization serververifier - The optional hostname verifier used to validate the TLS certificate by the authorization serverprincipalExtractor - The object used to extract the username from the JWT tokengroupsClaimQuery - The optional JSONPath query for group extractiongroupsClaimDelimiter - The optional delimiter for group extractionvalidIssuerUri - The required value of the 'iss' claim in JWT tokenrefreshSeconds - The optional time interval between two consecutive regular JWKS keys refresh runsrefreshMinPauseSeconds - The optional minimum pause between two consecutive JWKS keys refreshes.expirySeconds - The maximum time to trust the unrefreshed JWKS keys. If keys are not successfully refreshed within this time, the validation will start failing.ignoreKeyUse - Should any key present in JWKS key set be considered a public key for signature checkingcheckAccessTokenType - Should the 'typ' claim in the token be validated (be equal to 'Bearer')audience - The optional audiencecustomClaimCheck - The optional JSONPath filter query for additional custom claim checkingconnectTimeoutSeconds - The maximum time to wait for connection to authorization server to be established (in seconds)readTimeoutSeconds - The maximum time to wait for response from authorization server after connection has been established and request sent (in seconds)enableMetrics - The switch that enables metrics collectionfailFast - Should exception be thrown during initialisation if unable to retrieve JWKS keysincludeAcceptHeader - Should we send the Accept header when making outbound http requestspublic TokenInfo validate(java.lang.String token)
TokenValidatorvalidate in interface TokenValidatortoken - An access token to validatepublic java.lang.String getValidatorId()
TokenValidatorgetValidatorId in interface TokenValidatorpublic void close()
TokenValidatorclose in interface TokenValidatorCopyright © 2024. All rights reserved.