Package org.gitlab4j.api.utils
Class MaskingLoggingFilter
- java.lang.Object
-
- org.gitlab4j.api.utils.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 java.lang.Object implements jakarta.ws.rs.client.ClientRequestFilter, jakarta.ws.rs.client.ClientResponseFilter, jakarta.ws.rs.ext.WriterInterceptorThis 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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected classMaskingLoggingFilter.LoggingStreamThis class is responsible for logging the request entities, it will truncate at maxEntitySize and add "...more..." to the end of the entity log string.
-
Field Summary
Fields Modifier and Type Field Description protected java.util.concurrent.atomic.AtomicLong_idstatic java.util.List<java.lang.String>DEFAULT_MASKED_HEADER_NAMESDefault list of header names that should be masked.protected static java.lang.StringENTITY_STREAM_PROPERTYProperty name for the entity stream propertyprotected java.util.logging.Levellevelprotected java.util.logging.Loggerloggerprotected static java.lang.StringLOGGING_ID_PROPERTYProperty name for the logging record id propertyprotected java.util.Set<java.lang.String>maskedHeaderNamesprotected intmaxEntitySizeprotected static java.lang.StringREQUEST_PREFIXPrefix for request log entries.protected static java.lang.StringRESPONSE_PREFIXPrefix for response log entries.protected static java.lang.StringSECTION_PREFIXPrefix that marks the beginning of a request or response section.
-
Constructor Summary
Constructors Constructor Description MaskingLoggingFilter(java.util.logging.Logger logger, java.util.logging.Level level)Creates a masking logging filter for the specified logger with entity logging disabled.MaskingLoggingFilter(java.util.logging.Logger logger, java.util.logging.Level level, int maxEntitySize)Creates a masking logging filter for the specified logger.MaskingLoggingFilter(java.util.logging.Logger logger, java.util.logging.Level level, int maxEntitySize, java.util.List<java.lang.String> maskedHeaderNames)Creates a masking logging filter for the specified logger.MaskingLoggingFilter(java.util.logging.Logger logger, java.util.logging.Level level, java.util.List<java.lang.String> maskedHeaderNames)Creates a masking logging filter for the specified logger with entity logging disabled.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddMaskedHeaderName(java.lang.String maskedHeaderName)Add a header name to the list of masked header names.protected java.lang.StringBuilderappendId(java.lang.StringBuilder sb, long id)voidaroundWriteTo(jakarta.ws.rs.ext.WriterInterceptorContext context)protected voidbuildEntityLogString(java.lang.StringBuilder sb, byte[] entity, int entitySize, java.nio.charset.Charset charset)voidfilter(jakarta.ws.rs.client.ClientRequestContext requestContext)voidfilter(jakarta.ws.rs.client.ClientRequestContext requestContext, jakarta.ws.rs.client.ClientResponseContext responseContext)protected java.util.Set<java.util.Map.Entry<java.lang.String,java.util.List<java.lang.String>>>getSortedHeaders(java.util.Set<java.util.Map.Entry<java.lang.String,java.util.List<java.lang.String>>> headers)protected voidlog(java.lang.StringBuilder sb)protected voidprintHeaders(java.lang.StringBuilder sb, long id, java.lang.String prefix, jakarta.ws.rs.core.MultivaluedMap<java.lang.String,java.lang.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.protected voidprintRequestLine(java.lang.StringBuilder sb, java.lang.String note, long id, java.lang.String method, java.net.URI uri)protected voidprintResponseLine(java.lang.StringBuilder sb, java.lang.String note, long id, int status)voidsetMaskedHeaderNames(java.util.List<java.lang.String> maskedHeaderNames)Set the list of header names to mask values for.
-
-
-
Field Detail
-
DEFAULT_MASKED_HEADER_NAMES
public static final java.util.List<java.lang.String> DEFAULT_MASKED_HEADER_NAMES
Default list of header names that should be masked.
-
REQUEST_PREFIX
protected static final java.lang.String REQUEST_PREFIX
Prefix for request log entries.- See Also:
- Constant Field Values
-
RESPONSE_PREFIX
protected static final java.lang.String RESPONSE_PREFIX
Prefix for response log entries.- See Also:
- Constant Field Values
-
SECTION_PREFIX
protected static final java.lang.String SECTION_PREFIX
Prefix that marks the beginning of a request or response section.- See Also:
- Constant Field Values
-
ENTITY_STREAM_PROPERTY
protected static final java.lang.String ENTITY_STREAM_PROPERTY
Property name for the entity stream property
-
LOGGING_ID_PROPERTY
protected static final java.lang.String LOGGING_ID_PROPERTY
Property name for the logging record id property
-
logger
protected final java.util.logging.Logger logger
-
level
protected final java.util.logging.Level level
-
maxEntitySize
protected final int maxEntitySize
-
_id
protected final java.util.concurrent.atomic.AtomicLong _id
-
maskedHeaderNames
protected java.util.Set<java.lang.String> maskedHeaderNames
-
-
Constructor Detail
-
MaskingLoggingFilter
public MaskingLoggingFilter(java.util.logging.Logger logger, java.util.logging.Level level)Creates a masking logging filter for the specified logger with entity logging disabled.- Parameters:
logger- the logger to log messages tolevel- level at which the messages will be logged
-
MaskingLoggingFilter
public MaskingLoggingFilter(java.util.logging.Logger logger, java.util.logging.Level level, int maxEntitySize)Creates a masking logging filter for the specified logger.- Parameters:
logger- the logger to log messages tolevel- level at which the messages will be loggedmaxEntitySize- 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(java.util.logging.Logger logger, java.util.logging.Level level, java.util.List<java.lang.String> maskedHeaderNames)Creates a masking logging filter for the specified logger with entity logging disabled.- Parameters:
logger- the logger to log messages tolevel- level at which the messages will be loggedmaskedHeaderNames- a list of header names that should have the values masked
-
MaskingLoggingFilter
public MaskingLoggingFilter(java.util.logging.Logger logger, java.util.logging.Level level, int maxEntitySize, java.util.List<java.lang.String> maskedHeaderNames)Creates a masking logging filter for the specified logger.- Parameters:
logger- the logger to log messages tolevel- level at which the messages will be loggedmaxEntitySize- 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 disabledmaskedHeaderNames- a list of header names that should have the values masked
-
-
Method Detail
-
setMaskedHeaderNames
public void setMaskedHeaderNames(java.util.List<java.lang.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(java.lang.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(java.lang.StringBuilder sb)
-
appendId
protected java.lang.StringBuilder appendId(java.lang.StringBuilder sb, long id)
-
printRequestLine
protected void printRequestLine(java.lang.StringBuilder sb, java.lang.String note, long id, java.lang.String method, java.net.URI uri)
-
printResponseLine
protected void printResponseLine(java.lang.StringBuilder sb, java.lang.String note, long id, int status)
-
getSortedHeaders
protected java.util.Set<java.util.Map.Entry<java.lang.String,java.util.List<java.lang.String>>> getSortedHeaders(java.util.Set<java.util.Map.Entry<java.lang.String,java.util.List<java.lang.String>>> headers)
-
printHeaders
protected void printHeaders(java.lang.StringBuilder sb, long id, java.lang.String prefix, jakarta.ws.rs.core.MultivaluedMap<java.lang.String,java.lang.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 inid- the ID for the logging lineprefix- the logging line prefix characterheaders- a MultiValue map holding the header keys and values
-
buildEntityLogString
protected void buildEntityLogString(java.lang.StringBuilder sb, byte[] entity, int entitySize, java.nio.charset.Charset charset)
-
filter
public void filter(jakarta.ws.rs.client.ClientRequestContext requestContext) throws java.io.IOException- Specified by:
filterin interfacejakarta.ws.rs.client.ClientRequestFilter- Throws:
java.io.IOException
-
filter
public void filter(jakarta.ws.rs.client.ClientRequestContext requestContext, jakarta.ws.rs.client.ClientResponseContext responseContext) throws java.io.IOException- Specified by:
filterin interfacejakarta.ws.rs.client.ClientResponseFilter- Throws:
java.io.IOException
-
aroundWriteTo
public void aroundWriteTo(jakarta.ws.rs.ext.WriterInterceptorContext context) throws java.io.IOException, jakarta.ws.rs.WebApplicationException- Specified by:
aroundWriteToin interfacejakarta.ws.rs.ext.WriterInterceptor- Throws:
java.io.IOExceptionjakarta.ws.rs.WebApplicationException
-
-