Class Mask


  • public class Mask
    extends Object
    A utility to mask sensitive data based on regex pattern before logging
    Author:
    Steve Hu
    • Constructor Detail

      • Mask

        public Mask()
    • Method Detail

      • maskString

        public static String maskString​(String input,
                                        String key)
        Mask the input string with a list of patterns indexed by key in string section in mask.json This is usually used to mask header values, query parameters and uri parameters
        Parameters:
        input - String The source of the string that needs to be masked
        key - String The key that maps to a list of patterns for masking in config file
        Returns:
        Masked result
      • maskRegex

        public static String maskRegex​(String input,
                                       String key,
                                       String name)
        Replace a string input with a pattern found in regex section with key as index. Usually, it is used to replace header, query parameter, uri parameter to same length of stars(*)
        Parameters:
        input - String The source of the string that needs to be masked
        key - String The key maps to a list of name to pattern pair
        name - String The name of the pattern in the key list
        Returns:
        String Masked result
      • maskJson

        public static String maskJson​(String input,
                                      String key)
        Replace values in JSON using json path
        Parameters:
        input - String The source of the string that needs to be masked
        key - String The key maps to a list of json path for masking
        Returns:
        String Masked result
      • maskJson

        public static String maskJson​(InputStream input,
                                      String key)
        Replace values in JSON using json path
        Parameters:
        input - InputStream inputStream of json that needs to be masked
        key - String The key maps to a list of json path for masking
        Returns:
        String Masked result
      • maskJson

        public static String maskJson​(Object input,
                                      String key)
        Replace values in JSON using json path
        Parameters:
        input - Object POJO of json that needs to be masked
        key - String The key maps to a list of json path for masking
        Returns:
        String Masked result
      • maskJson

        public static String maskJson​(com.jayway.jsonpath.DocumentContext ctx,
                                      String key)