Class StringHelper
- java.lang.Object
-
- hu.icellmobilsoft.coffee.tool.utils.string.StringHelper
-
@Dependent public class StringHelper extends Object
Helper class for String utility functions with 3rd party dependencies (ie. microprofile-config)- Since:
- 1.0.0
- Author:
- mark.petrenyi
-
-
Field Summary
Fields Modifier and Type Field Description static String[]DEFAULT_PATTERNConstantDEFAULT_PATTERN=".*?(pass|secret).*?"
-
Constructor Summary
Constructors Constructor Description StringHelper()Default constructor, constructs a new object.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static String[]getSensitiveKeyPattern()getSensitiveKeyPattern.static StringmaskPropertyValue(String key, Object value)Masks value, if key ignore-case matches a pattern.static StringmaskValueInXmlJson(String text)Masks values belonging to properties ignore-case matching a defined keyPattern in XML or JSON texts.
-
-
-
Field Detail
-
DEFAULT_PATTERN
public static final String[] DEFAULT_PATTERN
ConstantDEFAULT_PATTERN=".*?(pass|secret).*?"
-
-
Method Detail
-
maskPropertyValue
public static String maskPropertyValue(String key, Object value)
Masks value, if key ignore-case matches a pattern. The pattern can be set with "coffee.config.log.sensitive.key.pattern" using microprofile-config's default config sources:- System properties
- Environment properties
- /META-INF/microprofile-config.properties
DEFAULT_PATTERN- Parameters:
key- The key to check against keyPattern.value- The value to mask- Returns:
- "*" if key and pattern are not blank and key matches pattern (case ignored); value otherwise
-
maskValueInXmlJson
public static String maskValueInXmlJson(String text)
Masks values belonging to properties ignore-case matching a defined keyPattern in XML or JSON texts.
The pattern can be set with "coffee.config.log.sensitive.key.pattern" using microprofile-config's default config sources:- System properties
- Environment properties
- /META-INF/microprofile-config.properties
DEFAULT_PATTERN
ie witch default pattern:
keypattern =.*?(pass|secret).*?Example input-output pairs text result <Password>abc</Password><Password>*</Password><verySecretToken>abc</verySecretToken><verySecretToken>*</verySecretToken><userName>abc</userName><userName>abc</userName>"pass":"abc" "pass":"*" "userPassword":"abc" "userPassword":"*" "userName":"abc" "userName":"abc" - Parameters:
text- XML or JSON text to replace sensitive data- Returns:
- masked text
-
getSensitiveKeyPattern
public static String[] getSensitiveKeyPattern()
getSensitiveKeyPattern.
- Returns:
- value of config key "coffee.config.log.sensitive.key.pattern" if set,
DEFAULT_PATTERNotherwise.
-
-