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

- - ### Field Summary

    Fields
    Modifier and Type | Field and 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`

    - ### Fields inherited from class org.keycloak.validate.AbstractSimpleValidator

      `IGNORE_EMPTY_VALUE`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `AbstractNumberValidator()`
    `AbstractNumberValidator(ValidatorConfig config)`

  - ### Method Summary

    All Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method and 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 validator
    `protected abstract boolean` | `isFirstGreaterThanToSecond(Number n1, Number n2)` Compare two numbers of supported type (fed by `convert(Object, ValidatorConfig)` and `getMinMaxConfig(ValidatorConfig, String)` )
    `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

      `getHelpText`

    - ### Methods inherited from interface org.keycloak.validate.SimpleValidator

      `close, create, init, postInit`

    - ### Methods inherited from interface org.keycloak.validate.Validator

      `validate, validate, validate, validate, validate, validate`

    - ### Methods inherited from interface org.keycloak.provider.ProviderFactory

      `getId, order`

- - ### 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

    - #### 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 interface `ConfiguredProvider`

    - #### 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 by `AbstractSimpleValidator.IGNORE_EMPTY_VALUE` configuration option, see `AbstractSimpleValidator.isIgnoreEmptyValuesConfigured(ValidatorConfig)`.
      Specified by:
        `skipValidation` in 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)`

    - #### 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 use `ValidationContext.addError(ValidationError)` to report error to the user! Can be called multiple time for one validation if input is Collection.
      Specified by:
        `doValidate` in 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)`

    - #### 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 given `ValidatorConfig`.

      Specified by:
        `validateConfig` in interface `ValidatorFactory`
      Parameters:
        `session` - the `KeycloakSession`
        `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 convert
        `config` -
      Returns:
        value converted to supported Number instance
      Throws:
        `NumberFormatException` - if value is not convertible to supported Number instance so `MESSAGE_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 from
        `key` - 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 by `convert(Object, ValidatorConfig)` and `getMinMaxConfig(ValidatorConfig, String)` )
      Parameters:
        `n1` -
        `n2` -
      Returns:
        true if first number is greater than second

Copyright © 2021 JBoss by Red Hat. All rights reserved.