Search in sources :

Example 6 with AMAccessAuditEventBuilder

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());
    }
}
Also used : JsonValue(org.forgerock.json.JsonValue) AuditException(org.forgerock.audit.AuditException) BufferingRepresentation(org.restlet.representation.BufferingRepresentation) Representation(org.restlet.representation.Representation) AMAccessAuditEventBuilder(org.forgerock.openam.audit.AMAccessAuditEventBuilder)

Example 7 with AMAccessAuditEventBuilder

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

Example 8 with AMAccessAuditEventBuilder

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

Example 9 with AMAccessAuditEventBuilder

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;
}
Also used : InvocationOnMock(org.mockito.invocation.InvocationOnMock) AuditEventFactory(org.forgerock.openam.audit.AuditEventFactory) AMAccessAuditEventBuilder(org.forgerock.openam.audit.AMAccessAuditEventBuilder)

Aggregations

AMAccessAuditEventBuilder (org.forgerock.openam.audit.AMAccessAuditEventBuilder)9 JsonValue (org.forgerock.json.JsonValue)4 AuditEvent (org.forgerock.audit.events.AuditEvent)3 HashSet (java.util.HashSet)1 AuditException (org.forgerock.audit.AuditException)1 AuditEventFactory (org.forgerock.openam.audit.AuditEventFactory)1 AuditRequestContext (org.forgerock.openam.audit.context.AuditRequestContext)1 RadiusResponse (org.forgerock.openam.radius.server.RadiusResponse)1 TransactionId (org.forgerock.services.TransactionId)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 BufferingRepresentation (org.restlet.representation.BufferingRepresentation)1 Representation (org.restlet.representation.Representation)1