Class ElasticsearchAuditEventHandler
- java.lang.Object
- 
- org.forgerock.audit.events.handlers.AuditEventHandlerBase
- 
- org.forgerock.audit.handlers.elasticsearch.ElasticsearchAuditEventHandler
 
 
- 
- All Implemented Interfaces:
- AuditEventHandler,- BatchConsumer
 
 public class ElasticsearchAuditEventHandler extends AuditEventHandlerBase implements BatchConsumer AuditEventHandlerfor Elasticsearch.
- 
- 
Field Summary- 
Fields inherited from class org.forgerock.audit.events.handlers.AuditEventHandlerBaseeventTopicsMetaData
 
- 
 - 
Constructor SummaryConstructors Constructor Description ElasticsearchAuditEventHandler(ElasticsearchAuditEventHandlerConfiguration configuration, EventTopicsMetaData eventTopicsMetaData, Client client)Create a newElasticsearchAuditEventHandlerinstance.
 - 
Method SummaryAll Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddToBatch(String topic, JsonValue event, StringBuilder payload)Adds an audit event to an Elasticsearch Bulk API payload.protected StringbuildBaseUri()Builds an Elasticsearch API base URI.protected StringbuildBasicAuthHeaderValue()Builds a basic authentication header-value, if username and password are provided in configuration.protected StringbuildBulkUri()Builds an Elasticsearch API URI for Bulk API.protected StringbuildEventUri(String topic, String eventId)Builds an Elasticsearch API URI for operating on a single event (e.g., index, get, etc.).protected StringbuildSearchUri(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 ResourceExceptionresourceException(String indexName, String topic, String resourceId, Response response)Gets anExceptionPromisecontaining an Elasticsearch HTTP response status and payload.voidshutdown()Instruct this object to flush any buffers and close any open file handles or network connections.voidstartup()Instruct this object that it is safe to initialize file handles and network connections.- 
Methods inherited from class org.forgerock.audit.events.handlers.AuditEventHandlerBasegetHandledTopics, getName, handleAction, isEnabled
 
- 
 
- 
- 
- 
Constructor Detail- 
ElasticsearchAuditEventHandlerpublic ElasticsearchAuditEventHandler(ElasticsearchAuditEventHandlerConfiguration configuration, EventTopicsMetaData eventTopicsMetaData, Client client) Create a newElasticsearchAuditEventHandlerinstance.- Parameters:
- configuration- Configuration parameters that can be adjusted by system administrators.
- eventTopicsMetaData- Meta-data for all audit event topics.
- client- HTTP client or- nullto use default client.
 
 
- 
 - 
Method Detail- 
startuppublic void startup() throws ResourceExceptionDescription copied from interface:AuditEventHandlerInstruct this object that it is safe to initialize file handles and network connections.Reconfiguration of the AuditServiceand 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.- Specified by:
- startupin interface- AuditEventHandler
- Throws:
- ResourceException- if starting the AuditEventHandler fails
 
 - 
shutdownpublic void shutdown() throws ResourceExceptionDescription copied from interface:AuditEventHandlerInstruct this object to flush any buffers and close any open file handles or network connections.- Specified by:
- shutdownin interface- AuditEventHandler
- Throws:
- ResourceException- if closing the AuditEventHandler fails
 
 - 
queryEventspublic Promise<QueryResponse,ResourceException> queryEvents(Context context, String topic, QueryRequest query, QueryResourceHandler handler) Queries the Elasticsearch Search API for audit events. Query some events from the provided topic.- Specified by:
- queryEventsin interface- AuditEventHandler
- Parameters:
- 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.
- Returns:
- a promise with either a response or an exception
 
 - 
readEventpublic Promise<ResourceResponse,ResourceException> readEvent(Context context, String topic, String resourceId) Description copied from interface:AuditEventHandlerReads an event with the provided resource id from the provided topic.- Specified by:
- readEventin interface- AuditEventHandler
- Parameters:
- context- The context chain that initiated the event.
- topic- The topic where event is read.
- resourceId- The identifier of the event.
- Returns:
- a promise with either a response or an exception
 
 - 
publishEventpublic Promise<ResourceResponse,ResourceException> publishEvent(Context context, String topic, JsonValue event) Description copied from interface:AuditEventHandlerPublishes an event to the provided topic.Note for implementors, it is imperative that the supplied eventis not modified in any way as this may cause undesirable behaviour where multiple handlers are configured. If theeventmust be modified, then make a copy of it and work with that.- Specified by:
- publishEventin interface- AuditEventHandler
- Parameters:
- context- The context chain that initiated the event.
- topic- The topic where to publish the event.
- event- The event to publish - which should be considered immutable.
- Returns:
- a promise with either a response or an exception
 
 - 
publishSingleEventprotected Promise<ResourceResponse,ResourceException> publishSingleEvent(String topic, JsonValue event) Publishes a single event to the provided topic.- Parameters:
- topic- The topic where to publish the event.
- event- The event to publish.
- Returns:
- a promise with either a response or an exception
 
 - 
addToBatchpublic void addToBatch(String topic, JsonValue event, StringBuilder payload) throws BatchException Adds an audit event to an Elasticsearch Bulk API payload.- Specified by:
- addToBatchin interface- BatchConsumer
- Parameters:
- topic- Event topic
- event- Event JSON payload
- payload- Elasticsearch Bulk API payload
- Throws:
- BatchException- indicates failure to add-to-batch
 
 - 
publishBatchpublic Promise<Void,BatchException> publishBatch(String payload) Publishes a Bulk API payload to Elasticsearch.- Specified by:
- publishBatchin interface- BatchConsumer
- Parameters:
- payload- Elasticsearch Bulk API payload
- Returns:
- a simple promise encapsulating any potential batch exception
 
 - 
buildBasicAuthHeaderValueprotected String buildBasicAuthHeaderValue() Builds a basic authentication header-value, if username and password are provided in configuration.- Returns:
- Basic authentication header-value or nullif not configured
 
 - 
buildEventUriprotected String buildEventUri(String topic, String eventId) Builds an Elasticsearch API URI for operating on a single event (e.g., index, get, etc.).- Parameters:
- topic- Audit topic
- eventId- Event ID
- Returns:
- URI
 
 - 
buildBulkUriprotected String buildBulkUri() Builds an Elasticsearch API URI for Bulk API.- Returns:
- URI
 
 - 
buildSearchUriprotected String buildSearchUri(String topic, int pageSize, int offset) Builds an Elasticsearch API URI for Search API.- Parameters:
- topic- The audit topic to search.
- pageSize- The number of results to return.
- offset- The number of results to skip.
- Returns:
- The search uri.
 
 - 
buildBaseUriprotected String buildBaseUri() Builds an Elasticsearch API base URI. The format is,http[s]://host:port/indexName - Returns:
- Base URI
 
 - 
resourceExceptionprotected static ResourceException resourceException(String indexName, String topic, String resourceId, Response response) Gets anExceptionPromisecontaining an Elasticsearch HTTP response status and payload.- Parameters:
- indexName- Index name
- topic- Event topic
- resourceId- Event ID
- response- HTTP response
- Returns:
- Exception- Promise
 
 
- 
 
-