public class ElasticsearchAuditEventHandler extends AuditEventHandlerBase implements BatchConsumer
AuditEventHandler
for Elasticsearch.eventTopicsMetaData
Constructor and Description |
---|
ElasticsearchAuditEventHandler(ElasticsearchAuditEventHandlerConfiguration configuration,
EventTopicsMetaData eventTopicsMetaData,
Client client)
Create a new
ElasticsearchAuditEventHandler instance. |
Modifier and Type | Method and Description |
---|---|
void |
addToBatch(String topic,
JsonValue event,
StringBuilder payload)
Adds an audit event to an Elasticsearch Bulk API payload.
|
protected String |
buildBaseUri()
Builds an Elasticsearch API base URI.
|
protected String |
buildBasicAuthHeaderValue()
Builds a basic authentication header-value, if username and password are provided in configuration.
|
protected String |
buildBulkUri()
Builds an Elasticsearch API URI for Bulk API.
|
protected String |
buildEventUri(String topic,
String eventId)
Builds an Elasticsearch API URI for operating on a single event (e.g., index, get, etc.).
|
protected String |
buildSearchUri(String topic,
int pageSize,
int offset)
Builds an Elasticsearch API URI for Search API.
|
Promise<Void,BatchException> |
publishBatch(String payload)
Publishes a Bulk API
payload to Elasticsearch.
|
Promise<ResourceResponse,ResourceException> |
publishEvent(Context context,
String topic,
JsonValue event)
Publishes an event to the provided topic.
|
protected Promise<ResourceResponse,ResourceException> |
publishSingleEvent(String topic,
JsonValue event)
Publishes a single event to the provided topic.
|
Promise<QueryResponse,ResourceException> |
queryEvents(Context context,
String topic,
QueryRequest query,
QueryResourceHandler handler)
Queries the Elasticsearch
Search API for
audit events.
|
Promise<ResourceResponse,ResourceException> |
readEvent(Context context,
String topic,
String resourceId)
Reads an event with the provided resource id from the provided topic.
|
protected static ResourceException |
resourceException(String indexName,
String topic,
String resourceId,
Response response)
Gets an
Exception Promise containing an Elasticsearch HTTP response status and payload. |
void |
shutdown()
Instruct this object to flush any buffers and close any open file handles or network connections.
|
void |
startup()
Instruct this object that it is safe to initialize file handles and network connections.
|
getHandledTopics, getName, handleAction, isEnabled
public ElasticsearchAuditEventHandler(ElasticsearchAuditEventHandlerConfiguration configuration, EventTopicsMetaData eventTopicsMetaData, Client client)
ElasticsearchAuditEventHandler
instance.configuration
- Configuration parameters that can be adjusted by system administrators.eventTopicsMetaData
- Meta-data for all audit event topics.client
- HTTP client or null
to use default client.public void startup() throws ResourceException
AuditEventHandler
Reconfiguration of the AuditService
and its handlers is achieved by replacing
rather than modifying the existing objects. Therefore, it's essential that the replacements do not perform
any I/O that would interfere with the operation of the objects they are replacing until the old objects are
shutdown. For example, when shutting down an old instance of a file-based AuditEventHandler, the old instance
may need to flush buffers, apply file rotation or retention policies, or even add line or block signatures
as part of tamper evident logging. Any of these operations could be broken if two handler instances are
operating on the same set of files simultaneously.
startup
in interface AuditEventHandler
ResourceException
- if starting the AuditEventHandler failspublic void shutdown() throws ResourceException
AuditEventHandler
shutdown
in interface AuditEventHandler
ResourceException
- if closing the AuditEventHandler failspublic Promise<QueryResponse,ResourceException> queryEvents(Context context, String topic, QueryRequest query, QueryResourceHandler handler)
queryEvents
in interface AuditEventHandler
context
- The context chain that initiated the event.topic
- The topic on which query is performed.query
- The request with the query.handler
- The handler to process responses for the query.public Promise<ResourceResponse,ResourceException> readEvent(Context context, String topic, String resourceId)
AuditEventHandler
readEvent
in interface AuditEventHandler
context
- The context chain that initiated the event.topic
- The topic where event is read.resourceId
- The identifier of the event.public Promise<ResourceResponse,ResourceException> publishEvent(Context context, String topic, JsonValue event)
AuditEventHandler
publishEvent
in interface AuditEventHandler
context
- The context chain that initiated the event.topic
- The topic where to publish the event.event
- The event to publish.protected Promise<ResourceResponse,ResourceException> publishSingleEvent(String topic, JsonValue event)
topic
- The topic where to publish the event.event
- The event to publish.public void addToBatch(String topic, JsonValue event, StringBuilder payload) throws BatchException
addToBatch
in interface BatchConsumer
topic
- Event topicevent
- Event JSON payloadpayload
- Elasticsearch Bulk API payloadBatchException
- indicates failure to add-to-batchpublic Promise<Void,BatchException> publishBatch(String payload)
publishBatch
in interface BatchConsumer
payload
- Elasticsearch Bulk API payloadprotected String buildBasicAuthHeaderValue()
null
if not configuredprotected String buildEventUri(String topic, String eventId)
topic
- Audit topiceventId
- Event IDprotected String buildBulkUri()
protected String buildSearchUri(String topic, int pageSize, int offset)
topic
- The audit topic to search.pageSize
- The number of results to return.offset
- The number of results to skip.protected String buildBaseUri()
http[s]://host:port/indexName
protected static ResourceException resourceException(String indexName, String topic, String resourceId, Response response)
Exception
Promise
containing an Elasticsearch HTTP response status and payload.indexName
- Index nametopic
- Event topicresourceId
- Event IDresponse
- HTTP responseException
Promise
Copyright 2011-2017 ForgeRock AS.