Search in sources :

Example 16 with AuditEvent

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;
}
Also used : JsonValue(org.forgerock.json.JsonValue) AuditEvent(org.forgerock.audit.events.AuditEvent)

Example 17 with 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);
    }
}
Also used : AuditEvent(org.forgerock.audit.events.AuditEvent)

Example 18 with 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);
    }
}
Also used : JsonValue(org.forgerock.json.JsonValue) AuditEvent(org.forgerock.audit.events.AuditEvent) AMAccessAuditEventBuilder(org.forgerock.openam.audit.AMAccessAuditEventBuilder)

Example 19 with 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);
    }
}
Also used : AuditEvent(org.forgerock.audit.events.AuditEvent) AMAccessAuditEventBuilder(org.forgerock.openam.audit.AMAccessAuditEventBuilder)

Example 20 with 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);
}
Also used : Response(org.restlet.Response) Request(org.restlet.Request) AuditEvent(org.forgerock.audit.events.AuditEvent) JsonRepresentation(org.restlet.ext.json.JsonRepresentation) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Date(java.util.Date) Test(org.testng.annotations.Test)

Aggregations

AuditEvent (org.forgerock.audit.events.AuditEvent)24 Test (org.testng.annotations.Test)13 JsonValue (org.forgerock.json.JsonValue)6 Map (java.util.Map)3 AMAccessAuditEventBuilder (org.forgerock.openam.audit.AMAccessAuditEventBuilder)3 Context (org.forgerock.services.context.Context)3 Date (java.util.Date)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 Request (org.restlet.Request)2 Response (org.restlet.Response)2 JsonRepresentation (org.restlet.ext.json.JsonRepresentation)2 LogExtracts (com.sun.identity.log.service.AgentLogParser.LogExtracts)1 URL (java.net.URL)1 List (java.util.List)1 AuditServiceBuilder (org.forgerock.audit.AuditServiceBuilder)1 AuditEventHandler (org.forgerock.audit.events.handlers.AuditEventHandler)1 Handler (org.forgerock.http.Handler)1 Request (org.forgerock.http.protocol.Request)1 SessionContext (org.forgerock.http.session.SessionContext)1 AMAuditServiceConfiguration (org.forgerock.openam.audit.configuration.AMAuditServiceConfiguration)1