use of org.forgerock.audit.events.AuditEvent in project OpenAM by OpenRock.
the class AuditEventPublisherTest method mockAuditEvent.
private AuditEvent mockAuditEvent(String content) {
AuditEvent auditEvent = mock(AuditEvent.class);
JsonValue jsonValue = mock(JsonValue.class);
given(auditEvent.getValue()).willReturn(jsonValue);
given(jsonValue.toString()).willReturn(content);
return auditEvent;
}
use of org.forgerock.audit.events.AuditEvent in project OpenAM by OpenRock.
the class SAML2Auditor method auditAccessSuccess.
@Override
public void auditAccessSuccess() {
if (!accessAttemptAudited) {
auditAccessAttempt();
}
if (auditEventPublisher.isAuditing(realm, AuditConstants.ACCESS_TOPIC, AuditConstants.EventName.AM_ACCESS_OUTCOME)) {
final long endTime = System.currentTimeMillis();
final long elapsedTime = endTime - startTime;
AuditEvent auditEvent = getDefaultSAML2AccessAuditEventBuilder().timestamp(endTime).eventName(AuditConstants.EventName.AM_ACCESS_OUTCOME).response(SUCCESSFUL, message, elapsedTime, MILLISECONDS).toEvent();
auditEventPublisher.tryPublish(AuditConstants.ACCESS_TOPIC, auditEvent);
}
}
use of org.forgerock.audit.events.AuditEvent 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.audit.events.AuditEvent 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.audit.events.AuditEvent in project OpenAM by OpenRock.
the class AbstractRestletAccessAuditFilterTest method shouldCaptureResponseBodyProperties.
@Test
public void shouldCaptureResponseBodyProperties() throws Exception {
// Given
auditFilter = new RestletAccessAuditFilterTest(restlet, eventPublisher, eventFactory, RestletBodyAuditor.jsonAuditor("fred"), RestletBodyAuditor.jsonAuditor("gary"));
Request request = new Request();
request.setDate(new Date());
Response response = new Response(request);
response.setEntity(new JsonRepresentation((Map<String, Object>) object(field("fred", "v"), field("gary", 7))));
when(eventPublisher.isAuditing(anyString(), anyString(), any(EventName.class))).thenReturn(true);
// When
auditFilter.afterHandle(request, response);
// Then
ArgumentCaptor<AuditEvent> captor = ArgumentCaptor.forClass(AuditEvent.class);
verify(eventPublisher).tryPublish(anyString(), captor.capture());
assertThat(captor.getValue().getValue()).isObject().hasObject("response").hasObject("detail").contains("gary", 7);
}
Aggregations