Class Validator

java.lang.Object
com.codingchili.core.security.Validator
All Implemented Interfaces:
Configurable, Serializable

public class Validator extends Object implements Configurable
Validates the contents of a json object according to the validation configuration.
See Also:
Serialized Form
  • Constructor Details

    • Validator

      public Validator()
  • Method Details

    • getPath

      public String getPath()
      Description copied from interface: Configurable
      Get the path of a loaded configuration file.
      Specified by:
      getPath in interface Configurable
      Returns:
      the directory path to the configuration file.
    • get

      public ValidatorSettings get(String name)
      Parameters:
      name - the name of the validator to retrieve.
      Returns:
      a validator matching the given name.
    • add

      public ValidatorSettings add(String name)
      Adds a validator.
      Parameters:
      name - the name of the new validation ruleset.
      Returns:
      a reference to the new validator settings.
    • add

      public Validator add(ValidatorSettings validator)
      Parameters:
      validator - validation ruleset to add.
      Returns:
      fluent.
    • plainText

      public static boolean plainText(Comparable value)
      tests if a comparable objects string format contains characters that are not in the accepted plaintext range of A-Z, a-z, 0-9 and whitespace.
      Parameters:
      value - the value to test.
      Returns:
      true if the value is plaintext.
    • toPlainText

      public static String toPlainText(String input)
      Converts a string into a plaintext string, stripping any potential unsafe characters.
      Parameters:
      input - the string to be sanitized.
      Returns:
      a plaintext string consisting of only A-Z, a-z, 0-9, whitespace.
    • validate

      public io.vertx.core.json.JsonObject validate(io.vertx.core.json.JsonObject json) throws RequestValidationException
      Validates a json object using the regular expression that is configured for its field names. Validation fails if evaluation is set to REJECT and the field value is matching, if evaluation mode is set to REPLACE then the matching substring will be replaced.
      Parameters:
      json - the json object to check field values on.
      Returns:
      the json object with values that have failed validation replaced.
      Throws:
      RequestValidationException - when the evaluation is configured to reject a value.