Package org.aoju.bus.gitlab.support
Class MaskingLoggingFilter
java.lang.Object
org.aoju.bus.gitlab.support.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 ClassesModifier and TypeClassDescriptionprotected classThis 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
FieldsModifier and TypeFieldDescriptionprotected final AtomicLongDefault list of header names that should be masked.protected static final StringProperty name for the entity stream propertyprotected final Levelprotected final Loggerprotected static final StringProperty name for the logging record id propertyprotected final intprotected static final StringPrefix for request log entries.protected static final StringPrefix for response log entries.protected static final StringPrefix that marks the beginning of a request or response section. -
Constructor Summary
ConstructorsConstructorDescriptionMaskingLoggingFilter(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 TypeMethodDescriptionvoidaddMaskedHeaderName(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 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
-
REQUEST_PREFIX
-
RESPONSE_PREFIX
-
SECTION_PREFIX
Prefix that marks the beginning of a request or response section.- See Also:
-
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
-
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
-
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
-