Class AuditWebFilter
- All Implemented Interfaces:
org.springframework.beans.factory.Aware
,org.springframework.context.ApplicationContextAware
,org.springframework.web.server.WebFilter
For each request the filter collects basic metadata such as IP address,
User-Agent
, request path and HTTP method and persists it using
AuditServiceImpl
. After the response has been sent another audit
entry is stored containing at least the HTTP status code.
The filter is active only when the configuration property
application.service.vault.audit.enabled
is set to true
.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic AuditEntry
createRequestAuditEntry
(org.springframework.http.server.reactive.ServerHttpRequest request) Build an audit entry representing an incoming HTTP request.static AuditEntry
createResponseAuditEntry
(String id, org.springframework.http.server.reactive.ServerHttpResponse response) Build an audit entry representing an HTTP response.reactor.core.publisher.Mono
<Void> filter
(org.springframework.web.server.ServerWebExchange exchange, org.springframework.web.server.WebFilterChain chain) Intercepts the request/response exchange to persist basic audit information.Methods inherited from class org.saidone.component.BaseComponent
init, setApplicationContext, shutDown, stop
-
Constructor Details
-
AuditWebFilter
public AuditWebFilter()
-
-
Method Details
-
filter
@NotNull public reactor.core.publisher.Mono<Void> filter(org.springframework.web.server.ServerWebExchange exchange, org.springframework.web.server.WebFilterChain chain) Intercepts the request/response exchange to persist basic audit information.The request is audited before the rest of the filter chain executes. After the chain completes, a second entry is stored describing the response.
- Specified by:
filter
in interfaceorg.springframework.web.server.WebFilter
- Parameters:
exchange
- the current server exchangechain
- the remaining web filter chain- Returns:
- completion signal for the filter chain
-
createRequestAuditEntry
public static AuditEntry createRequestAuditEntry(org.springframework.http.server.reactive.ServerHttpRequest request) Build an audit entry representing an incoming HTTP request.The metadata map of the returned entry contains information such as the request identifier, client IP,
User-Agent
, path and HTTP method.- Parameters:
request
- the server request- Returns:
- populated audit entry for the request
-
createResponseAuditEntry
public static AuditEntry createResponseAuditEntry(String id, org.springframework.http.server.reactive.ServerHttpResponse response) Build an audit entry representing an HTTP response.The metadata map of the returned entry contains the identifier of the original request and the response status code.
- Parameters:
id
- identifier of the related requestresponse
- the server response- Returns:
- populated audit entry for the response
-