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 usingKEY_MINandKEY_MAXconfig options.- Author:
- Vlastimil Elias 
 
- 
- 
Field SummaryFields Modifier and Type Field Description protected static List<ProviderConfigProperty>configPropertiesstatic StringKEY_MAXstatic StringKEY_MINstatic StringMESSAGE_INVALID_NUMBERstatic StringMESSAGE_NUMBER_OUT_OF_RANGEstatic StringMESSAGE_NUMBER_OUT_OF_RANGE_TOO_BIGstatic StringMESSAGE_NUMBER_OUT_OF_RANGE_TOO_SMALL- 
Fields inherited from class org.keycloak.validate.AbstractSimpleValidatorIGNORE_EMPTY_VALUE
 
- 
 - 
Constructor SummaryConstructors Constructor Description AbstractNumberValidator()AbstractNumberValidator(ValidatorConfig config)
 - 
Method SummaryAll Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected 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.List<ProviderConfigProperty>getConfigProperties()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 StringselectRangeErrorMessage(ValidatorConfig config)Select 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.ValidationResultvalidateConfig(KeycloakSession session, ValidatorConfig config)Validates the given validation config.- 
Methods inherited from class org.keycloak.validate.AbstractSimpleValidatorisIgnoreEmptyValuesConfigured, validate
 - 
Methods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 - 
Methods inherited from interface org.keycloak.provider.ConfiguredProvidergetConfig, getHelpText
 - 
Methods inherited from interface org.keycloak.provider.ProviderFactorygetConfigMetadata, getId, order
 - 
Methods inherited from interface org.keycloak.validate.SimpleValidatorclose, create, init, postInit
 
- 
 
- 
- 
- 
Field Detail- 
MESSAGE_INVALID_NUMBERpublic static final String MESSAGE_INVALID_NUMBER - See Also:
- Constant Field Values
 
 - 
MESSAGE_NUMBER_OUT_OF_RANGEpublic static final String MESSAGE_NUMBER_OUT_OF_RANGE - See Also:
- Constant Field Values
 
 - 
MESSAGE_NUMBER_OUT_OF_RANGE_TOO_SMALLpublic static final String MESSAGE_NUMBER_OUT_OF_RANGE_TOO_SMALL - See Also:
- Constant Field Values
 
 - 
MESSAGE_NUMBER_OUT_OF_RANGE_TOO_BIGpublic static final String MESSAGE_NUMBER_OUT_OF_RANGE_TOO_BIG - See Also:
- Constant Field Values
 
 - 
KEY_MINpublic static final String KEY_MIN - See Also:
- Constant Field Values
 
 - 
KEY_MAXpublic static final String KEY_MAX - See Also:
- Constant Field Values
 
 - 
configPropertiesprotected static final List<ProviderConfigProperty> configProperties 
 
- 
 - 
Constructor Detail- 
AbstractNumberValidatorpublic AbstractNumberValidator() 
 - 
AbstractNumberValidatorpublic AbstractNumberValidator(ValidatorConfig config) 
 
- 
 - 
Method Detail- 
getConfigPropertiespublic List<ProviderConfigProperty> getConfigProperties() - Specified by:
- getConfigPropertiesin interface- ConfiguredProvider
 
 - 
skipValidationprotected boolean skipValidation(Object value, ValidatorConfig config) 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 class- AbstractSimpleValidator
- Parameters:
- value- currently validated we make decision for
- config- 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:
- AbstractSimpleValidator.doValidate(Object, String, ValidationContext, ValidatorConfig)
 
 - 
doValidateprotected 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 class- AbstractSimpleValidator
- Parameters:
- value- to be validated, never null
- context- for the validation. Add errors into it.
- config- of the validation if provided
- See Also:
- AbstractSimpleValidator.skipValidation(Object, ValidatorConfig)
 
 - 
selectRangeErrorMessageprotected String selectRangeErrorMessage(ValidatorConfig config) Select error message depending on the allowed range interval bound configuration.
 - 
validateConfigpublic ValidationResult validateConfig(KeycloakSession session, ValidatorConfig config) Description copied from interface:ValidatorFactoryValidates the given validation config.Implementations can use the KeycloakSessionto validate the givenValidatorConfig.- Specified by:
- validateConfigin interface- ValidatorFactory
- Parameters:
- session- the- KeycloakSession
- config- the config to be validated
- Returns:
- the validation result
 
 - 
convertprotected abstract Number convert(Object value, ValidatorConfig config) Convert input value to instance of Number supported by this validator.- Parameters:
- value- to convert
- config-
- Returns:
- value converted to supported Number instance
- Throws:
- NumberFormatException- if value is not convertible to supported Number instance so- MESSAGE_INVALID_NUMBERerror is reported.
 
 - 
getMinMaxConfigprotected abstract Number getMinMaxConfig(ValidatorConfig config, String key) Get config value for min and max validation bound as a Number supported by this validator- Parameters:
- config- to get from
- key- of the config value
- Returns:
- bound value or null
 
 - 
isFirstGreaterThanToSecondprotected abstract boolean isFirstGreaterThanToSecond(Number n1, Number n2) 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
 
 
- 
 
-