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 SanitizableDataApply 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 SanitizingFunctionifKeyContains(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 SanitizingFunctionifKeyEndsWith(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 SanitizingFunctionifKeyEquals(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 SanitizingFunctionifKeyMatches(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 SanitizingFunctionifKeyMatches(Predicate<String> predicate) Return a new function with a filter that also applies if the data key matches any of the given predicate.default SanitizingFunctionifKeyMatches(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 SanitizingFunctionifKeyMatches(Pattern... patterns) Return a new function with a filter that also applies if the data key matches any of the given patterns.default SanitizingFunctionifKeyMatchesIgnoringCase(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 SanitizingFunctionReturn a new function with a filter that also applies if the data is likely to contain a credential.default SanitizingFunctionReturn a new function with a filter that also applies if the data is likely to contain a sensitive value.default SanitizingFunctionReturn a new function with a filter that also applies if the data is likely to contain a sensitive property value.default SanitizingFunctionReturn a new function with a filter that also applies if the data is likely to contain a URI.default SanitizingFunctionifMatches(Predicate<SanitizableData> predicate) Return a new function with a filter that also applies if the data matches the given predicate.default SanitizingFunctionifMatches(List<Predicate<SanitizableData>> predicates) Return a new function with a filter that also applies if the data matches any of the given predicates.default SanitizingFunctionifValueMatches(Predicate<Object> predicate) Return a new function with a filter that also applies if the data value matches the given predicate.default SanitizingFunctionifValueMatches(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 SanitizingFunctionifValueStringMatches(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 SanitizingFunctionifValueStringMatches(Predicate<String> predicate) Return a new function with a filter that also applies if the data string value matches the given predicate.default SanitizingFunctionifValueStringMatches(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 SanitizingFunctionifValueStringMatches(Pattern... patterns) Return a new function with a filter that also applies if the data string value matches any of the given patterns.default SanitizingFunctionReturn a new function with a filter that also applies if the data is for VCAP services.static SanitizingFunctionof(SanitizingFunction sanitizingFunction) Helper method that can be used working with a sanitizingFunction as a lambda.static SanitizingFunctionFactory method to return aSanitizingFunctionthat 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
nullif 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 aSanitizingFunctionthat 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
SanitizingFunctionthat 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
SanitizingFunctionfor further method calls - Since:
- 3.5.0
-