Package org.keycloak.validate.validators
Class AbstractNumberValidator
java.lang.Object
org.keycloak.validate.AbstractSimpleValidator
org.keycloak.validate.validators.AbstractNumberValidator
- All Implemented Interfaces:
ConfiguredProvider,Provider,ProviderFactory<Validator>,SimpleValidator,Validator,ValidatorFactory
- Direct Known Subclasses:
DoubleValidator,IntegerValidator
public abstract class AbstractNumberValidator
extends AbstractSimpleValidator
implements ConfiguredProvider
Abstract class for number validator. Supports min and max value validations using
KEY_MIN and
KEY_MAX config options.- Author:
- Vlastimil Elias <velias@redhat.com>
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final List<ProviderConfigProperty>static final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final StringFields inherited from class org.keycloak.validate.AbstractSimpleValidator
IGNORE_EMPTY_VALUE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract Numberconvert(Object value, ValidatorConfig config) Convert input value to instance of Number supported by this validator.protected voiddoValidate(Object value, String inputHint, ValidationContext context, ValidatorConfig config) Validate type, format, range of the value etc.protected abstract NumbergetMinMaxConfig(ValidatorConfig config, String key) Get config value for min and max validation bound as a Number supported by this validatorprotected abstract booleanisFirstGreaterThanToSecond(Number n1, Number n2) Compare two numbers of supported type (fed byconvert(Object, ValidatorConfig)andgetMinMaxConfig(ValidatorConfig, String))protected StringSelect error message depending on the allowed range interval bound configuration.protected booleanskipValidation(Object value, ValidatorConfig config) Decide if validation of individual value should be skipped or not.validateConfig(KeycloakSession session, ValidatorConfig config) Validates the given validation config.Methods inherited from class org.keycloak.validate.AbstractSimpleValidator
isIgnoreEmptyValuesConfigured, validateMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.keycloak.provider.ConfiguredProvider
getConfig, getHelpTextMethods inherited from interface org.keycloak.provider.ProviderFactory
dependsOn, getConfigMetadata, getId, orderMethods inherited from interface org.keycloak.validate.SimpleValidator
close, create, init, postInit
-
Field Details
-
MESSAGE_INVALID_NUMBER
- See Also:
-
MESSAGE_NUMBER_OUT_OF_RANGE
- See Also:
-
MESSAGE_NUMBER_OUT_OF_RANGE_TOO_SMALL
- See Also:
-
MESSAGE_NUMBER_OUT_OF_RANGE_TOO_BIG
- See Also:
-
KEY_MIN
- See Also:
-
KEY_MAX
- See Also:
-
configProperties
-
-
Constructor Details
-
AbstractNumberValidator
public AbstractNumberValidator() -
AbstractNumberValidator
-
-
Method Details
-
getConfigProperties
- Specified by:
getConfigPropertiesin interfaceConfiguredProvider
-
skipValidation
Description copied from class:AbstractSimpleValidatorDecide if validation of individual value should be skipped or not. It should be controlled byAbstractSimpleValidator.IGNORE_EMPTY_VALUEconfiguration option, seeAbstractSimpleValidator.isIgnoreEmptyValuesConfigured(ValidatorConfig).- Specified by:
skipValidationin classAbstractSimpleValidator- Parameters:
value- currently validated we make decision forconfig- to look for options in- Returns:
- true if validation should be skipped for this value -
AbstractSimpleValidator.doValidate(Object, String, ValidationContext, ValidatorConfig)is not called in this case. - See Also:
-
doValidate
protected void doValidate(Object value, String inputHint, ValidationContext context, ValidatorConfig config) Description copied from class:AbstractSimpleValidatorValidate type, format, range of the value etc. Always useValidationContext.addError(ValidationError)to report error to the user! Can be called multiple time for one validation if input is Collection.- Specified by:
doValidatein classAbstractSimpleValidator- Parameters:
value- to be validated, never nullcontext- for the validation. Add errors into it.config- of the validation if provided- See Also:
-
selectRangeErrorMessage
Select error message depending on the allowed range interval bound configuration. -
validateConfig
Description copied from interface:ValidatorFactoryValidates the given validation config.Implementations can use the
KeycloakSessionto validate the givenValidatorConfig.- Specified by:
validateConfigin interfaceValidatorFactory- Parameters:
session- theKeycloakSessionconfig- the config to be validated- Returns:
- the validation result
-
convert
Convert input value to instance of Number supported by this validator.- Parameters:
value- to convertconfig-- Returns:
- value converted to supported Number instance
- Throws:
NumberFormatException- if value is not convertible to supported Number instance soMESSAGE_INVALID_NUMBERerror is reported.
-
getMinMaxConfig
Get config value for min and max validation bound as a Number supported by this validator- Parameters:
config- to get fromkey- of the config value- Returns:
- bound value or null
-
isFirstGreaterThanToSecond
Compare two numbers of supported type (fed byconvert(Object, ValidatorConfig)andgetMinMaxConfig(ValidatorConfig, String))- Parameters:
n1-n2-- Returns:
- true if first number is greater than second
-