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>
audience
private static int
CONNECTION_TIMEOUT
private int
connectionTimeout
private HostnameVerifier
hostnameVerifier
private Set<String>
issuers
private static int
MIN_TIME_BETWEEN_REQUESTS
private int
minTimeBetweenRequests
private Map<String,PublicKey>
namedKeys
private PublicKey
publicKey
private int
readTimeout
private SSLContext
sslContext
private long
updateTimeout
-
Constructor Summary
Constructors Modifier Constructor Description private
Builder()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description JwtValidator.Builder
audience(String... audience)
Defines one or more string values representing the audiences supported by this configuration.JwtValidator
build()
Returns aJwtValidator
instance based on all the configuration provided with this builder.JwtValidator.Builder
connectionTimeout(int connectionTimeout)
Sets the connection timeout to a specified timeout, in milliseconds.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.JwtValidator.Builder
publicKey(byte[] publicKeyPem)
A default public key in its PEM format used to validate the signature of tokens withoutkid
header parameter.JwtValidator.Builder
publicKey(PublicKey publicKey)
A defaultPublicKey
format used to validate the signature of tokens withoutkid
header parameter.JwtValidator.Builder
publicKeys(Map<String,PublicKey> namedKeys)
JwtValidator.Builder
readTimeout(int readTimeout)
Sets the read timeout to a specified timeout, in milliseconds.JwtValidator.Builder
setJkuMinTimeBetweenRequests(int minTimeBetweenRequests)
The time in which there will be no more requests to retrieve the keys from the jkws URL.JwtValidator.Builder
setJkuTimeout(long timeout)
A timeout for cached jwks when using jku claim.JwtValidator.Builder
useSslContext(SSLContext sslContext)
A predefinedSSLContext
that will be used to connect to the jku endpoint when retrieving remote keys.JwtValidator.Builder
useSslHostnameVerifier(HostnameVerifier hostnameVerifier)
AHostnameVerifier
that 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
iss
claim 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
aud
claim 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
kid
header 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
PublicKey
format used to validate the signature of tokens withoutkid
header 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
PublicKey
map, which is used for validating tokens withkid
and withoutjku
header 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
SSLContext
that 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
HostnameVerifier
that 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 aJwtValidator
instance based on all the configuration provided with this builder.- Returns:
- a new
JwtValidator
instance with all the given configuration
-
-