org.keycloak.validate.validators

## Class LengthValidator

- java.lang.Object
- - org.keycloak.validate.AbstractSimpleValidator
  - - org.keycloak.validate.AbstractStringValidator
    - - org.keycloak.validate.validators.LengthValidator

- All Implemented Interfaces:
    ConfiguredProvider, Provider, ProviderFactory<Validator>, SimpleValidator, Validator, ValidatorFactory

      public class LengthValidator
      extends AbstractStringValidator
      implements ConfiguredProvider

  String value length validation - accepts plain string and collection of strings, for basic behavior like null/blank values handling and collections support see `AbstractStringValidator`. Validator trims String value before the length validation, can be disabled by `KEY_TRIM_DISABLED` boolean configuration entry set to `true`.

  Configuration have to be always provided, with at least one of `KEY_MIN` and `KEY_MAX`.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static String` | `ID`
    `static LengthValidator` | `INSTANCE`
    `static String` | `KEY_MAX`
    `static String` | `KEY_MIN`
    `static String` | `KEY_TRIM_DISABLED`
    `static String` | `MESSAGE_INVALID_LENGTH`
    `static String` | `MESSAGE_INVALID_LENGTH_TOO_LONG`
    `static String` | `MESSAGE_INVALID_LENGTH_TOO_SHORT`

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

      `IGNORE_EMPTY_VALUE`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `LengthValidator()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected void` | `doValidate(String value, String inputHint, ValidationContext context, ValidatorConfig config)`
    `List<ProviderConfigProperty>` | `getConfigProperties()`
    `String` | `getHelpText()`
    `String` | `getId()`
    `protected String` | `selectErrorMessage(ValidatorConfig config)` Select error message depending on the allowed length interval bound configuration.
    `ValidationResult` | `validateConfig(KeycloakSession session, ValidatorConfig config)` Validates the given validation config.

    - ### Methods inherited from class org.keycloak.validate.AbstractStringValidator

      `doValidate, skipValidation`

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

      `order`

- - ### Field Detail

    - #### INSTANCE

          public static final LengthValidator INSTANCE

    - #### ID

          public static final String ID

      See Also:
        Constant Field Values

    - #### MESSAGE_INVALID_LENGTH

          public static final String MESSAGE_INVALID_LENGTH

      See Also:
        Constant Field Values

    - #### MESSAGE_INVALID_LENGTH_TOO_SHORT

          public static final String MESSAGE_INVALID_LENGTH_TOO_SHORT

      See Also:
        Constant Field Values

    - #### MESSAGE_INVALID_LENGTH_TOO_LONG

          public static final String MESSAGE_INVALID_LENGTH_TOO_LONG

      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

    - #### KEY_TRIM_DISABLED

          public static final String KEY_TRIM_DISABLED

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### LengthValidator

          public LengthValidator()

  - ### Method Detail

    - #### getId

          public String getId()

      Specified by:
        `getId` in interface `ProviderFactory<Validator>`

    - #### doValidate

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

      Specified by:
        `doValidate` in class `AbstractStringValidator`

    - #### selectErrorMessage

          protected String selectErrorMessage(ValidatorConfig config)

      Select error message depending on the allowed length 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 given `ValidatorConfig`.

      Specified by:
        `validateConfig` in interface `ValidatorFactory`
      Parameters:
        `session` - the `KeycloakSession`
        `config` - the config to be validated
      Returns:
        the validation result

    - #### getHelpText

          public String getHelpText()

      Specified by:
        `getHelpText` in interface `ConfiguredProvider`

    - #### getConfigProperties

          public List<ProviderConfigProperty> getConfigProperties()

      Specified by:
        `getConfigProperties` in interface `ConfiguredProvider`

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