public class DataSanitizer
extends java.lang.Object
IMPORTANT: These sanitize methods will modify the object values for matching keys. It is up to the caller to copy/clone the object. There are static helper methods for performing a deep clone of Maps and IData objects.
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
DEFAULT_MASK
The default mask: *******
|
Constructor and Description |
---|
DataSanitizer(java.lang.String... keys)
The list of keys to sanitize.
|
Modifier and Type | Method and Description |
---|---|
static IData |
cloneIData(IData data)
Clones an IData.
|
static java.util.Map<java.lang.String,java.lang.Object> |
cloneMap(java.util.Map<java.lang.String,java.lang.Object> map)
Clones a Map.
|
java.lang.String |
getMask()
Returns the mask used to replace sensitive values.
|
boolean |
sanitize(IData source)
Sanitizes an IData for the specified keys.
|
boolean |
sanitize(java.util.Map<java.lang.String,java.lang.Object> source)
Sanitizes a Map for the specified keys.
|
java.lang.String |
sanitize(java.lang.String source)
Sanitizes fields identified as
sensitiveKeys in a String that does not contain a delimiter. |
java.lang.String |
sanitize(java.lang.String source,
java.lang.String delimiter)
Sanitizes fields identified as
sensitiveKeys in a String with delimited fields. |
boolean |
sanitizePojo(java.lang.Object source)
Sanitizes a POJO for the specified keys.
|
void |
setMask(java.lang.String mask)
Sets the mask that replaces sensitive values.
|
void |
setSkipClasses(java.lang.Class<?>... classes)
Classes of the fields to exclude from inspection.
|
public static final java.lang.String DEFAULT_MASK
public DataSanitizer(java.lang.String... keys)
keys
- The list of keys to sanitize.public void setSkipClasses(java.lang.Class<?>... classes)
classes
- Classes containing fields to exclude from inspection.public java.lang.String getMask()
setMask(String)
public void setMask(java.lang.String mask)
setMask(String)
mask
- The mask to use to replace sensitive values.public boolean sanitizePojo(java.lang.Object source) throws DataSanitizerException
source
are also inspected.source
- the POJO to sanitizeDataSanitizerException
public boolean sanitize(IData source) throws DataSanitizerException
source
are also inspected.source
- the IData to sanitizeDataSanitizerException
public boolean sanitize(java.util.Map<java.lang.String,java.lang.Object> source) throws DataSanitizerException
source
are also inspected.source
- the Map to sanitizeDataSanitizerException
public java.lang.String sanitize(java.lang.String source)
sensitiveKeys
in a String that does not contain a delimiter.
In this case, the entire String is masked until another sensitive key is found
or the end of the String is reached.source
- public java.lang.String sanitize(java.lang.String source, java.lang.String delimiter)
sensitiveKeys
in a String with delimited fields.
Note: When source
contains key-value pairs, this method
recognizes a delimiter; however, it does not recognize a key-value pair
separator (e.g., '='). Therefore, the key-value separator will be masked along with
the sensitive value.source
- the String to sanitizedelimiter
- Optional delimiter to signal end of a key value.
If not provided, the mask
is applied to the end of the source string.public static IData cloneIData(IData data) throws DataSanitizerException
IDataUtil.deepClone(IData)
.data
- IData to cloneDataSanitizerException
public static java.util.Map<java.lang.String,java.lang.Object> cloneMap(java.util.Map<java.lang.String,java.lang.Object> map) throws DataSanitizerException
Serializable
and not contain transient fields.map
- DataSanitizerException