Interface SanitizingFunction
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
Function that takes a
SanitizableData
and applies sanitization to the value, if
necessary. Can be used by a Sanitizer
to determine the sanitized value.
This interface also provides convenience methods that can help build a
SanitizingFunction
instances, for example to return from a @Bean
method. See sanitizeValue()
for an example.
- Since:
- 2.6.0
- Author:
- Madhura Bhave, Phillip Webb
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionapply
(SanitizableData data) Apply the sanitizing function to the given data.default SanitizableData
Apply the sanitizing function as long as the filter passes or there is no filter.default Predicate<SanitizableData>
filter()
Return an optional filter that determines if the sanitizing function applies.default SanitizingFunction
ifKeyContains
(String... values) Return a new function with a filter that also applies if the data key contains any of the given values (ignoring case).default SanitizingFunction
ifKeyEndsWith
(String... suffixes) Return a new function with a filter that also applies if the data key ends with any of the given values (ignoring case).default SanitizingFunction
ifKeyEquals
(String... values) Return a new function with a filter that also applies if the data key is equal to any of the given values (ignoring case).default SanitizingFunction
ifKeyMatches
(String... regexes) Return a new function with a filter that also applies if the data key matches any of the given regex patterns (ignoring case).default SanitizingFunction
ifKeyMatches
(Predicate<String> predicate) Return a new function with a filter that also applies if the data key matches any of the given predicate.default SanitizingFunction
ifKeyMatches
(List<Predicate<String>> predicates) Return a new function with a filter that also applies if the data key matches any of the given predicates.default SanitizingFunction
ifKeyMatches
(Pattern... patterns) Return a new function with a filter that also applies if the data key matches any of the given patterns.default SanitizingFunction
ifKeyMatchesIgnoringCase
(BiPredicate<String, String> predicate, String... values) Return a new function with a filter that also applies if the data key and any of the values match the given predicate.default SanitizingFunction
Return a new function with a filter that also applies if the data is likely to contain a credential.default SanitizingFunction
Return a new function with a filter that also applies if the data is likely to contain a sensitive value.default SanitizingFunction
Return a new function with a filter that also applies if the data is likely to contain a sensitive property value.default SanitizingFunction
Return a new function with a filter that also applies if the data is likely to contain a URI.default SanitizingFunction
ifMatches
(Predicate<SanitizableData> predicate) Return a new function with a filter that also applies if the data matches the given predicate.default SanitizingFunction
ifMatches
(List<Predicate<SanitizableData>> predicates) Return a new function with a filter that also applies if the data matches any of the given predicates.default SanitizingFunction
ifValueMatches
(Predicate<Object> predicate) Return a new function with a filter that also applies if the data value matches the given predicate.default SanitizingFunction
ifValueMatches
(List<Predicate<Object>> predicates) Return a new function with a filter that also applies if the data value matches any of the given predicates.default SanitizingFunction
ifValueStringMatches
(String... regexes) Return a new function with a filter that also applies if the data string value matches any of the given regex patterns (ignoring case).default SanitizingFunction
ifValueStringMatches
(Predicate<String> predicate) Return a new function with a filter that also applies if the data string value matches the given predicate.default SanitizingFunction
ifValueStringMatches
(List<Predicate<String>> predicates) Return a new function with a filter that also applies if the data string value matches any of the given predicates.default SanitizingFunction
ifValueStringMatches
(Pattern... patterns) Return a new function with a filter that also applies if the data string value matches any of the given patterns.default SanitizingFunction
Return a new function with a filter that also applies if the data is for VCAP services.static SanitizingFunction
of
(SanitizingFunction sanitizingFunction) Helper method that can be used working with a sanitizingFunction as a lambda.static SanitizingFunction
Factory method to return aSanitizingFunction
that sanitizes the value.
-
Method Details
-
apply
Apply the sanitizing function to the given data.- Parameters:
data
- the data to sanitize- Returns:
- the sanitized data or the original instance is no sanitization is applied
-
filter
Return an optional filter that determines if the sanitizing function applies.- Returns:
- a predicate used to filter functions or
null
if no filter is declared - Since:
- 3.5.0
- See Also:
-
applyUnlessFiltered
Apply the sanitizing function as long as the filter passes or there is no filter.- Parameters:
data
- the data to sanitize- Returns:
- the sanitized data or the original instance is no sanitization is applied
- Since:
- 3.5.0
-
ifLikelySensitive
Return a new function with a filter that also applies if the data is likely to contain a sensitive value. This method can help construct a useful sanitizing function, but may not catch all sensitive data so care should be taken to test the results for your specific environment.- Returns:
- a new sanitizing function with an updated
filter()
- Since:
- 3.5.0
- See Also:
-
ifLikelyCredential
Return a new function with a filter that also applies if the data is likely to contain a credential. This method can help construct a useful sanitizing function, but may not catch all sensitive data so care should be taken to test the results for your specific environment.- Returns:
- a new sanitizing function with an updated
filter()
- Since:
- 3.5.0
- See Also:
-
ifLikelyUri
Return a new function with a filter that also applies if the data is likely to contain a URI. This method can help construct a useful sanitizing function, but may not catch all sensitive data so care should be taken to test the results for your specific environment.- Returns:
- a new sanitizing function with an updated
filter()
- Since:
- 3.5.0
- See Also:
-
ifLikelySensitiveProperty
Return a new function with a filter that also applies if the data is likely to contain a sensitive property value. This method can help construct a useful sanitizing function, but may not catch all sensitive data so care should be taken to test the results for your specific environment.- Returns:
- a new sanitizing function with an updated
filter()
- Since:
- 3.5.0
- See Also:
-
ifVcapServices
Return a new function with a filter that also applies if the data is for VCAP services.- Returns:
- a new sanitizing function with an updated
filter()
- Since:
- 3.5.0
- See Also:
-
ifKeyEquals
Return a new function with a filter that also applies if the data key is equal to any of the given values (ignoring case).- Parameters:
values
- the case insensitive values that the key can equal- Returns:
- a new sanitizing function with an updated
filter()
- Since:
- 3.5.0
- See Also:
-
ifKeyEndsWith
Return a new function with a filter that also applies if the data key ends with any of the given values (ignoring case).- Parameters:
suffixes
- the case insensitive suffixes that they key can end with- Returns:
- a new sanitizing function with an updated
filter()
- Since:
- 3.5.0
- See Also:
-
ifKeyContains
Return a new function with a filter that also applies if the data key contains any of the given values (ignoring case).- Parameters:
values
- the case insensitive values that the key can contain- Returns:
- a new sanitizing function with an updated
filter()
- Since:
- 3.5.0
- See Also:
-
ifKeyMatchesIgnoringCase
default SanitizingFunction ifKeyMatchesIgnoringCase(BiPredicate<String, String> predicate, String... values) Return a new function with a filter that also applies if the data key and any of the values match the given predicate. The predicate is only called with lower case values.- Parameters:
predicate
- the predicate used to check the key against a value. The key is the first argument and the value is the second. Both are converted to lower casevalues
- the case insensitive values that the key can match- Returns:
- a new sanitizing function with an updated
filter()
- Since:
- 3.5.0
- See Also:
-
ifKeyMatches
Return a new function with a filter that also applies if the data key matches any of the given regex patterns (ignoring case).- Parameters:
regexes
- the case insensitive regexes that the key can match- Returns:
- a new sanitizing function with an updated
filter()
- Since:
- 3.5.0
- See Also:
-
ifKeyMatches
Return a new function with a filter that also applies if the data key matches any of the given patterns.- Parameters:
patterns
- the patterns that the key can match- Returns:
- a new sanitizing function with an updated
filter()
- Since:
- 3.5.0
- See Also:
-
ifKeyMatches
Return a new function with a filter that also applies if the data key matches any of the given predicates.- Parameters:
predicates
- the predicates that the key can match- Returns:
- a new sanitizing function with an updated
filter()
- Since:
- 3.5.0
- See Also:
-
ifKeyMatches
Return a new function with a filter that also applies if the data key matches any of the given predicate.- Parameters:
predicate
- the predicate that the key can match- Returns:
- a new sanitizing function with an updated
filter()
- Since:
- 3.5.0
- See Also:
-
ifValueStringMatches
Return a new function with a filter that also applies if the data string value matches any of the given regex patterns (ignoring case).- Parameters:
regexes
- the case insensitive regexes that the values string can match- Returns:
- a new sanitizing function with an updated
filter()
- Since:
- 3.5.0
- See Also:
-
ifValueStringMatches
Return a new function with a filter that also applies if the data string value matches any of the given patterns.- Parameters:
patterns
- the patterns that the value string can match- Returns:
- a new sanitizing function with an updated
filter()
- Since:
- 3.5.0
- See Also:
-
ifValueStringMatches
Return a new function with a filter that also applies if the data string value matches any of the given predicates.- Parameters:
predicates
- the predicates that the value string can match- Returns:
- a new sanitizing function with an updated
filter()
- Since:
- 3.5.0
- See Also:
-
ifValueMatches
Return a new function with a filter that also applies if the data value matches any of the given predicates.- Parameters:
predicates
- the predicates that the value can match- Returns:
- a new sanitizing function with an updated
filter()
- Since:
- 3.5.0
- See Also:
-
ifValueStringMatches
Return a new function with a filter that also applies if the data string value matches the given predicate.- Parameters:
predicate
- the predicate that the value string can match- Returns:
- a new sanitizing function with an updated
filter()
- Since:
- 3.5.0
- See Also:
-
ifValueMatches
Return a new function with a filter that also applies if the data value matches the given predicate.- Parameters:
predicate
- the predicate that the value can match- Returns:
- a new sanitizing function with an updated
filter()
- Since:
- 3.5.0
- See Also:
-
ifMatches
Return a new function with a filter that also applies if the data matches any of the given predicates.- Parameters:
predicates
- the predicates that the data can match- Returns:
- a new sanitizing function with an updated
filter()
- Since:
- 3.5.0
- See Also:
-
ifMatches
Return a new function with a filter that also applies if the data matches the given predicate.- Parameters:
predicate
- the predicate that the data can match- Returns:
- a new sanitizing function with an updated
filter()
- Since:
- 3.5.0
- See Also:
-
sanitizeValue
Factory method to return aSanitizingFunction
that sanitizes the value. This method is often chained with one or moreif...
methods. For example:return SanitizingFunction.sanitizeValue() .ifKeyContains("password", "secret") .ifValueStringMatches("^gh._[a-zA-Z0-9]{36}$");
- Returns:
- a
SanitizingFunction
that sanitizes values.
-
of
Helper method that can be used working with a sanitizingFunction as a lambda. For example:SanitizingFunction.of((data) -> data.withValue("----")).ifKeyContains("password");
- Parameters:
sanitizingFunction
- the sanitizing function lambda- Returns:
- a
SanitizingFunction
for further method calls - Since:
- 3.5.0
-