Class AuditLoggerPlugin

java.lang.Object
org.apache.solr.security.AuditLoggerPlugin
All Implemented Interfaces:
Closeable, AutoCloseable, Runnable, SolrInfoBean, SolrMetricProducer
Direct Known Subclasses:
MultiDestinationAuditLogger, SolrLogAuditLoggerPlugin

public abstract class AuditLoggerPlugin extends Object implements Closeable, Runnable, SolrInfoBean
Base class for Audit logger plugins. This interface may change in next release and is marked experimental
Since:
8.1.0
WARNING: This API is experimental and might change in incompatible ways in the next release.
  • Field Details

  • Constructor Details

    • AuditLoggerPlugin

      public AuditLoggerPlugin()
  • Method Details

    • init

      public void init(Map<String,Object> pluginConfig)
      Initialize the plugin from security.json. This method removes parameters from config object after consuming, so subclasses can check for config errors.
      Parameters:
      pluginConfig - the config for the plugin
    • audit

      protected abstract void audit(AuditEvent event)
      This is the method that each Audit plugin has to implement to do the actual logging.
      Parameters:
      event - the audit event
    • doAudit

      public final void doAudit(AuditEvent event)
      Called by the framework, and takes care of metrics tracking and to dispatch to either synchronous or async logging.
    • shouldMute

      protected boolean shouldMute(AuditEvent event)
      Returns true if any of the configured mute rules matches. The inner lists are ORed, while rules inside inner lists are ANDed
      Parameters:
      event - the audit event
    • auditAsync

      protected final void auditAsync(AuditEvent event)
      Enqueues an AuditEvent to a queue and returns immediately. A background thread will pull events from this queue and call audit(AuditEvent)
      Parameters:
      event - the audit event
    • run

      public void run()
      Pick next event from async queue and call audit(AuditEvent)
      Specified by:
      run in interface Runnable
    • shouldLog

      public boolean shouldLog(AuditEvent.EventType eventType)
      Checks whether this event type should be logged based on "eventTypes" config parameter.
      Parameters:
      eventType - the event type to consider
      Returns:
      true if this event type should be logged
    • setFormatter

      public void setFormatter(AuditLoggerPlugin.AuditEventFormatter formatter)
    • initializeMetrics

      public void initializeMetrics(SolrMetricsContext parentContext, io.opentelemetry.api.common.Attributes attributes)
      Description copied from interface: SolrMetricProducer
      Implementation should initialize all metrics to a SolrMetricsContext Registry/MeterProvider with Attributes as the common set of attributes that will be attached to every metric that is initialized for that class/component
      Specified by:
      initializeMetrics in interface SolrMetricProducer
      Parameters:
      parentContext - The registry that the component will initialize metrics to
      attributes - Base set of attributes that will be bound to all metrics for that component
    • getName

      public String getName()
      Description copied from interface: SolrInfoBean
      Simple common usage name, e.g. BasicQueryHandler, or fully qualified class name.
      Specified by:
      getName in interface SolrInfoBean
    • getDescription

      public String getDescription()
      Description copied from interface: SolrInfoBean
      Simple one or two line description
      Specified by:
      getDescription in interface SolrInfoBean
    • getCategory

      public SolrInfoBean.Category getCategory()
      Description copied from interface: SolrInfoBean
      Category of this component
      Specified by:
      getCategory in interface SolrInfoBean
    • getSolrMetricsContext

      public SolrMetricsContext getSolrMetricsContext()
      Description copied from interface: SolrMetricProducer
      Implementations should return the context used in SolrMetricProducer.initializeMetrics(SolrMetricsContext, Attributes) to ensure proper cleanup of metrics at the end of the life-cycle of this component. This should be the child context if one was created, or null if the parent context was used.
      Specified by:
      getSolrMetricsContext in interface SolrMetricProducer
    • close

      public void close() throws IOException
      Waits 30s for async queue to drain, then closes executor threads. Subclasses should either call super.close() or waitForQueueToDrain(int) before shutting itself down to make sure they can complete logging events in the queue.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in interface SolrMetricProducer
      Throws:
      IOException
    • waitForQueueToDrain

      protected void waitForQueueToDrain(int timeoutSeconds)
      Blocks until the async event queue is drained
      Parameters:
      timeoutSeconds - number of seconds to wait for queue to drain