Class JwtValidatorBuilder
java.lang.Object
com.sap.cloud.security.token.validation.validators.JwtValidatorBuilder
Class used to build a token validator for an OAuth service configuration
Custom validators can be added via
OAuth2ServiceConfiguration. Custom validators can be added via
with(Validator) method.-
Method Summary
Modifier and TypeMethodDescriptionbuild()Builds the validators with the applied parameters.configureAnotherServiceInstance(OAuth2ServiceConfiguration otherConfiguration) Allows to provide another service configuration, e.g.Disables tenant id check for JwtSignatureValidator.static JwtValidatorBuildergetInstance(OAuth2ServiceConfiguration configuration) Creates a builder instance that can be configured further.Adds a custom validator to the validation chain.withAudienceValidator(Validator<Token> audienceValidator) Sets / overwrites the default audience validator.withCacheConfiguration(CacheConfiguration tokenKeyCacheConfiguration) Use to configure the token key cache.withHttpClient(org.apache.http.impl.client.CloseableHttpClient httpClient) In case you want to configure theOidcConfigurationServiceand theOAuth2TokenKeyServicewith your own Rest client.withOAuth2TokenKeyService(OAuth2TokenKeyService tokenKeyService) Deprecated.for internal use onlywithOidcConfigurationService(OidcConfigurationService oidcConfigurationService) Deprecated.for internal use onlywithValidatorListener(ValidationListener validationListener) Adds the validation listener to the jwt validator that is being built.
-
Method Details
-
getInstance
Creates a builder instance that can be configured further.- Parameters:
configuration- the identity service configuration- Returns:
- the builder
-
with
Adds a custom validator to the validation chain.- Parameters:
validator- the validator used for validation.- Returns:
- this builder.
-
withCacheConfiguration
Use to configure the token key cache.- Parameters:
tokenKeyCacheConfiguration- the cache configuration- Returns:
- this builder
-
withAudienceValidator
Sets / overwrites the default audience validator.- Parameters:
audienceValidator- the validator used for validation.- Returns:
- this builder.
-
withOAuth2TokenKeyService
@Deprecated public JwtValidatorBuilder withOAuth2TokenKeyService(OAuth2TokenKeyService tokenKeyService) Deprecated.for internal use onlyOverwrite in case you want to configure your ownOAuth2TokenKeyServiceinstance.- Parameters:
tokenKeyService- your token key service- Returns:
- this builder
-
withOidcConfigurationService
@Deprecated public JwtValidatorBuilder withOidcConfigurationService(OidcConfigurationService oidcConfigurationService) Deprecated.for internal use onlyOverwrite in case you want to configure your ownOAuth2TokenKeyServiceinstance.- Parameters:
oidcConfigurationService- your token key service- Returns:
- this builder
-
withHttpClient
public JwtValidatorBuilder withHttpClient(org.apache.http.impl.client.CloseableHttpClient httpClient) In case you want to configure theOidcConfigurationServiceand theOAuth2TokenKeyServicewith your own Rest client.- Parameters:
httpClient- your own http client- Returns:
- this builder
-
configureAnotherServiceInstance
public JwtValidatorBuilder configureAnotherServiceInstance(@Nullable OAuth2ServiceConfiguration otherConfiguration) Allows to provide another service configuration, e.g. in case you have multiple Xsuaa identity service instances and you like to accept tokens issued for them as well.- Parameters:
otherConfiguration- the configuration of the other service instance, e.g. the broker- Returns:
- this builder
-
withValidatorListener
Adds the validation listener to the jwt validator that is being built.- Parameters:
validationListener- the listener to be added to the validator.- Returns:
- this builder
-
disableTenantIdCheck
Disables tenant id check for JwtSignatureValidator. In case Jwt issuer claim doesn't match with the url attribute from OAuth2ServiceConfiguration tenant id (zid) claim needs to be present in token to ensure that the tenant belongs to this issuer. This method disables the tenant id check. Use with caution as it relaxes the validation rules! It is not recommended to disable this check for standard Identity service setup.- Returns:
- this builder
-
build
Builds the validators with the applied parameters.- Returns:
- the combined validators.
-