Package org.apache.solr.security
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, SolrMetricProducer
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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
AuditLoggerPlugin.AuditEventFormatter
Interface for formatting the eventstatic class
AuditLoggerPlugin.JSONAuditEventFormatter
Event formatter that returns event as JSON stringstatic interface
AuditLoggerPlugin.MuteRule
-
Nested classes/interfaces inherited from interface org.apache.solr.core.SolrInfoBean
SolrInfoBean.Category, SolrInfoBean.Group
-
-
Field Summary
Fields Modifier and Type Field Description protected List<String>
eventTypes
protected AuditLoggerPlugin.AuditEventFormatter
formatter
protected SolrMetricManager
metricManager
protected com.codahale.metrics.Meter
numErrors
protected com.codahale.metrics.Meter
numLogged
protected com.codahale.metrics.Meter
numLost
protected com.codahale.metrics.Timer
queuedTime
protected String
registryName
protected com.codahale.metrics.Timer
requestTimes
protected com.codahale.metrics.Counter
totalTime
-
Constructor Summary
Constructors Constructor Description AuditLoggerPlugin()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract void
audit(AuditEvent event)
This is the method that each Audit plugin has to implement to do the actual logging.protected void
auditAsync(AuditEvent event)
Enqueues anAuditEvent
to a queue and returns immediately.void
close()
Waits 30s for async queue to drain, then closes executor threads.void
doAudit(AuditEvent event)
Called by the framework, and takes care of metrics tracking and to dispatch to either synchronous or async logging.SolrInfoBean.Category
getCategory()
Category of this componentString
getDescription()
Simple one or two line descriptionSet<String>
getMetricNames()
Modifiable set of metric names that this component reports (default is null, which means none).com.codahale.metrics.MetricRegistry
getMetricRegistry()
An instance ofMetricRegistry
that this component uses for metrics reporting (default is null, which means no registry).String
getName()
Simple common usage name, e.g.void
init(Map<String,Object> pluginConfig)
Initialize the plugin from security.json.void
initializeMetrics(SolrMetricManager manager, String registryName, String tag, String scope)
Initializes metrics specific to this producervoid
run()
Pick next event from async queue and callaudit(AuditEvent)
void
setFormatter(AuditLoggerPlugin.AuditEventFormatter formatter)
boolean
shouldLog(AuditEvent.EventType eventType)
Checks whether this event type should be logged based on "eventTypes" config parameter.protected boolean
shouldMute(AuditEvent event)
Returns true if any of the configured mute rules matches.protected void
waitForQueueToDrain(int timeoutSeconds)
Blocks until the async event queue is drained-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.solr.core.SolrInfoBean
getMetricsSnapshot, registerMetricName
-
-
-
-
Field Detail
-
formatter
protected AuditLoggerPlugin.AuditEventFormatter formatter
-
registryName
protected String registryName
-
metricManager
protected SolrMetricManager metricManager
-
numErrors
protected com.codahale.metrics.Meter numErrors
-
numLost
protected com.codahale.metrics.Meter numLost
-
numLogged
protected com.codahale.metrics.Meter numLogged
-
requestTimes
protected com.codahale.metrics.Timer requestTimes
-
queuedTime
protected com.codahale.metrics.Timer queuedTime
-
totalTime
protected com.codahale.metrics.Counter totalTime
-
-
Method Detail
-
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 anAuditEvent
to a queue and returns immediately. A background thread will pull events from this queue and callaudit(AuditEvent)
- Parameters:
event
- the audit event
-
run
public void run()
Pick next event from async queue and callaudit(AuditEvent)
-
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(SolrMetricManager manager, String registryName, String tag, String scope)
Description copied from interface:SolrMetricProducer
Initializes metrics specific to this producer- Specified by:
initializeMetrics
in interfaceSolrMetricProducer
- Parameters:
manager
- an instance ofSolrMetricManager
registryName
- registry name where metrics are registeredtag
- a symbolic tag that represents this instance of the producer, or a group of related instances that have the same life-cycle. This tag is used when managing life-cycle of some metrics and is set whenSolrMetricProducer.initializeMetrics(SolrMetricManager, String, String, String)
is called.scope
- scope of the metrics (eg. handler name) to separate metrics of
-
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 interfaceSolrInfoBean
-
getDescription
public String getDescription()
Description copied from interface:SolrInfoBean
Simple one or two line description- Specified by:
getDescription
in interfaceSolrInfoBean
-
getCategory
public SolrInfoBean.Category getCategory()
Description copied from interface:SolrInfoBean
Category of this component- Specified by:
getCategory
in interfaceSolrInfoBean
-
getMetricNames
public Set<String> getMetricNames()
Description copied from interface:SolrInfoBean
Modifiable set of metric names that this component reports (default is null, which means none). If not null then this set is used bySolrInfoBean.registerMetricName(String)
to capture what metrics names are reported from this component.NOTE: this set has to allow iteration under modifications.
- Specified by:
getMetricNames
in interfaceSolrInfoBean
-
getMetricRegistry
public com.codahale.metrics.MetricRegistry getMetricRegistry()
Description copied from interface:SolrInfoBean
An instance ofMetricRegistry
that this component uses for metrics reporting (default is null, which means no registry).- Specified by:
getMetricRegistry
in interfaceSolrInfoBean
-
close
public void close() throws IOException
Waits 30s for async queue to drain, then closes executor threads. Subclasses should either callsuper.close()
orwaitForQueueToDrain(int)
before shutting itself down to make sure they can complete logging events in the queue.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- 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
-
-