Class Obfuscator


  • public final class Obfuscator
    extends Object
    Simple obfuscator for object trees and configuration containers with key-value pairs. Matches a configurable set of patterns and replaces sensitive values with a pre-defined masked value for output. Example input:
       {
         "type": "sample object",
         "nestedCredentials": {
           "user": "admin",
           "password": "verysecret"
         }
       }
     
    Example output
       {
         "type": "sample object",
         "nestedCredentials": {
           "user": "admin",
           "password": "*****"
         }
       }
     
    • Constructor Detail

      • Obfuscator

        public Obfuscator()
        Obfuscator with default behavior matching (ignore case) "secret", "password", and "token" suffixes. Masks any values with '*****'
      • Obfuscator

        public Obfuscator​(String maskedValue,
                          List<Pattern> patterns)
        Obfuscator with customized masking behavior. Defaults do not apply! Please ensure case-insensitive regex matching.
        Parameters:
        maskedValue - replacement value
        patterns - key patterns to obfuscate
    • Method Detail

      • toJson

        public com.fasterxml.jackson.databind.JsonNode toJson​(Object object)
        Serialize an object tree to JSON and obfuscate matching keys. This method handles special cases for JsonNode and String objects separately to minimize surprises.
        Parameters:
        object - input tree
        Returns:
        obfuscated JSON tree
      • toJsonString

        public String toJsonString​(Object object)
        Serialize an object tree to a JSON string and obfuscate matching keys.
        Parameters:
        object - input tree
        Returns:
        obfuscated JSON string