Package org.gitlab4j.api.utils
Class MaskingLoggingFilter
java.lang.Object
org.gitlab4j.api.utils.MaskingLoggingFilter
- All Implemented Interfaces:
javax.ws.rs.client.ClientRequestFilter,javax.ws.rs.client.ClientResponseFilter,javax.ws.rs.ext.WriterInterceptor
@Priority(-2147483648) public class MaskingLoggingFilter extends Object implements javax.ws.rs.client.ClientRequestFilter, javax.ws.rs.client.ClientResponseFilter, javax.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.
-
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 AtomicLong_idstatic List<String>DEFAULT_MASKED_HEADER_NAMESDefault list of header names that should be masked.protected static StringENTITY_STREAM_PROPERTYProperty name for the entity stream propertyprotected Levellevelprotected Loggerloggerprotected static StringLOGGING_ID_PROPERTYProperty name for the logging record id propertyprotected Set<String>maskedHeaderNamesprotected intmaxEntitySizeprotected static StringREQUEST_PREFIXPrefix for request log entries.protected static StringRESPONSE_PREFIXPrefix for response log entries.protected static StringSECTION_PREFIXPrefix that marks the beginning of a request or response section. -
Constructor Summary
Constructors Constructor Description MaskingLoggingFilter(Logger logger, Level level)Creates a masking logging filter for the specified logger with entity logging disabled.MaskingLoggingFilter(Logger logger, Level level, int maxEntitySize)Creates a masking logging filter for the specified logger.MaskingLoggingFilter(Logger logger, Level level, int maxEntitySize, List<String> maskedHeaderNames)Creates a masking logging filter for the specified logger.MaskingLoggingFilter(Logger logger, Level level, List<String> maskedHeaderNames)Creates a masking logging filter for the specified logger with entity logging disabled. -
Method Summary
Modifier and Type Method Description voidaddMaskedHeaderName(String maskedHeaderName)Add a header name to the list of masked header names.protected StringBuilderappendId(StringBuilder sb, long id)voidaroundWriteTo(javax.ws.rs.ext.WriterInterceptorContext context)protected voidbuildEntityLogString(StringBuilder sb, byte[] entity, int entitySize, Charset charset)voidfilter(javax.ws.rs.client.ClientRequestContext requestContext)voidfilter(javax.ws.rs.client.ClientRequestContext requestContext, javax.ws.rs.client.ClientResponseContext responseContext)protected Set<Map.Entry<String,List<String>>>getSortedHeaders(Set<Map.Entry<String,List<String>>> headers)protected voidlog(StringBuilder sb)protected voidprintHeaders(StringBuilder sb, long id, String prefix, javax.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.protected voidprintRequestLine(StringBuilder sb, String note, long id, String method, URI uri)protected voidprintResponseLine(StringBuilder sb, String note, long id, int status)voidsetMaskedHeaderNames(List<String> maskedHeaderNames)Set the list of header names to mask values for.
-
Field Details
-
DEFAULT_MASKED_HEADER_NAMES
Default list of header names that should be masked. -
REQUEST_PREFIX
Prefix for request log entries.- See Also:
- Constant Field Values
-
RESPONSE_PREFIX
Prefix for response log entries.- See Also:
- Constant Field Values
-
SECTION_PREFIX
Prefix that marks the beginning of a request or response section.- See Also:
- Constant Field Values
-
ENTITY_STREAM_PROPERTY
Property name for the entity stream property -
LOGGING_ID_PROPERTY
Property name for the logging record id property -
logger
-
level
-
maxEntitySize
protected final int maxEntitySize -
_id
-
maskedHeaderNames
-
-
Constructor Details
-
MaskingLoggingFilter
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
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
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(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 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 Details
-
setMaskedHeaderNames
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
Add a header name to the list of masked header names.- Parameters:
maskedHeaderName- the masked header name to add
-
log
-
appendId
-
printRequestLine
-
printResponseLine
-
getSortedHeaders
-
printHeaders
protected void printHeaders(StringBuilder sb, long id, String prefix, javax.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 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(StringBuilder sb, byte[] entity, int entitySize, Charset charset) -
filter
- Specified by:
filterin interfacejavax.ws.rs.client.ClientRequestFilter- Throws:
IOException
-
filter
public void filter(javax.ws.rs.client.ClientRequestContext requestContext, javax.ws.rs.client.ClientResponseContext responseContext) throws IOException- Specified by:
filterin interfacejavax.ws.rs.client.ClientResponseFilter- Throws:
IOException
-
aroundWriteTo
public void aroundWriteTo(javax.ws.rs.ext.WriterInterceptorContext context) throws IOException, javax.ws.rs.WebApplicationException- Specified by:
aroundWriteToin interfacejavax.ws.rs.ext.WriterInterceptor- Throws:
IOExceptionjavax.ws.rs.WebApplicationException
-