Class JwtValidatorBuilder
- java.lang.Object
-
- com.sap.cloud.security.token.validation.validators.JwtValidatorBuilder
-
public class JwtValidatorBuilder extends Object
Class used to build a token validator for a oauth service configurationOAuth2ServiceConfiguration.
Custom validators can be added viawith(Validator)method.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description CombiningValidator<Token>build()Builds the validators with the applied parameters.JwtValidatorBuilderconfigureAnotherServiceInstance(OAuth2ServiceConfiguration otherConfiguration)Allows to provide another service configuration, e.g.JwtValidatorBuilderdisableTenantIdCheck()Disables tenant id check for JwtSignatureValidator.static JwtValidatorBuildergetInstance(OAuth2ServiceConfiguration configuration)Creates a builder instance that can be configured further.JwtValidatorBuilderwith(Validator<Token> validator)Adds a custom validator to the validation chain.JwtValidatorBuilderwithAudienceValidator(Validator<Token> audienceValidator)Sets / overwrites the default audience validator.JwtValidatorBuilderwithCacheConfiguration(CacheConfiguration tokenKeyCacheConfiguration)Use to configure the token key cache.JwtValidatorBuilderwithHttpClient(org.apache.http.impl.client.CloseableHttpClient httpClient)In case you want to configure theOidcConfigurationServiceand theOAuth2TokenKeyServicewith your own Rest client.JwtValidatorBuilderwithOAuth2TokenKeyService(OAuth2TokenKeyService tokenKeyService)Deprecated.for internal use onlyJwtValidatorBuilderwithOidcConfigurationService(OidcConfigurationService oidcConfigurationService)Deprecated.for internal use onlyJwtValidatorBuilderwithValidatorListener(ValidationListener validationListener)Adds the validation listener to the jwt validator that is being built.
-
-
-
Method Detail
-
getInstance
public static JwtValidatorBuilder getInstance(OAuth2ServiceConfiguration configuration)
Creates a builder instance that can be configured further.- Parameters:
configuration- the identity service configuration- Returns:
- the builder
-
with
public JwtValidatorBuilder with(Validator<Token> validator)
Adds a custom validator to the validation chain.- Parameters:
validator- the validator used for validation.- Returns:
- this builder.
-
withCacheConfiguration
public JwtValidatorBuilder withCacheConfiguration(CacheConfiguration tokenKeyCacheConfiguration)
Use to configure the token key cache.- Parameters:
tokenKeyCacheConfiguration- the cache configuration- Returns:
- this builder
-
withAudienceValidator
public JwtValidatorBuilder withAudienceValidator(Validator<Token> audienceValidator)
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
public JwtValidatorBuilder withValidatorListener(ValidationListener validationListener)
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
public JwtValidatorBuilder 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
public CombiningValidator<Token> build()
Builds the validators with the applied parameters.- Returns:
- the combined validators.
-
-