public class AuditServiceProxy extends Object implements AuditService
The proxied AuditService can be swapped by calling setDelegate(AuditService)
.
Thread-safety is achieved by blocking proxied calls until the old AuditService has flushed all buffers and closed any open file or network connections.
Modifier and Type | Field and Description |
---|---|
static String |
ACTION_PARAM_TARGET_HANDLER
Parameter that may be used when using an action, to provide the name of the handler to use as a target.
|
Constructor and Description |
---|
AuditServiceProxy(AuditService delegate)
Create a new
AuditServiceProxy . |
Modifier and Type | Method and Description |
---|---|
AuditServiceConfiguration |
getConfig()
Gets the AuditService configuration.
|
Set<String> |
getKnownTopics()
Returns the set of event topics (schemas) that the
AuditService understands. |
AuditEventHandler |
getRegisteredHandler(String handlerName)
Returns the registered handler corresponding to provided name.
|
Collection<AuditEventHandler> |
getRegisteredHandlers()
Returns the registered handlers.
|
Promise<ActionResponse,ResourceException> |
handleAction(Context context,
ActionRequest request)
Audit service may support actions on the service itself or on handlers.
|
Promise<ResourceResponse,ResourceException> |
handleCreate(Context context,
CreateRequest request)
Propagates the audit event to the
AuditEventHandler objects that have been registered
for the audit event topic. |
Promise<ResourceResponse,ResourceException> |
handleDelete(Context context,
DeleteRequest request)
Audit service does not support changing audit entries.
|
Promise<ResourceResponse,ResourceException> |
handlePatch(Context context,
PatchRequest request)
Audit service does not support changing audit entries.
|
Promise<QueryResponse,ResourceException> |
handleQuery(Context context,
QueryRequest request,
QueryResourceHandler handler)
Performs the query on the specified object and returns the associated results.
|
Promise<ResourceResponse,ResourceException> |
handleRead(Context context,
ReadRequest request)
Gets an object from the audit logs by identifier.
|
Promise<ResourceResponse,ResourceException> |
handleUpdate(Context context,
UpdateRequest request)
Audit service does not support changing audit entries.
|
boolean |
isAuditing(String topic)
Returns whether or not events of the specified topic will be handled.
|
boolean |
isRunning()
Returns true if this object is running.
|
protected void |
obtainReadLock()
Obtain the read lock or block until it becomes available.
|
protected void |
obtainWriteLock()
Obtain the write lock or block until it becomes available.
|
protected void |
releaseReadLock()
Release the read lock.
|
protected void |
releaseWriteLock()
Release the write lock.
|
void |
setDelegate(AuditService newDelegate)
Sets the AuditService this object proxies.
|
void |
shutdown()
Closes this
AuditService and all its AuditEventHandler s. |
void |
startup()
Allows this
AuditService and all its AuditEventHandler s to perform any initialization that
would be unsafe to do if any other instance of the AuditService were still running. |
public static final String ACTION_PARAM_TARGET_HANDLER
public AuditServiceProxy(AuditService delegate)
AuditServiceProxy
.delegate
- The AuditService
that this object should proxy.public void setDelegate(AuditService newDelegate) throws ServiceUnavailableException
Thread-safety is achieved by blocking proxied calls until the old AuditService has flushed all buffers and closed any open file or network connections.
newDelegate
- A new AuditService instance with updated configuration.ServiceUnavailableException
- If the new audit service cannot be started.public Promise<ResourceResponse,ResourceException> handleRead(Context context, ReadRequest request)
AuditService
The object will contain metadata properties, including object identifier _id
,
and object version _rev
to enable optimistic concurrency
If this AuditService
has been closed, the returned promise will resolve to a
ServiceUnavailableException
.
Promise
that will be
completed when the resource has been read.
Read expects failure exceptions as follows:
ForbiddenException
if access to the resource is forbidden.
NotSupportedException
if the requested functionality is not
implemented/supported
BadRequestException
if the passed identifier or filter is
invalid
NotFoundException
if the specified resource could not be
found.
handleRead
in interface AuditService
handleRead
in interface RequestHandler
context
- The request server context, such as associated principal.request
- The read request.Promise
containing the result of the operation.public Promise<ResourceResponse,ResourceException> handleCreate(Context context, CreateRequest request)
AuditService
AuditEventHandler
objects that have been registered
for the audit event topic.
This method sets the _id
property to the assigned identifier for the object,
and the _rev
property to the revised object version (For optimistic concurrency).
If this AuditService
has been closed, the returned promise will resolve to a
ServiceUnavailableException
.
Promise
that will be
completed when the resource has been added.
Create expects failure exceptions as follows:
ForbiddenException
if access to the resource is forbidden.
NotSupportedException
if the requested functionality is not
implemented/supported
PreconditionFailedException
if a resource with the same ID
already exists
BadRequestException
if the passed identifier or value is
invalid
NotFoundException
if the specified id could not be resolved,
for example when an intermediate resource in the hierarchy does not
exist.
handleCreate
in interface AuditService
handleCreate
in interface RequestHandler
context
- The request server context, such as associated principal.request
- The create request.Promise
containing the result of the operation.public Promise<ResourceResponse,ResourceException> handleUpdate(Context context, UpdateRequest request)
AuditService
The returned promise will resolve to a NotSupportedException
.
handleUpdate
in interface AuditService
handleUpdate
in interface RequestHandler
context
- The request server context, such as associated principal.request
- The update request.Promise
containing the result of the operation.public Promise<ResourceResponse,ResourceException> handleDelete(Context context, DeleteRequest request)
AuditService
The returned promise will resolve to a NotSupportedException
.
handleDelete
in interface AuditService
handleDelete
in interface RequestHandler
context
- The request server context, such as associated principal.request
- The delete request.Promise
containing the result of the operation.public Promise<ResourceResponse,ResourceException> handlePatch(Context context, PatchRequest request)
AuditService
The returned promise will resolve to a NotSupportedException
.
handlePatch
in interface AuditService
handlePatch
in interface RequestHandler
context
- The request server context, such as associated principal.request
- The patch request.Promise
containing the result of the operation.public Promise<QueryResponse,ResourceException> handleQuery(Context context, QueryRequest request, QueryResourceHandler handler)
AuditService
Queries are parametric; a set of named parameters is provided as the query criteria. The query result is a JSON object structure composed of basic Java types.
The returned map is structured as follow:QueryConstants
defines the map keys, including the result records (QUERY_RESULT)
If this AuditService
has been closed, the returned promise will resolve to a
ServiceUnavailableException
.
Promise
that will be completed when the
search has completed.
Implementations must invoke
QueryResourceHandler.handleResource(ResourceResponse)
for each resource
which matches the query criteria. Once all matching resources have been
returned implementations are required to return either a
QueryResponse
if the query has completed successfully, or
ResourceException
if the query did not complete successfully
(even if some matching resources were returned).
Query expects failure exceptions as follows:
ForbiddenException
if access to the resource is forbidden
NotSupportedException
if the requested functionality is not
implemented/supported
BadRequestException
if the passed identifier, parameters or
filter is invalid
NotFoundException
if the specified resource could not be
found
handleQuery
in interface AuditService
handleQuery
in interface RequestHandler
context
- The request server context, such as associated principal.request
- The query request.handler
- The query resource handler to be notified for each matching
resource.Promise
containing the result of the operation.public Promise<ActionResponse,ResourceException> handleAction(Context context, ActionRequest request)
AuditService
One of the following paths format is expected:
[path-to-audit-service]?_action=XXX : call a global action on audit service
[path-to-audit-service/[topic]?_action=XXX : call an action on audit service and a single topic
[path-to-audit-service]?_action=XXX&handler=HHH : call on action on a specific handler
[path-to-audit-service/[topic]?_action=XXX&handler=HHH : call on action on a specific handler and topic
handleAction
in interface AuditService
handleAction
in interface RequestHandler
context
- The request server context, such as associated principal.request
- The action request.Promise
containing the result of the operation.public AuditServiceConfiguration getConfig() throws ServiceUnavailableException
AuditService
getConfig
in interface AuditService
ServiceUnavailableException
- if the AuditService has been closed.public AuditEventHandler getRegisteredHandler(String handlerName) throws ServiceUnavailableException
AuditService
getRegisteredHandler
in interface AuditService
handlerName
- Name of the registered handler to retrieve.null
if no handler with the provided name
was registered to the service.ServiceUnavailableException
- if the AuditService has been closed.public Collection<AuditEventHandler> getRegisteredHandlers() throws ServiceUnavailableException
AuditService
getRegisteredHandlers
in interface AuditService
ServiceUnavailableException
- if the AuditService has been closed.public boolean isAuditing(String topic) throws ServiceUnavailableException
AuditService
isAuditing
in interface AuditService
topic
- Identifies a category of events to which handlers may or may not be registered.ServiceUnavailableException
- if the AuditService has been closed.public Set<String> getKnownTopics() throws ServiceUnavailableException
AuditService
AuditService
understands.getKnownTopics
in interface AuditService
ServiceUnavailableException
- if the AuditService has been closed.public void shutdown()
AuditService
AuditService
and all its AuditEventHandler
s.
This ensures that any buffered are flushed and all file handles / network connections are closed.
Once closed
, any further calls to this AuditService
will throw, or return a promise
that will resolve to, ServiceUnavailableException
.
shutdown
in interface AuditService
public void startup() throws ServiceUnavailableException
AuditService
AuditService
and all its AuditEventHandler
s to perform any initialization that
would be unsafe to do if any other instance of the AuditService
were still running.startup
in interface AuditService
ServiceUnavailableException
- if the AuditService has been closed.public boolean isRunning()
AuditService
This object will be in a 'running' state if AuditService.startup()
completed successfully and AuditService.shutdown()
has not yet been called.
isRunning
in interface AuditService
protected final void obtainReadLock()
IllegalStateException
- If the current thread already holds the write lock.protected final void releaseReadLock()
protected final void obtainWriteLock()
protected final void releaseWriteLock()
Copyright 2011-2017 ForgeRock AS.