org.keycloak.validate

## Class AbstractSimpleValidator

- java.lang.Object
- - org.keycloak.validate.AbstractSimpleValidator

- All Implemented Interfaces:
    Provider, ProviderFactory<Validator>, SimpleValidator, Validator, ValidatorFactory
  Direct Known Subclasses:
    AbstractNumberValidator, AbstractStringValidator

      public abstract class AbstractSimpleValidator
      extends Object
      implements SimpleValidator

  Base class for arbitrary value type validators. Functionality covered in this base class:
  - accepts supported type, collection of supported type.
  - behavior around null and empty values is controlled by `IGNORE_EMPTY_VALUE` configuration option which is boolean. Error should be produced for them by default, but they should be ignored if that option is `true`. Logic must be implemented in `skipValidation(Object, ValidatorConfig)`.
  Author:
    Vlastimil Elias

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static String` | `IGNORE_EMPTY_VALUE` Config option which allows to switch validator to ignore null, empty string and even blank string value - not to produce error for them.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `AbstractSimpleValidator()`

  - ### Method Summary

    All Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected abstract void` | `doValidate(Object value, String inputHint, ValidationContext context, ValidatorConfig config)` Validate type, format, range of the value etc.
    `protected boolean` | `isIgnoreEmptyValuesConfigured(ValidatorConfig config)` Default implementation only looks for `IGNORE_EMPTY_VALUE` configuration option.
    `protected abstract boolean` | `skipValidation(Object value, ValidatorConfig config)` Decide if validation of individual value should be skipped or not.
    `ValidationContext` | `validate(Object input, String inputHint, ValidationContext context, ValidatorConfig config)` Validates the given `input` with an additional `inputHint` and `config`.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

    - ### 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.validate.ValidatorFactory

      `validateConfig`

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

      `getId, order`

- - ### Field Detail

    - #### IGNORE_EMPTY_VALUE

          public static final String IGNORE_EMPTY_VALUE

      Config option which allows to switch validator to ignore null, empty string and even blank string value - not to produce error for them. Used eg. in UserProfile where we have optional attributes and required concern is checked by separate validators.
      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### AbstractSimpleValidator

          public AbstractSimpleValidator()

  - ### Method Detail

    - #### validate

          public ValidationContext validate(Object input,
                                            String inputHint,
                                            ValidationContext context,
                                            ValidatorConfig config)

      Description copied from interface: `Validator`
      Validates the given `input` with an additional `inputHint` and `config`.
      Specified by:
        `validate` in interface `Validator`
      Parameters:
        `input` - the value to validate
        `inputHint` - an optional input hint to guide the validation
        `context` - the validation context
        `config` - parameterization for the current validation
      Returns:
        the validation context with the outcome of the validation

    - #### doValidate

          protected abstract void doValidate(Object value,
                                             String inputHint,
                                             ValidationContext context,
                                             ValidatorConfig config)

      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.
      Parameters:
        `value` - to be validated, never null
        `inputHint` -
        `context` - for the validation. Add errors into it.
        `config` - of the validation if provided
      See Also:
        `skipValidation(Object, ValidatorConfig)`

    - #### skipValidation

          protected abstract boolean skipValidation(Object value,
                                                    ValidatorConfig config)

      Decide if validation of individual value should be skipped or not. It should be controlled by `IGNORE_EMPTY_VALUE` configuration option, see `isIgnoreEmptyValuesConfigured(ValidatorConfig)`.
      Parameters:
        `value` - currently validated we make decision for
        `config` - to look for options in
      Returns:
        true if validation should be skipped for this value - `doValidate(Object, String, ValidationContext, ValidatorConfig)` is not called in this case.
      See Also:
        `doValidate(Object, String, ValidationContext, ValidatorConfig)`

    - #### isIgnoreEmptyValuesConfigured

          protected boolean isIgnoreEmptyValuesConfigured(ValidatorConfig config)

      Default implementation only looks for `IGNORE_EMPTY_VALUE` configuration option.
      Parameters:
        `config` - to get option from
      Returns:

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