CommonAuditAccessLogPublisher.java revision e433824f46514e6ed863eb6b95c70038331c8c24
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at legal-notices/CDDLv1_0.txt.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information:
* Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*
*
* Copyright 2015 ForgeRock AS
*/
/**
* Publishes access events to Common Audit.
*
* @param <T> the type of configuration
*/
abstract class CommonAuditAccessLogPublisher<T extends AccessLogPublisherCfg>
extends AbstractTextAccessLogPublisher<T>
implements CommonAuditLogPublisher
{
/** Transaction id used when the incoming request does not contain a transaction id. */
/** Audit service handler. */
private RequestHandler requestHandler;
/** Current configuration for this publisher. */
private T config;
{
this.requestHandler = handler;
}
abstract boolean shouldLogControlOids();
T getConfig()
{
return config;
}
{
}
{
}
public boolean isConfigurationAcceptable(final T configuration, final List<LocalizableMessage> unacceptableReasons)
{
}
{
{
return;
}
}
{
if (!isResponseLoggable(addOperation))
{
return;
}
}
{
if (!isResponseLoggable(bindOperation))
{
return;
}
if (failureMessage != null)
{
// this code path is mutually exclusive with the if result code is success
// down below
{ // SASL bind and we have successfully found a user entry for auth
}
else
{ // SASL bind failed to find user entry for auth or simple bind
}
}
{
// this code path is mutually exclusive with the if failure message exist
// just above
{
{
{
}
}
else
{
}
}
}
}
{
{
return;
}
}
private void appendProxiedAuthorizationDNIfNeeded(OpenDJAccessAuditEventBuilder<?> builder, DN proxiedAuthorizationDN)
{
if (proxiedAuthorizationDN != null)
{
}
}
{
{
return;
}
.response(ResponseStatus.SUCCESSFUL, String.valueOf(ResultCode.SUCCESS.intValue()), 0, TimeUnit.MILLISECONDS)
}
{
{
return;
}
}
public void logDisconnect(final ClientConnection clientConnection, final DisconnectReason disconnectReason,
final LocalizableMessage message)
{
{
return;
}
.response(ResponseStatus.SUCCESSFUL, String.valueOf(ResultCode.SUCCESS.intValue()), 0, TimeUnit.MILLISECONDS)
}
{
{
return;
}
{
if (extOpHandler != null)
{
}
}
}
{
{
return;
}
}
{
{
return;
}
}
{
{
return;
}
}
{
if (!isRequestLoggable(unbindOperation))
{
return;
}
}
protected void close0()
{
// nothing to do because closing is managed in the CommonAudit class
}
final OpenDJAccessAuditEventBuilder<?> builder)
{
}
private void appendAddRequest(final AddOperation addOperation, OpenDJAccessAuditEventBuilder<?> builder)
{
}
private void appendBindRequest(final BindOperation bindOperation, final OpenDJAccessAuditEventBuilder<?> builder)
{
bindOperation.getAuthenticationType().toString() : "SASL mechanism=" + bindOperation.getSASLMechanism();
}
final OpenDJAccessAuditEventBuilder<?> builder)
{
}
final OpenDJAccessAuditEventBuilder<?> builder)
{
}
final OpenDJAccessAuditEventBuilder<?> builder)
{
if (extOpHandler != null)
{
}
}
final OpenDJAccessAuditEventBuilder<?> builder)
{
}
final OpenDJAccessAuditEventBuilder<?> builder)
{
}
{
{
}
else
{
builder.response(status, String.valueOf(resultCode), executionTime.getFirst(), executionTime.getSecond());
}
return builder;
}
/** Returns an event builder with all common fields filled. */
private OpenDJAccessAuditEventBuilder<?> getEventBuilder(final Operation operation, final String opType)
{
if (shouldLogControlOids())
{
}
return builder;
}
{
if (transactionId == null)
{
// use a default value because transaction id has no usage in this case
}
return transactionId;
}
{
{
{
try
{
}
catch (DirectoryException e)
{
logger.error(ERR_COMMON_AUDIT_INVALID_TRANSACTION_ID.get(StaticUtils.stackTraceToSingleLineString(e)));
}
}
}
return null;
}
{
// if not configured for nanos, use millis
return etime <= -1 ?
}
/** Sends an JSON-encoded event to the audit service. */
{
{
public void handleException(ResourceException e)
{
logger.error(ERR_COMMON_AUDIT_UNABLE_TO_PROCESS_LOG_EVENT.get(StaticUtils.stackTraceToSingleLineString(e)));
}
})
{
public void handleRuntimeException(RuntimeException e)
{
logger.error(ERR_COMMON_AUDIT_UNABLE_TO_PROCESS_LOG_EVENT.get(StaticUtils.stackTraceToSingleLineString(e)));
}
});
}
}