Class 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 Detail

      • DEFAULT_PATTERN

        public static final String[] DEFAULT_PATTERN
        Constant DEFAULT_PATTERN=".*?(pass|secret).*?"
    • Constructor Detail

      • StringHelper

        public StringHelper()
        Default constructor, constructs a new object.
    • 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:
        1. System properties
        2. Environment properties
        3. /META-INF/microprofile-config.properties
        If pattern is not set via config it dafaults to 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:
        1. System properties
        2. Environment properties
        3. /META-INF/microprofile-config.properties
        If pattern is not set via config it defaults to 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