| Modifier and Type | Field and Description |
|---|---|
static String |
DIRECTORY_NAME_REGEX |
static String |
FILE_NAME_REGEX |
| Constructor and Description |
|---|
FileValidator()
Initialize file validator with an appropriate set of codecs
|
FileValidator(Encoder encoder)
Initialize file validator with an appropriate set of codecs
|
| Modifier and Type | Method and Description |
|---|---|
void |
assertValidFileUpload(String context,
String directorypath,
String filename,
File parent,
byte[] content,
int maxBytes,
List<String> allowedExtensions,
boolean allowNull)
Validates the filepath, filename, and content of a file.
|
void |
assertValidFileUpload(String context,
String directorypath,
String filename,
File parent,
byte[] content,
int maxBytes,
List<String> allowedExtensions,
boolean allowNull,
List<ValidationException> errors)
Calls getValidFileUpload with the supplied List to capture ValidationExceptions
|
List<String> |
getAllowedExtensions() |
Encoder |
getFileEncoder() |
Integer |
getMaxFilePathSize() |
Long |
getMaxFileUploadSize() |
String |
getValidDirectoryPath(String context,
String input,
File parent,
boolean allowNull)
Returns a canonicalized and validated directory path as a String, provided that the input maps to an existing directory that is an existing subdirectory (at any level) of the specified parent.
|
String |
getValidDirectoryPath(String context,
String input,
File parent,
boolean allowNull,
List<ValidationException> errors)
Calls getValidDirectoryPath with the supplied error List to capture ValidationExceptions
|
byte[] |
getValidFileContent(String context,
byte[] input,
boolean allowNull)
Returns validated file content as a byte array.
|
byte[] |
getValidFileContent(String context,
byte[] input,
int maxBytes,
boolean allowNull,
List<ValidationException> errors)
Calls getValidFileContent with the supplied List to capture ValidationExceptions
|
byte[] |
getValidFileContent(String context,
byte[] input,
long maxBytes,
boolean allowNull)
Returns validated file content as a byte array.
|
String |
getValidFileName(String context,
String input,
List<String> allowedExtensions,
boolean allowNull)
Returns a canonicalized and validated file name as a String.
|
String |
getValidFileName(String context,
String input,
List<String> allowedExtensions,
boolean allowNull,
List<ValidationException> errors)
Calls getValidFileName with the supplied List to capture ValidationExceptions
|
String |
getValidInput(String context,
String input,
String type,
int maxLength,
boolean allowNull)
Validates data received from the browser and returns a safe version.
|
String |
getValidInput(String context,
String input,
String type,
int maxLength,
boolean allowNull,
boolean canonicalize)
Validates data received from the browser and returns a safe version.
|
boolean |
isValidDirectoryPath(String context,
String input,
File parent,
boolean allowNull)
Calls getValidDirectoryPath and returns true if no exceptions are thrown.
|
boolean |
isValidDirectoryPath(String context,
String input,
File parent,
boolean allowNull,
List<ValidationException> errors)
Calls getValidDirectoryPath and returns true if no exceptions are thrown.
|
boolean |
isValidFileContent(String context,
byte[] input,
int maxBytes,
boolean allowNull)
Calls getValidFileContent and returns true if no exceptions are thrown.
|
boolean |
isValidFileContent(String context,
byte[] input,
int maxBytes,
boolean allowNull,
List<ValidationException> errors)
Calls getValidFileContent and returns true if no exceptions are thrown.
|
boolean |
isValidFileName(String context,
String input,
boolean allowNull)
Calls getValidFileName with the default list of allowedExtensions
|
boolean |
isValidFileName(String context,
String input,
boolean allowNull,
List<ValidationException> errors)
Calls getValidFileName with the default list of allowedExtensions
|
boolean |
isValidFileName(String context,
String input,
List<String> allowedExtensions,
boolean allowNull)
Calls getValidFileName with the default list of allowedExtensions
|
boolean |
isValidFileName(String context,
String input,
List<String> allowedExtensions,
boolean allowNull,
List<ValidationException> errors)
Calls getValidFileName with the default list of allowedExtensions
|
boolean |
isValidFileUpload(String context,
String directorypath,
String filename,
File parent,
byte[] content,
int maxBytes,
boolean allowNull)
Calls getValidFileUpload and returns true if no exceptions are thrown.
|
boolean |
isValidFileUpload(String context,
String directorypath,
String filename,
File parent,
byte[] content,
int maxBytes,
boolean allowNull,
List<ValidationException> errors)
Calls getValidFileUpload and returns true if no exceptions are thrown.
|
void |
setAllowedExtensions(List<String> allowedExtensions) |
void |
setFileEncoder(Encoder fileEncoder) |
void |
setMaxFilePathSize(Integer maxFilePathSize) |
void |
setMaxFileUploadSize(Long maxFileUploadSize) |
public static final String FILE_NAME_REGEX
public static final String DIRECTORY_NAME_REGEX
public FileValidator()
public FileValidator(Encoder encoder)
encoder - The encoder instance to usepublic Long getMaxFileUploadSize()
public void setMaxFileUploadSize(Long maxFileUploadSize)
public Integer getMaxFilePathSize()
public void setMaxFilePathSize(Integer maxFilePathSize)
public Encoder getFileEncoder()
public void setFileEncoder(Encoder fileEncoder)
public boolean isValidDirectoryPath(String context, String input, File parent, boolean allowNull)
Note: On platforms that support symlinks, this function will fail canonicalization if directorypath is a symlink. For example, on MacOS X, /etc is actually /private/etc. If you mean to use /etc, use its real path (/private/etc), not the symlink (/etc).
context - A descriptive name of the parameter that you are validating (e.g., LoginPage_UsernameField). This value is used by any logging or error handling that is done with respect to the
value passed in.input - The actual input data to validate.parent - A File indicating the parent directory into which the input File will be placed.allowNull - If allowNull is true then an input that is NULL or an empty string will be legal. If allowNull is false then NULL or an empty String will throw a ValidationException.public boolean isValidDirectoryPath(String context, String input, File parent, boolean allowNull, List<ValidationException> errors)
Note: On platforms that support symlinks, this function will fail canonicalization if directorypath is a symlink. For example, on MacOS X, /etc is actually /private/etc. If you mean to use /etc, use its real path (/private/etc), not the symlink (/etc).
context - A descriptive name of the parameter that you are validating (e.g., LoginPage_UsernameField). This value is used by any logging or error handling that is done with respect to the
value passed in.input - The actual input data to validate.parent - A File indicating the parent directory into which the input File will be placed.allowNull - If allowNull is true then an input that is NULL or an empty string will be legal. If allowNull is false then NULL or an empty String will throw a ValidationException.errors - A List to contain any validation errors.public String getValidDirectoryPath(String context, String input, File parent, boolean allowNull) throws ValidationException
context - A descriptive name of the parameter that you are validating (e.g., LoginPage_UsernameField). This value is used by any logging or error handling that is done with respect to the
value passed in.input - The actual input data to validate.parent - A File indicating the parent directory into which the input File will be placed.allowNull - If allowNull is true then an input that is NULL or an empty string will be legal. If allowNull is false then NULL or an empty String will throw a ValidationException.ValidationException - if validation errors occurpublic String getValidDirectoryPath(String context, String input, File parent, boolean allowNull, List<ValidationException> errors)
context - A descriptive name of the parameter that you are validating (e.g., LoginPage_UsernameField). This value is used by any logging or error handling that is done with respect to the
value passed in.input - The actual input data to validate.parent - A File indicating the parent directory into which the input File will be placed.allowNull - If allowNull is true then an input that is NULL or an empty string will be legal. If allowNull is false then NULL or an empty String will throw a ValidationException.errors - A List to contain any validation errors.public boolean isValidFileName(String context, String input, boolean allowNull)
context - A descriptive name of the parameter that you are validating (e.g., LoginPage_UsernameField). This value is used by any logging or error handling that is done with respect to the
value passed in.input - The actual input data to validate.allowNull - If allowNull is true then an input that is NULL or an empty string will be legal. If allowNull is false then NULL or an empty String will throw a ValidationException.public boolean isValidFileName(String context, String input, boolean allowNull, List<ValidationException> errors)
context - A descriptive name of the parameter that you are validating (e.g., LoginPage_UsernameField). This value is used by any logging or error handling that is done with respect to the
value passed in.input - The actual input data to validate.allowNull - If allowNull is true then an input that is NULL or an empty string will be legal. If allowNull is false then NULL or an empty String will throw a ValidationException.errors - A List to contain any validation errors.public boolean isValidFileName(String context, String input, List<String> allowedExtensions, boolean allowNull)
context - A descriptive name of the parameter that you are validating (e.g., LoginPage_UsernameField). This value is used by any logging or error handling that is done with respect to the
value passed in.input - The actual input data to validate.allowedExtensions - A List of allowed file extensions to validate againstallowNull - If allowNull is true then an input that is NULL or an empty string will be legal. If allowNull is false then NULL or an empty String will throw a ValidationException.public boolean isValidFileName(String context, String input, List<String> allowedExtensions, boolean allowNull, List<ValidationException> errors)
context - A descriptive name of the parameter that you are validating (e.g., LoginPage_UsernameField). This value is used by any logging or error handling that is done with respect to the
value passed in.input - The actual input data to validate.allowedExtensions - A List of allowed file extensions to validate againstallowNull - If allowNull is true then an input that is NULL or an empty string will be legal. If allowNull is false then NULL or an empty String will throw a ValidationException.errors - A List to contain any validation errors.public String getValidFileName(String context, String input, List<String> allowedExtensions, boolean allowNull) throws ValidationException
context - A descriptive name of the parameter that you are validating (e.g., LoginPage_UsernameField). This value is used by any logging or error handling that is done with respect to the
value passed in.input - The actual input data to validate.allowedExtensions - A List of allowed file extensions to validate againstallowNull - If allowNull is true then an input that is NULL or an empty string will be legal. If allowNull is false then NULL or an empty String will throw a ValidationException.ValidationException - if validation errors occurpublic String getValidFileName(String context, String input, List<String> allowedExtensions, boolean allowNull, List<ValidationException> errors)
context - A descriptive name of the parameter that you are validating (e.g., LoginPage_UsernameField). This value is used by any logging or error handling that is done with respect to the
value passed in.input - The actual input data to validate.allowedExtensions - A List of allowed file extensions to validate againstallowNull - If allowNull is true then an input that is NULL or an empty string will be legal. If allowNull is false then NULL or an empty String will throw a ValidationException.errors - A List to contain any validation errors.public boolean isValidFileUpload(String context, String directorypath, String filename, File parent, byte[] content, int maxBytes, boolean allowNull) throws ValidationException
Note: On platforms that support symlinks, this function will fail canonicalization if directorypath is a symlink. For example, on MacOS X, /etc is actually /private/etc. If you mean to use /etc, use its real path (/private/etc), not the symlink (/etc).
context - A descriptive name of the parameter that you are validating (e.g., LoginPage_UsernameField). This value is used by any logging or error handling that is done with respect to the
value passed in.directorypath - The file path of the uploaded file.filename - The filename of the uploaded fileparent - A File indicating the parent directory into which the input File will be placed.content - A byte array containing the content of the uploaded file.maxBytes - The max number of bytes allowed for a legal file upload.allowNull - If allowNull is true then an input that is NULL or an empty string will be legal. If allowNull is false then NULL or an empty String will throw a ValidationException.ValidationException - if validation errors occurpublic boolean isValidFileUpload(String context, String directorypath, String filename, File parent, byte[] content, int maxBytes, boolean allowNull, List<ValidationException> errors)
Note: On platforms that support symlinks, this function will fail canonicalization if directorypath is a symlink. For example, on MacOS X, /etc is actually /private/etc. If you mean to use /etc, use its real path (/private/etc), not the symlink (/etc).
context - A descriptive name of the parameter that you are validating (e.g., LoginPage_UsernameField). This value is used by any logging or error handling that is done with respect to the
value passed in.directorypath - The file path of the uploaded file.filename - The filename of the uploaded fileparent - A File indicating the parent directory into which the input File will be placed.content - A byte array containing the content of the uploaded file.maxBytes - The max number of bytes allowed for a legal file upload.allowNull - If allowNull is true then an input that is NULL or an empty string will be legal. If allowNull is false then NULL or an empty String will throw a ValidationException.errors - A List to contain any validation errors.public void assertValidFileUpload(String context, String directorypath, String filename, File parent, byte[] content, int maxBytes, List<String> allowedExtensions, boolean allowNull) throws ValidationException
context - A descriptive name of the parameter that you are validating (e.g., LoginPage_UsernameField). This value is used by any logging or error handling that is done with respect to the
value passed in.directorypath - The file path of the uploaded file.filename - The filename of the uploaded fileparent - A File indicating the parent directory into which the input File will be placed.content - A byte array containing the content of the uploaded file.maxBytes - The max number of bytes allowed for a legal file upload.allowedExtensions - A List of allowed file extensions to validate againstallowNull - If allowNull is true then an input that is NULL or an empty string will be legal. If allowNull is false then NULL or an empty String will throw a ValidationException.ValidationException - if validation errors occurpublic void assertValidFileUpload(String context, String directorypath, String filename, File parent, byte[] content, int maxBytes, List<String> allowedExtensions, boolean allowNull, List<ValidationException> errors)
context - A descriptive name of the parameter that you are validating (e.g., LoginPage_UsernameField). This value is used by any logging or error handling that is done with respect to the
value passed in.directorypath - The file path of the uploaded file.filename - The filename of the uploaded fileparent - A File indicating the parent directory into which the input File will be placed.content - A byte array containing the content of the uploaded file.maxBytes - The max number of bytes allowed for a legal file upload.allowedExtensions - A List of allowed file extensions to validate againstallowNull - If allowNull is true then an input that is NULL or an empty string will be legal. If allowNull is false then NULL or an empty String will throw a ValidationException.errors - A List to contain any validation errors.public boolean isValidFileContent(String context, byte[] input, int maxBytes, boolean allowNull)
context - A descriptive name of the parameter that you are validating (e.g., LoginPage_UsernameField). This value is used by any logging or error handling that is done with respect to the
value passed in.input - The actual input data to validate.maxBytes - The max number of bytes allowed for a legal file upload.allowNull - If allowNull is true then an input that is NULL or an empty string will be legal. If allowNull is false then NULL or an empty String will throw a ValidationException.public boolean isValidFileContent(String context, byte[] input, int maxBytes, boolean allowNull, List<ValidationException> errors)
context - A descriptive name of the parameter that you are validating (e.g., LoginPage_UsernameField). This value is used by any logging or error handling that is done with respect to the
value passed in.input - The actual input data to validate.maxBytes - The max number of bytes allowed for a legal file upload.allowNull - If allowNull is true then an input that is NULL or an empty string will be legal. If allowNull is false then NULL or an empty String will throw a ValidationException.errors - A List to contain any validation errors.public byte[] getValidFileContent(String context, byte[] input, boolean allowNull) throws ValidationException
context - A descriptive name of the parameter that you are validating (e.g., LoginPage_UsernameField). This value is used by any logging or error handling that is done with respect to the
value passed in.input - The actual input data to validate.allowNull - If allowNull is true then an input that is NULL or an empty string will be legal. If allowNull is false then NULL or an empty String will throw a ValidationException.ValidationException - if validation errors occurpublic byte[] getValidFileContent(String context, byte[] input, long maxBytes, boolean allowNull) throws ValidationException
context - A descriptive name of the parameter that you are validating (e.g., LoginPage_UsernameField). This value is used by any logging or error handling that is done with respect to the
value passed in.input - The actual input data to validate.maxBytes - The max number of bytes allowed for a legal file upload.allowNull - If allowNull is true then an input that is NULL or an empty string will be legal. If allowNull is false then NULL or an empty String will throw a ValidationException.ValidationException - if validation errors occurpublic byte[] getValidFileContent(String context, byte[] input, int maxBytes, boolean allowNull, List<ValidationException> errors) throws ValidationException
context - A descriptive name of the parameter that you are validating (e.g., LoginPage_UsernameField). This value is used by any logging or error handling that is done with respect to the
value passed in.input - The actual input data to validate.maxBytes - The max number of bytes allowed for a legal file upload.allowNull - If allowNull is true then an input that is NULL or an empty string will be legal. If allowNull is false then NULL or an empty String will throw a ValidationException.errors - A List to contain any validation errors.ValidationException - if validation errors occurpublic String getValidInput(String context, String input, String type, int maxLength, boolean allowNull) throws ValidationException
context - A descriptive name for the field to validate. This is used for error facing validation messages and element identification.input - The actual user input data to validate.type - The regular expression name which maps to the actual regular expression from "ESAPI.properties".maxLength - The maximum post-canonicalized String length allowed.allowNull - If allowNull is true then a input that is NULL or an empty string will be legal. If allowNull is false then NULL or an empty String will throw a ValidationException.ValidationException - if validation errors occurpublic String getValidInput(String context, String input, String type, int maxLength, boolean allowNull, boolean canonicalize) throws ValidationException
context - A descriptive name for the field to validate. This is used for error facing validation messages and element identification.input - The actual user input data to validate.type - The regular expression name which maps to the actual regular expression in the ESAPI validation configuration filemaxLength - The maximum String length allowed. If input is canonicalized per the canonicalize argument, then maxLength must be verified after canonicalizationallowNull - If allowNull is true then a input that is NULL or an empty string will be legal. If allowNull is false then NULL or an empty String will throw a ValidationException.canonicalize - If canonicalize is true then input will be canonicalized before validationValidationException - if validation errors occurCopyright © 2017. All rights reserved.