Class MaskingLoggingFilter

java.lang.Object
org.miaixz.bus.gitlab.support.MaskingLoggingFilter
All Implemented Interfaces:
jakarta.ws.rs.client.ClientRequestFilter, jakarta.ws.rs.client.ClientResponseFilter, jakarta.ws.rs.ext.WriterInterceptor

@Priority(-2147483648) public class MaskingLoggingFilter extends Object implements jakarta.ws.rs.client.ClientRequestFilter, jakarta.ws.rs.client.ClientResponseFilter, jakarta.ws.rs.ext.WriterInterceptor
This class logs request and response info masking HTTP header values that are known to contain sensitive information. This class was patterned after org.glassfish.jersey.logging.LoggingInterceptor, but written in such a way that it could be sub-classed and have its behavior modified.
  • Field Details

    • DEFAULT_MASKED_HEADER_NAMES

      public static final List<String> DEFAULT_MASKED_HEADER_NAMES
      Default list of header names that should be masked.
    • REQUEST_PREFIX

      protected static final String REQUEST_PREFIX
      Prefix for request log entries.
      See Also:
    • RESPONSE_PREFIX

      protected static final String RESPONSE_PREFIX
      Prefix for response log entries.
      See Also:
    • SECTION_PREFIX

      protected static final String SECTION_PREFIX
      Prefix that marks the beginning of a request or response section.
      See Also:
    • ENTITY_STREAM_PROPERTY

      protected static final String ENTITY_STREAM_PROPERTY
      Property name for the entity stream property
    • LOGGING_ID_PROPERTY

      protected static final String LOGGING_ID_PROPERTY
      Property name for the logging record id property
    • logger

      protected final Logger logger
    • level

      protected final Level level
    • maxEntitySize

      protected final int maxEntitySize
    • _id

      protected final AtomicLong _id
    • maskedHeaderNames

      protected Set<String> maskedHeaderNames
  • Constructor Details

    • MaskingLoggingFilter

      public MaskingLoggingFilter(Logger logger, Level level)
      Creates a masking logging filter for the specified logger with entity logging disabled.
      Parameters:
      logger - the logger to log messages to
      level - level at which the messages will be logged
    • MaskingLoggingFilter

      public MaskingLoggingFilter(Logger logger, Level level, int maxEntitySize)
      Creates a masking logging filter for the specified logger.
      Parameters:
      logger - the logger to log messages to
      level - level at which the messages will be logged
      maxEntitySize - maximum number of entity bytes to be logged. When logging if the maxEntitySize is reached, the entity logging will be truncated at maxEntitySize and "...more..." will be added at the end of the log entry. If maxEntitySize is <= 0, entity logging will be disabled
    • MaskingLoggingFilter

      public MaskingLoggingFilter(Logger logger, Level level, List<String> maskedHeaderNames)
      Creates a masking logging filter for the specified logger with entity logging disabled.
      Parameters:
      logger - the logger to log messages to
      level - level at which the messages will be logged
      maskedHeaderNames - a list of header names that should have the values masked
    • MaskingLoggingFilter

      public MaskingLoggingFilter(Logger logger, Level level, int maxEntitySize, List<String> maskedHeaderNames)
      Creates a masking logging filter for the specified logger.
      Parameters:
      logger - the logger to log messages to
      level - level at which the messages will be logged
      maxEntitySize - maximum number of entity bytes to be logged. When logging if the maxEntitySize is reached, the entity logging will be truncated at maxEntitySize and "...more..." will be added at the end of the log entry. If maxEntitySize is <= 0, entity logging will be disabled
      maskedHeaderNames - a list of header names that should have the values masked
  • Method Details

    • setMaskedHeaderNames

      public void setMaskedHeaderNames(List<String> maskedHeaderNames)
      Set the list of header names to mask values for. If null, will clear the header names to mask.
      Parameters:
      maskedHeaderNames - a list of header names that should have the values masked, if null, will clear the header names to mask
    • addMaskedHeaderName

      public void addMaskedHeaderName(String maskedHeaderName)
      Add a header name to the list of masked header names.
      Parameters:
      maskedHeaderName - the masked header name to add
    • log

      protected void log(StringBuilder sb)
    • appendId

      protected StringBuilder appendId(StringBuilder sb, long id)
    • printRequestLine

      protected void printRequestLine(StringBuilder sb, String note, long id, String method, URI uri)
    • printResponseLine

      protected void printResponseLine(StringBuilder sb, String note, long id, int status)
    • getSortedHeaders

      protected Set<Map.Entry<String,List<String>>> getSortedHeaders(Set<Map.Entry<String,List<String>>> headers)
    • printHeaders

      protected void printHeaders(StringBuilder sb, long id, String prefix, jakarta.ws.rs.core.MultivaluedMap<String,String> headers)
      Logs each of the HTTP headers, masking the value of the header if the header key is in the list of masked header names.
      Parameters:
      sb - the StringBuilder to build up the logging info in
      id - the ID for the logging line
      prefix - the logging line prefix character
      headers - a MultiValue map holding the header keys and values
    • buildEntityLogString

      protected void buildEntityLogString(StringBuilder sb, byte[] entity, int entitySize, Charset charset)
    • filter

      public void filter(jakarta.ws.rs.client.ClientRequestContext requestContext) throws IOException
      Specified by:
      filter in interface jakarta.ws.rs.client.ClientRequestFilter
      Throws:
      IOException
    • filter

      public void filter(jakarta.ws.rs.client.ClientRequestContext requestContext, jakarta.ws.rs.client.ClientResponseContext responseContext) throws IOException
      Specified by:
      filter in interface jakarta.ws.rs.client.ClientResponseFilter
      Throws:
      IOException
    • aroundWriteTo

      public void aroundWriteTo(jakarta.ws.rs.ext.WriterInterceptorContext context) throws IOException, jakarta.ws.rs.WebApplicationException
      Specified by:
      aroundWriteTo in interface jakarta.ws.rs.ext.WriterInterceptor
      Throws:
      IOException
      jakarta.ws.rs.WebApplicationException