Class JwtProvider.Builder
java.lang.Object
io.helidon.security.providers.jwt.JwtProvider.Builder
- All Implemented Interfaces:
Builder<JwtProvider.Builder, JwtProvider>, Supplier<JwtProvider>
- Enclosing class:
JwtProvider
public static final class JwtProvider.Builder
extends Object
implements Builder<JwtProvider.Builder, JwtProvider>
Fluent API builder for
JwtProvider.-
Method Summary
Modifier and TypeMethodDescriptionallowImpersonation(boolean allowImpersonation) Whether to allow impersonation by explicitly overriding username from outbound requests usingEndpointConfig.PROPERTY_OUTBOUND_IDproperty.allowUnsigned(boolean allowUnsigned) Configure support for unsigned JWTs without requiring verification JWKs.atnTokenHandler(TokenHandler tokenHandler) Token handler to extract username from request.authenticate(boolean authenticate) Whether to authenticate requests.build()Build the instance from this builder.Load this builder from a configuration.voidexpectedAudience(String audience) Audience expected in inbound JWTs.expectedIssuer(String issuer) Issuer expected in inbound JWTs.Issuer used to create new JWTs.jwkCircuitBreaker(CircuitBreaker jwkCircuitBreaker) Circuit breaker around each complete retry batch used to load verification keys from a filesystem path or URI; by default, the circuit opens after one exhausted batch and permits a recovery probe after 5 seconds.jwkCircuitBreaker(CircuitBreakerConfig jwkCircuitBreaker) Circuit breaker used when loading verification keys from a filesystem path or URI.Circuit breaker used when loading verification keys from a filesystem path or URI.jwkCircuitBreaker(Supplier<? extends CircuitBreaker> supplier) Circuit breaker used when loading verification keys from a filesystem path or URI.Retry used when loading verification keys from a filesystem path or URI; by default, it wraps two timeout-guarded attempts within an 11-second overall timeout.jwkRetry(RetryConfig jwkRetry) Retry used when loading verification keys from a filesystem path or URI.jwkRetry(Consumer<RetryConfig.Builder> consumer) Retry used when loading verification keys from a filesystem path or URI.Retry used when loading verification keys from a filesystem path or URI.jwkTimeout(Timeout jwkTimeout) Timeout applied to each attempt to load verification keys from a filesystem path or URI; it defaults to 5 seconds, must be positive, must execute on the current thread, and must not exceed the retry overall timeout.jwkTimeout(TimeoutConfig jwkTimeout) Timeout applied to each attempt to load verification keys from a filesystem path or URI.jwkTimeout(Consumer<TimeoutConfig.Builder> consumer) Timeout applied to each attempt to load verification keys from a filesystem path or URI.jwkTimeout(Supplier<? extends Timeout> supplier) Timeout applied to each attempt to load verification keys from a filesystem path or URI.jwtGroupsPath(String jwtGroupsPath) Path to the JWT payload claim containing the groups to add as role grants.jwtGroupsSeparator(String jwtGroupsSeparator) Separator used to split a string claim value into multiple groups.optional(boolean optional) Whether authentication is required.outboundConfig(OutboundConfig config) Configuration of outbound rules.propagate(boolean propagate) Whether to propagate identity.JWK resource used to sign JWTs created by us.subjectType(SubjectType subjectType) Principal type this provider extracts (and also propagates).useJwtGroups(boolean useJwtGroups) Claimgroupsfrom JWT will be used to automatically add groups to current subject (may be used withRolesAllowedannotation).JWK resource used to verify JWTs created by other parties.verifyJwk(ResourceConfig verifyJwkResource) JWK resource configuration used to verify JWTs created by other parties.Fixed JWK keys used to verify JWTs created by other parties.verifySignature(boolean shouldValidate) Configure whether to verify signatures.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Builder
get, identity, updateModifier and TypeMethodDescriptiondefault JwtProviderget()default JwtProvider.Builderidentity()Instance of this builder as the correct type.default JwtProvider.Builderupdate(Consumer<JwtProvider.Builder> consumer) Update the builder in a fluent API way.
-
Method Details
-
build
Description copied from interface:BuilderBuild the instance from this builder.- Specified by:
buildin interfaceBuilder<JwtProvider.Builder, JwtProvider>- Returns:
- instance of the built type
-
propagate
Whether to propagate identity.- Parameters:
propagate- whether to propagate identity (true) or not (false)- Returns:
- updated builder instance
-
authenticate
Whether to authenticate requests.- Parameters:
authenticate- whether to authenticate (true) or not (false)- Returns:
- updated builder instance
-
allowImpersonation
Whether to allow impersonation by explicitly overriding username from outbound requests usingEndpointConfig.PROPERTY_OUTBOUND_IDproperty. By default this is not allowed and identity can only be propagated.- Parameters:
allowImpersonation- set to true to allow impersonation- Returns:
- updated builder instance
-
allowUnsigned
Configure support for unsigned JWTs without requiring verification JWKs. If this is set totrueany JWT that has algorithm set tononeand nokiddefined will be accepted. Such a token does not trigger loading of a configured verification JWK resource. Signed tokens continue to require matching verification keys. Note that this has serious security impact - if JWT can be sent from a third party, this allows the third party to send ANY JWT and it would be accepted as valid.- Parameters:
allowUnsigned- to allow unsigned (insecure) JWT- Returns:
- updated builder instance
-
verifySignature
Configure whether to verify signatures. Signatures verification is enabled by default. You can configure the provider not to verify signatures.Make sure your service is properly secured on network level and only accessible from a secure endpoint that provides the JWTs when signature verification is disabled. If signature verification is disabled, configured claim validation still applies, but signatures are not checked.
- Parameters:
shouldValidate- set to false to disable validation of JWT signatures- Returns:
- updated builder instance
-
subjectType
Principal type this provider extracts (and also propagates).- Parameters:
subjectType- type of principal- Returns:
- updated builder instance
-
atnTokenHandler
Token handler to extract username from request.- Parameters:
tokenHandler- token handler instance- Returns:
- updated builder instance
-
optional
Whether authentication is required. By default, request will fail if the username cannot be extracted. If set to false, request will process and this provider will abstain.- Parameters:
optional- whether authentication is optional (true) or required (false)- Returns:
- updated builder instance
-
outboundConfig
Configuration of outbound rules.- Parameters:
config- outbound configuration, each target may contain custom objectJwtProvider.JwtOutboundTargetto add our configuration.- Returns:
- updated builder instance
-
signJwk
JWK resource used to sign JWTs created by us.- Parameters:
signJwkResource- resource pointing to a JSON with keys- Returns:
- updated builder instance
-
verifyJwk
JWK resource used to verify JWTs created by other parties.- Parameters:
verifyJwkResource- resource pointing to a JSON with keys- Returns:
- updated builder instance
-
verifyJwk
Fixed JWK keys used to verify JWTs created by other parties.- Parameters:
verifyKeys- keys used to verify inbound JWTs- Returns:
- updated builder instance
-
verifyJwk
JWK resource configuration used to verify JWTs created by other parties. Filesystem paths and URIs are loaded lazily and protected by the configured retry and circuit breaker. Classpath and inline resources are loaded when the provider is built.- Parameters:
verifyJwkResource- configuration of the resource containing verification keys- Returns:
- updated builder instance
-
jwkRetry
Retry used when loading verification keys from a filesystem path or URI; by default, it wraps two timeout-guarded attempts within an 11-second overall timeout.- Parameters:
jwkRetry- retry to use- Returns:
- updated builder instance
-
jwkRetry
Retry used when loading verification keys from a filesystem path or URI. The supplier is invoked only when a dynamic verification JWK source requires the retry.- Parameters:
jwkRetry- prototype of retry to use- Returns:
- updated builder instance
-
jwkRetry
Retry used when loading verification keys from a filesystem path or URI.- Parameters:
consumer- consumer of builder of retry to use- Returns:
- updated builder instance
-
jwkRetry
Retry used when loading verification keys from a filesystem path or URI.- Parameters:
supplier- supplier of retry to use- Returns:
- updated builder instance
-
jwkTimeout
Timeout applied to each attempt to load verification keys from a filesystem path or URI; it defaults to 5 seconds, must be positive, must execute on the current thread, and must not exceed the retry overall timeout. Current-thread execution ensures that a retry cannot overlap an attempt that is still unwinding after an interrupt. The deadline interrupts the loader; prompt termination also depends on the underlying I/O honoring interruption or enforcing its own timeout.- Parameters:
jwkTimeout- timeout to use- Returns:
- updated builder instance
-
jwkTimeout
Timeout applied to each attempt to load verification keys from a filesystem path or URI. The supplier is invoked only when a dynamic verification JWK source requires the timeout.- Parameters:
jwkTimeout- prototype of timeout to use- Returns:
- updated builder instance
-
jwkTimeout
Timeout applied to each attempt to load verification keys from a filesystem path or URI.- Parameters:
consumer- consumer of builder of timeout to use- Returns:
- updated builder instance
-
jwkTimeout
Timeout applied to each attempt to load verification keys from a filesystem path or URI.- Parameters:
supplier- supplier of timeout to use- Returns:
- updated builder instance
-
jwkCircuitBreaker
Circuit breaker around each complete retry batch used to load verification keys from a filesystem path or URI; by default, the circuit opens after one exhausted batch and permits a recovery probe after 5 seconds.- Parameters:
jwkCircuitBreaker- circuit breaker to use- Returns:
- updated builder instance
-
jwkCircuitBreaker
Circuit breaker used when loading verification keys from a filesystem path or URI. The supplier is invoked only when a dynamic verification JWK source requires the circuit breaker.- Parameters:
jwkCircuitBreaker- prototype of circuit breaker to use- Returns:
- updated builder instance
-
jwkCircuitBreaker
Circuit breaker used when loading verification keys from a filesystem path or URI.- Parameters:
consumer- consumer of builder of circuit breaker to use- Returns:
- updated builder instance
-
jwkCircuitBreaker
Circuit breaker used when loading verification keys from a filesystem path or URI.- Parameters:
supplier- supplier of circuit breaker to use- Returns:
- updated builder instance
-
issuer
Issuer used to create new JWTs.- Parameters:
issuer- issuer to add to the issuer claim- Returns:
- updated builder instance
-
config
Load this builder from a configuration.- Parameters:
config- configuration to load from- Returns:
- updated builder instance
-
expectedAudience
Audience expected in inbound JWTs.- Parameters:
audience- audience string
-
expectedIssuer
Issuer expected in inbound JWTs.- Parameters:
issuer- issuer string- Returns:
- updated builder instance
-
useJwtGroups
Claimgroupsfrom JWT will be used to automatically add groups to current subject (may be used withRolesAllowedannotation).- Parameters:
useJwtGroups- whether to usegroupsclaim from JWT to retrieve roles- Returns:
- updated builder instance
-
jwtGroupsPath
Path to the JWT payload claim containing the groups to add as role grants. The default path isgroups. Nested object claims can be configured with slash-separated path segments, such asrealm/groups.- Parameters:
jwtGroupsPath- JWT groups claim path- Returns:
- updated builder instance
-
jwtGroupsSeparator
Separator used to split a string claim value into multiple groups. This is used only whenjwtGroupsPath(String)configures a custom path other thangroups. The defaultgroupsclaim keeps the standard JWT behavior. Setting this property without changing the JWT groups path has no effect.- Parameters:
jwtGroupsSeparator- separator for string-valued custom groups claim- Returns:
- updated builder instance
-