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
Modifier and TypeFieldDescriptionprotected static final List<ProviderConfigProperty>
static final String
static final String
static final String
static final String
static final String
static final String
Fields inherited from class org.keycloak.validate.AbstractSimpleValidator
IGNORE_EMPTY_VALUE
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected 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.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
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.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
dependsOn, getConfigMetadata, getId, order
Methods 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:
getConfigProperties
in interfaceConfiguredProvider
-
skipValidation
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:
-
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:
-
selectRangeErrorMessage
Select error message depending on the allowed range interval bound configuration. -
validateConfig
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
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
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
-