Class MongoDBAuditBackend

All Implemented Interfaces:
AuditBackend, AuditAdmin, AuditLogger<LogEntry>, AuditReader<LogEntry>, AuditStorage, Logs<LogEntry>, AuditBackend<LogEntry>

public class MongoDBAuditBackend extends AbstractAuditBackend
Implementation of the AuditBackend interface using MongoDB persistence.
Since:
9.1
  • Field Details

    • SEQ_NAME

      public static final String SEQ_NAME
      See Also:
    • collection

      protected final com.mongodb.client.MongoCollection<org.bson.Document> collection
    • cursorService

      protected final CursorService<com.mongodb.client.MongoCursor<org.bson.Document>,org.bson.Document,String> cursorService
  • Constructor Details

    • MongoDBAuditBackend

      public MongoDBAuditBackend(com.mongodb.client.MongoCollection<org.bson.Document> collection)
      Since:
      2025.0
  • Method Details

    • getAuditCollection

      public com.mongodb.client.MongoCollection<org.bson.Document> getAuditCollection()
      Returns:
      the MongoCollection configured with audit settings.
    • initUIDSequencer

      protected static void initUIDSequencer(com.mongodb.client.MongoCollection<org.bson.Document> collection)
      Ensures the audit sequence returns an UID greater or equal than the maximum log entry id.
    • queryLogs

      public LogEntryList queryLogs(QueryBuilder query)
      Description copied from interface: AuditBackend
      Returns the logs given a collection of predicates and a default sort.
      Parameters:
      query - the query builder to fetch log entries
      Returns:
      a list of log entries
    • getLogEntryByID

      public LogEntry getLogEntryByID(long id)
      Description copied from interface: AuditBackend
      Returns a given log entry given its id.
      Parameters:
      id - the log entry identifier
      Returns:
      a LogEntry instance
    • nativeQuery

      public List<?> nativeQuery(String query, Map<String,Object> params, int pageNb, int pageSize)
      Description copied from interface: AuditReader
      Returns a batched list of entries.
      Parameters:
      query - a JPA query language query if implementation of audit backend is JPA (< 7.3 or audit.elasticsearch.enabled=false) and JSON if implementation is Elasticsearch
      params - parameters for the query
      pageNb - the page number (starts at 1)
      pageSize - the number of results per page
    • buildFilter

      public org.bson.conversions.Bson buildFilter(String query, Map<String,Object> params)
    • expandQueryVariables

      public String expandQueryVariables(String query, Object[] params)
    • expandQueryVariables

      public String expandQueryVariables(String query, Map<String,Object> params)
    • addLogEntries

      public void addLogEntries(List<LogEntry> entries)
      Description copied from interface: AuditBackend
      Adds given log entries.
      Parameters:
      entries - the list of log entries.
    • getEventsCount

      public Long getEventsCount(String eventId)
    • append

      public void append(List<String> jsonEntries)
      Specified by:
      append in interface AuditStorage
      Overrides:
      append in class AbstractAuditBackend
    • scroll

      public ScrollResult<String> scroll(QueryBuilder query, int batchSize, int keepAliveSeconds)
      Specified by:
      scroll in interface AuditStorage
      Overrides:
      scroll in class AbstractAuditBackend
    • scroll

      public ScrollResult<String> scroll(String scrollId)
      Specified by:
      scroll in interface AuditStorage
      Overrides:
      scroll in class AbstractAuditBackend
    • clearEntries

      protected void clearEntries()
      Description copied from class: AbstractAuditBackend
      INTERNAL METHOD FOR TESTS, DO NOT USE.
      Overrides:
      clearEntries in class AbstractAuditBackend
    • hasCapability

      public boolean hasCapability(AuditBackend.Capability capability)
      Description copied from interface: AuditBackend
      Checks whether the backend has the capability.