Package com.codingchili.core.security
Class Validator
java.lang.Object
com.codingchili.core.security.Validator
- All Implemented Interfaces:
Configurable
,Serializable
Validates the contents of a json object according to the validation configuration.
- See Also:
- Serialized Form
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionadd(ValidatorSettings validator)
Adds a validator.getPath()
Get the path of a loaded configuration file.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.static String
toPlainText(String input)
Converts a string into a plaintext string, stripping any potential unsafe characters.io.vertx.core.json.JsonObject
validate(io.vertx.core.json.JsonObject json)
Validates a json object using the regular expression that is configured for its field names.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.codingchili.core.configuration.Configurable
save, serialize, setPath
-
Constructor Details
-
Validator
public Validator()
-
-
Method Details
-
getPath
Description copied from interface:Configurable
Get the path of a loaded configuration file.- Specified by:
getPath
in interfaceConfigurable
- Returns:
- the directory path to the configuration file.
-
get
- Parameters:
name
- the name of the validator to retrieve.- Returns:
- a validator matching the given name.
-
add
Adds a validator.- Parameters:
name
- the name of the new validation ruleset.- Returns:
- a reference to the new validator settings.
-
add
- Parameters:
validator
- validation ruleset to add.- Returns:
- fluent.
-
plainText
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
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 RequestValidationExceptionValidates 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.
-