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_MIN
andKEY_MAX
config options.- Author:
- Vlastimil Elias
-
-
Field Summary
Fields Modifier and Type Field Description protected static List<ProviderConfigProperty>
configProperties
static String
KEY_MAX
static String
KEY_MIN
static String
MESSAGE_INVALID_NUMBER
static String
MESSAGE_NUMBER_OUT_OF_RANGE
static String
MESSAGE_NUMBER_OUT_OF_RANGE_TOO_BIG
static String
MESSAGE_NUMBER_OUT_OF_RANGE_TOO_SMALL
-
Fields inherited from class org.keycloak.validate.AbstractSimpleValidator
IGNORE_EMPTY_VALUE
-
-
Constructor Summary
Constructors Constructor Description AbstractNumberValidator()
AbstractNumberValidator(ValidatorConfig config)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract Number
convert(Object value, ValidatorConfig config)
Convert input value to instance of Number supported by this validator.protected void
doValidate(Object value, String inputHint, ValidationContext context, ValidatorConfig config)
Validate type, format, range of the value etc.List<ProviderConfigProperty>
getConfigProperties()
protected abstract Number
getMinMaxConfig(ValidatorConfig config, String key)
Get config value for min and max validation bound as a Number supported by this validatorprotected abstract boolean
isFirstGreaterThanToSecond(Number n1, Number n2)
Compare two numbers of supported type (fed byconvert(Object, ValidatorConfig)
andgetMinMaxConfig(ValidatorConfig, String)
)protected String
selectRangeErrorMessage(ValidatorConfig config)
Select error message depending on the allowed range interval bound configuration.protected boolean
skipValidation(Object value, ValidatorConfig config)
Decide if validation of individual value should be skipped or not.ValidationResult
validateConfig(KeycloakSession session, ValidatorConfig config)
Validates the given validation config.-
Methods inherited from class org.keycloak.validate.AbstractSimpleValidator
isIgnoreEmptyValuesConfigured, validate
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.keycloak.provider.ConfiguredProvider
getConfig, getHelpText
-
Methods inherited from interface org.keycloak.provider.ProviderFactory
getConfigMetadata, getId, order
-
Methods inherited from interface org.keycloak.validate.SimpleValidator
close, create, init, postInit
-
-
-
-
Field Detail
-
MESSAGE_INVALID_NUMBER
public static final String MESSAGE_INVALID_NUMBER
- See Also:
- Constant Field Values
-
MESSAGE_NUMBER_OUT_OF_RANGE
public static final String MESSAGE_NUMBER_OUT_OF_RANGE
- See Also:
- Constant Field Values
-
MESSAGE_NUMBER_OUT_OF_RANGE_TOO_SMALL
public static final String MESSAGE_NUMBER_OUT_OF_RANGE_TOO_SMALL
- See Also:
- Constant Field Values
-
MESSAGE_NUMBER_OUT_OF_RANGE_TOO_BIG
public static final String MESSAGE_NUMBER_OUT_OF_RANGE_TOO_BIG
- See Also:
- Constant Field Values
-
KEY_MIN
public static final String KEY_MIN
- See Also:
- Constant Field Values
-
KEY_MAX
public static final String KEY_MAX
- See Also:
- Constant Field Values
-
configProperties
protected static final List<ProviderConfigProperty> configProperties
-
-
Constructor Detail
-
AbstractNumberValidator
public AbstractNumberValidator()
-
AbstractNumberValidator
public AbstractNumberValidator(ValidatorConfig config)
-
-
Method Detail
-
getConfigProperties
public List<ProviderConfigProperty> getConfigProperties()
- Specified by:
getConfigProperties
in interfaceConfiguredProvider
-
skipValidation
protected boolean skipValidation(Object value, ValidatorConfig config)
Description copied from class:AbstractSimpleValidator
Decide if validation of individual value should be skipped or not. It should be controlled byAbstractSimpleValidator.IGNORE_EMPTY_VALUE
configuration option, seeAbstractSimpleValidator.isIgnoreEmptyValuesConfigured(ValidatorConfig)
.- Specified by:
skipValidation
in 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:
AbstractSimpleValidator.doValidate(Object, String, ValidationContext, ValidatorConfig)
-
doValidate
protected void doValidate(Object value, String inputHint, ValidationContext context, ValidatorConfig config)
Description copied from class:AbstractSimpleValidator
Validate 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:
doValidate
in classAbstractSimpleValidator
- Parameters:
value
- to be validated, never nullcontext
- for the validation. Add errors into it.config
- of the validation if provided- See Also:
AbstractSimpleValidator.skipValidation(Object, ValidatorConfig)
-
selectRangeErrorMessage
protected String selectRangeErrorMessage(ValidatorConfig config)
Select error message depending on the allowed range interval bound configuration.
-
validateConfig
public ValidationResult validateConfig(KeycloakSession session, ValidatorConfig config)
Description copied from interface:ValidatorFactory
Validates the given validation config.Implementations can use the
KeycloakSession
to validate the givenValidatorConfig
.- Specified by:
validateConfig
in interfaceValidatorFactory
- Parameters:
session
- theKeycloakSession
config
- the config to be validated- Returns:
- the validation result
-
convert
protected abstract Number convert(Object value, ValidatorConfig config)
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_NUMBER
error is reported.
-
getMinMaxConfig
protected 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 fromkey
- of the config value- Returns:
- bound value or null
-
isFirstGreaterThanToSecond
protected 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
-
-