Class MaskingJsonGeneratorDecorator

java.lang.Object
net.logstash.logback.mask.MaskingJsonGeneratorDecorator
All Implemented Interfaces:
LifeCycle, JsonGeneratorDecorator

public class MaskingJsonGeneratorDecorator extends Object implements JsonGeneratorDecorator, LifeCycle
A JsonGeneratorDecorator that wraps a JsonGenerator with a MaskingJsonGenerator, so that sensitive field values can be masked.
  • Constructor Details

    • MaskingJsonGeneratorDecorator

      public MaskingJsonGeneratorDecorator()
  • Method Details

    • isStarted

      public boolean isStarted()
      Specified by:
      isStarted in interface LifeCycle
    • start

      public void start()
      Specified by:
      start in interface LifeCycle
    • stop

      public void stop()
      Specified by:
      stop in interface LifeCycle
    • decorate

      public JsonGenerator decorate(JsonGenerator generator)
      Description copied from interface: JsonGeneratorDecorator
      Decorates the given generator, and returns the decorated generator.

      The returned decorator does not need to be the same object as the given generator.

      Specified by:
      decorate in interface JsonGeneratorDecorator
      Parameters:
      generator - the generator to decorate
      Returns:
      the decorated generator
    • setDefaultMask

      public void setDefaultMask(String defaultMask)
      Sets the default mask value to use for any paths added via addPath(String) and values added via addValue(String).

      By default, this is "****".

      Parameters:
      defaultMask - the default mask value to be used to mask real values.
    • addPath

      public void addPath(String pathToMask)
      Adds the given path to the paths that will be masked.

      The default mask value will be substituted for values at the given path.

      Parameters:
      pathToMask - the path to mask. See PathBasedFieldMasker for the format.
    • addPaths

      public void addPaths(String pathsToMask)
      Adds the given comma separated paths to the paths that will be masked.

      The default mask value will be substituted for values at the given paths.

      Parameters:
      pathsToMask - comma separate string of paths to mask. See PathBasedFieldMasker for the format.
    • addPathMask

      public void addPathMask(MaskingJsonGeneratorDecorator.PathMask pathMask)
      Adds the given paths and mask that will be used to determine if a field should be masked.

      The mask value will be written for any of the paths.

      Parameters:
      pathMask - a paths used to determine if a value should be masked, and their corresponding mask value.
    • addPathMaskSupplier

      public void addPathMaskSupplier(MaskingJsonGeneratorDecorator.PathMaskSupplier pathMaskSupplier)
      Adds the given supplier of paths and mask that will be used to determine if a field should be masked.

      The mask value will be written for any of the paths.

      Parameters:
      pathMaskSupplier - a supplier of paths used to determine if a value should be masked, and their corresponding mask value.
    • addFieldMasker

      public void addFieldMasker(FieldMasker fieldMasker)
      Add the given FieldMasker to the maskers used to mask a field.
      Parameters:
      fieldMasker - the masker to add
    • addValue

      public void addValue(String valueToMask)
      Adds the given value regex to the regexes that will be used to determine if a field value should be masked.

      The default mask value will be substituted for values that match the given regex.

      Parameters:
      valueToMask - a regular expression used to determine if a value should be masked.
    • addValues

      public void addValues(String valuesToMask)
      Adds the comma separated string of value regexes to the regexes that will be used to determine if a field value should be masked.

      The default mask value will be substituted for values that match the given regexes.

      Parameters:
      valuesToMask - comma-separated string of regular expressions used to determine if a value should be masked.
    • addValueMask

      public void addValueMask(MaskingJsonGeneratorDecorator.ValueMask valueMask)
      Adds the given value regexes and mask to the regexes that will be used to determine if a field value should be masked.

      The mask value will be written for values that match any of the value regexes.

      Parameters:
      valueMask - regular expressions used to determine if a value should be masked, and their corresponding mask value
    • addValueMaskSupplier

      public void addValueMaskSupplier(MaskingJsonGeneratorDecorator.ValueMaskSupplier valueMaskSupplier)
      Adds the given supplier of value regexes and mask to the regexes that will be used to determine if a field value should be masked.

      The mask value will be written for values that match any of the value regexes.

      Parameters:
      valueMaskSupplier - a supplier of regular expressions used to determine if a value should be masked, and their corresponding mask value
    • addValueMasker

      public void addValueMasker(ValueMasker valueMasker)
      Add the given ValueMasker to the maskers used to mask a value.
      Parameters:
      valueMasker - the masker to add