Class AuditWebFilter

java.lang.Object
org.saidone.component.BaseComponent
org.saidone.service.audit.AuditWebFilter
All Implemented Interfaces:
org.springframework.beans.factory.Aware, org.springframework.context.ApplicationContextAware, org.springframework.web.server.WebFilter

@Component @ConditionalOnProperty(name="application.service.vault.audit.enabled", havingValue="true") public class AuditWebFilter extends BaseComponent implements org.springframework.web.server.WebFilter
Web filter that audits incoming requests and outgoing responses.

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 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 interface org.springframework.web.server.WebFilter
      Parameters:
      exchange - the current server exchange
      chain - 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 request
      response - the server response
      Returns:
      populated audit entry for the response