use of org.forgerock.openam.audit.AMAccessAuditEventBuilder in project OpenAM by OpenRock.
the class AbstractRestletAccessAuditFilter method auditAccessSuccess.
private void auditAccessSuccess(Request request, Response response) {
String realm = getRealmFromRequest(request);
if (auditEventPublisher.isAuditing(realm, ACCESS_TOPIC, EventName.AM_ACCESS_OUTCOME)) {
long endTime = System.currentTimeMillis();
long elapsedTime = endTime - request.getDate().getTime();
final Representation entity = response.getEntity();
AMAccessAuditEventBuilder builder = auditEventFactory.accessEvent(realm).timestamp(endTime).transactionId(AuditRequestContext.getTransactionIdValue()).eventName(EventName.AM_ACCESS_OUTCOME).component(component).userId(getUserIdForAccessOutcome(request, response)).trackingIds(getTrackingIdsForAccessOutcome(request, response));
JsonValue detail = null;
if (responseDetailCreator != null) {
try {
detail = responseDetailCreator.apply(entity);
} catch (AuditException e) {
debug.warning("An error occurred when fetching response body details for audit", e);
}
}
if (detail == null) {
builder.response(SUCCESSFUL, "", elapsedTime, MILLISECONDS);
} else {
builder.responseWithDetail(SUCCESSFUL, "", elapsedTime, MILLISECONDS, detail);
}
addHttpData(request, builder);
auditEventPublisher.tryPublish(ACCESS_TOPIC, builder.toEvent());
}
}
use of org.forgerock.openam.audit.AMAccessAuditEventBuilder in project OpenAM by OpenRock.
the class CrestAuditor method auditAccessFailure.
/**
* Publishes an event with details of the failed CREST operation, if the 'access' topic is audited.
* <p/>
* Any exception that occurs while trying to publish the audit event will be
* captured in the debug logs but otherwise ignored.
*
* @param resultCode The HTTP result code relating to the failure.
* @param message A human-readable description of the error that occurred.
*/
void auditAccessFailure(int resultCode, String message) {
if (auditEventPublisher.isAuditing(realm, ACCESS_TOPIC, EventName.AM_ACCESS_OUTCOME)) {
final long endTime = System.currentTimeMillis();
final long elapsedTime = endTime - startTime;
JsonValue detail = json(object(field(ACCESS_RESPONSE_DETAIL_REASON, message)));
AMAccessAuditEventBuilder builder = auditEventFactory.accessEvent(realm).forHttpRequest(context, request).timestamp(endTime).transactionId(AuditRequestContext.getTransactionIdValue()).eventName(EventName.AM_ACCESS_OUTCOME).component(component).responseWithDetail(FAILED, Integer.toString(resultCode), elapsedTime, MILLISECONDS, detail);
addSessionDetailsFromSSOTokenContext(builder, context);
if (ipAddressHeaderPropertyIsSet()) {
setClientFromHttpContextHeaderIfExists(builder, context);
}
AuditEvent auditEvent = builder.toEvent();
postProcessEvent(auditEvent);
auditEventPublisher.tryPublish(ACCESS_TOPIC, auditEvent);
}
}
use of org.forgerock.openam.audit.AMAccessAuditEventBuilder in project OpenAM by OpenRock.
the class CrestAuditor method auditAccessSuccess.
/**
* Publishes an event with details of the successfully completed CREST operation, if the 'access' topic is audited.
* Provides additional detail.
* <p/>
* Any exception that occurs while trying to publish the audit event will be
* captured in the debug logs but otherwise ignored.
*
* @param responseDetail Additional details relating to the response (e.g. failure description or summary
* of the payload). Can be null if there are no additional details.
*/
void auditAccessSuccess(JsonValue responseDetail) {
if (auditEventPublisher.isAuditing(realm, ACCESS_TOPIC, EventName.AM_ACCESS_OUTCOME)) {
final long endTime = System.currentTimeMillis();
final long elapsedTime = endTime - startTime;
AMAccessAuditEventBuilder builder = auditEventFactory.accessEvent(realm).forHttpRequest(context, request).timestamp(endTime).transactionId(AuditRequestContext.getTransactionIdValue()).eventName(EventName.AM_ACCESS_OUTCOME).component(component);
if (responseDetail == null) {
builder.response(SUCCESSFUL, "", elapsedTime, MILLISECONDS);
} else {
builder.responseWithDetail(SUCCESSFUL, "", elapsedTime, MILLISECONDS, responseDetail);
}
addSessionDetailsFromSSOTokenContext(builder, context);
if (ipAddressHeaderPropertyIsSet()) {
setClientFromHttpContextHeaderIfExists(builder, context);
}
AuditEvent auditEvent = builder.toEvent();
postProcessEvent(auditEvent);
auditEventPublisher.tryPublish(ACCESS_TOPIC, auditEvent);
}
}
use of org.forgerock.openam.audit.AMAccessAuditEventBuilder in project OpenAM by OpenRock.
the class AuditTestUtils method mockAuditEventFactory.
public static AuditEventFactory mockAuditEventFactory() {
AuditEventFactory auditEventFactory = mock(AuditEventFactory.class);
when(auditEventFactory.accessEvent(NO_REALM)).thenAnswer(new Answer<AMAccessAuditEventBuilder>() {
@Override
public AMAccessAuditEventBuilder answer(InvocationOnMock invocation) throws Throwable {
return new AMAccessAuditEventBuilder();
}
});
return auditEventFactory;
}
Aggregations