Class JwtValidator.Builder
- java.lang.Object
-
- org.wildfly.security.auth.realm.token.validator.JwtValidator.Builder
-
- Enclosing class:
- JwtValidator
public static class JwtValidator.Builder extends Object
-
-
Field Summary
Fields Modifier and Type Field Description private Set<String>audienceprivate static intCONNECTION_TIMEOUTprivate intconnectionTimeoutprivate HostnameVerifierhostnameVerifierprivate Set<String>issuersprivate static intMIN_TIME_BETWEEN_REQUESTSprivate intminTimeBetweenRequestsprivate Map<String,PublicKey>namedKeysprivate PublicKeypublicKeyprivate intreadTimeoutprivate SSLContextsslContextprivate longupdateTimeout
-
Constructor Summary
Constructors Modifier Constructor Description privateBuilder()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description JwtValidator.Builderaudience(String... audience)Defines one or more string values representing the audiences supported by this configuration.JwtValidatorbuild()Returns aJwtValidatorinstance based on all the configuration provided with this builder.JwtValidator.BuilderconnectionTimeout(int connectionTimeout)Sets the connection timeout to a specified timeout, in milliseconds.JwtValidator.Builderissuer(String... issuer)Defines one or more string values representing an unique identifier for the entities that are allowed as issuers of a given JWT.JwtValidator.BuilderpublicKey(byte[] publicKeyPem)A default public key in its PEM format used to validate the signature of tokens withoutkidheader parameter.JwtValidator.BuilderpublicKey(PublicKey publicKey)A defaultPublicKeyformat used to validate the signature of tokens withoutkidheader parameter.JwtValidator.BuilderpublicKeys(Map<String,PublicKey> namedKeys)JwtValidator.BuilderreadTimeout(int readTimeout)Sets the read timeout to a specified timeout, in milliseconds.JwtValidator.BuildersetJkuMinTimeBetweenRequests(int minTimeBetweenRequests)The time in which there will be no more requests to retrieve the keys from the jkws URL.JwtValidator.BuildersetJkuTimeout(long timeout)A timeout for cached jwks when using jku claim.JwtValidator.BuilderuseSslContext(SSLContext sslContext)A predefinedSSLContextthat will be used to connect to the jku endpoint when retrieving remote keys.JwtValidator.BuilderuseSslHostnameVerifier(HostnameVerifier hostnameVerifier)AHostnameVerifierthat will be used to validate the hostname when using SSL/TLS.
-
-
-
Field Detail
-
CONNECTION_TIMEOUT
private static final int CONNECTION_TIMEOUT
- See Also:
- Constant Field Values
-
MIN_TIME_BETWEEN_REQUESTS
private static final int MIN_TIME_BETWEEN_REQUESTS
- See Also:
- Constant Field Values
-
publicKey
private PublicKey publicKey
-
hostnameVerifier
private HostnameVerifier hostnameVerifier
-
sslContext
private SSLContext sslContext
-
updateTimeout
private long updateTimeout
-
connectionTimeout
private int connectionTimeout
-
readTimeout
private int readTimeout
-
minTimeBetweenRequests
private int minTimeBetweenRequests
-
-
Method Detail
-
issuer
public JwtValidator.Builder issuer(String... issuer)
Defines one or more string values representing an unique identifier for the entities that are allowed as issuers of a given JWT. During validation JWT tokens must have a
issclaim that contains one of the values defined here.If not provided, the validator will not perform validations based on the issuer claim.
- Parameters:
issuer- one or more string values representing the valid issuers- Returns:
- this instance
-
audience
public JwtValidator.Builder audience(String... audience)
Defines one or more string values representing the audiences supported by this configuration. During validation JWT tokens must have an
audclaim that contains one of the values defined here.If not provided, the validator will not perform validations based on the audience claim.
- Parameters:
audience- one or more string values representing the valid audiences- Returns:
- this instance
-
publicKey
public JwtValidator.Builder publicKey(byte[] publicKeyPem)
A default public key in its PEM format used to validate the signature of tokens without
kidheader parameter.If not provided, the validator will not validate signatures.
- Parameters:
publicKeyPem- the public key in its PEM format- Returns:
- this instance
-
publicKey
public JwtValidator.Builder publicKey(PublicKey publicKey)
A default
PublicKeyformat used to validate the signature of tokens withoutkidheader parameter.If not provided, the validator will not validate signatures.
- Parameters:
publicKey- the public key in its PEM format- Returns:
- this instance
-
publicKeys
public JwtValidator.Builder publicKeys(Map<String,PublicKey> namedKeys)
A
PublicKeymap, which is used for validating tokens withkidand withoutjkuheader parameter.- Parameters:
namedKeys- map of public keys for toen verification, where the maps key stand for kid- Returns:
- this instance
-
useSslContext
public JwtValidator.Builder useSslContext(SSLContext sslContext)
A predefined
SSLContextthat will be used to connect to the jku endpoint when retrieving remote keys. This configuration is mandatory if using jku claims.- Parameters:
sslContext- the SSL context- Returns:
- this instance
-
useSslHostnameVerifier
public JwtValidator.Builder useSslHostnameVerifier(HostnameVerifier hostnameVerifier)
A
HostnameVerifierthat will be used to validate the hostname when using SSL/TLS. This configuration is mandatory if using jku claims.- Parameters:
hostnameVerifier- the hostname verifier- Returns:
- this instance
-
setJkuTimeout
public JwtValidator.Builder setJkuTimeout(long timeout)
A timeout for cached jwks when using jku claim. After this timeout, the keys of need to be re-cached before use. Default value is 2 minutes.
- Parameters:
timeout- timeout in ms before keys needs to be re-cached- Returns:
- this instance
-
connectionTimeout
public JwtValidator.Builder connectionTimeout(int connectionTimeout)
Sets the connection timeout to a specified timeout, in milliseconds. A non-zero value specifies the timeout when connecting to a resource. A timeout of zero is interpreted as an infinite timeout.- Parameters:
connectionTimeout- the connection timeout- Returns:
- this instance
-
readTimeout
public JwtValidator.Builder readTimeout(int readTimeout)
Sets the read timeout to a specified timeout, in milliseconds. A non-zero value specifies the timeout when reading from Input stream when a connection is established to a resource. A timeout of zero is interpreted as an infinite timeout.- Parameters:
readTimeout- the read timeout- Returns:
- this instance
-
setJkuMinTimeBetweenRequests
public JwtValidator.Builder setJkuMinTimeBetweenRequests(int minTimeBetweenRequests)
The time in which there will be no more requests to retrieve the keys from the jkws URL.
- Parameters:
minTimeBetweenRequests- The time in millis- Returns:
- this instance
-
build
public JwtValidator build()
Returns aJwtValidatorinstance based on all the configuration provided with this builder.- Returns:
- a new
JwtValidatorinstance with all the given configuration
-
-