Search in sources :

Example 1 with EventDetailsKey

use of uk.gov.ida.eventemitter.EventDetailsKey in project verify-hub by alphagov.

the class AttributeQueryRequestRunnable method logAndAuditMessageError.

private void logAndAuditMessageError(Exception e, AttributeQueryContainerDto attributeQueryContainerDto, SessionId sessionId) {
    String errorMessage = MatchingServiceRequestExceptionErrorMessageMapper.getErrorMessageForException(e);
    Map<EventDetailsKey, String> details = new HashMap<>();
    UUID errorId = UUID.randomUUID();
    details.put(idp_entity_id, attributeQueryContainerDto.getIssuer());
    details.put(message, errorMessage + e.getMessage());
    details.put(error_id, errorId.toString());
    EventSinkHubEvent hubEvent = new EventSinkHubEvent(serviceInfo, sessionId, EventSinkHubEventConstants.EventTypes.ERROR_EVENT, details);
    eventSinkProxy.logHubEvent(hubEvent);
    eventEmitter.record(hubEvent);
    if (attributeQueryContainerDto.isOnboarding()) {
        LOG.warn(LogFormatter.formatLog(errorId, e.getMessage()), e);
    } else {
        LOG.error(LogFormatter.formatLog(errorId, e.getMessage()), e);
    }
}
Also used : HashMap(java.util.HashMap) EventDetailsKey(uk.gov.ida.eventemitter.EventDetailsKey) UUID(java.util.UUID) EventSinkHubEvent(uk.gov.ida.hub.shared.eventsink.EventSinkHubEvent)

Example 2 with EventDetailsKey

use of uk.gov.ida.eventemitter.EventDetailsKey in project verify-hub by alphagov.

the class HealthCheckEventLogger method logException.

public void logException(ApplicationException exception, String message) {
    LOG.warn(message, exception);
    if (exception.isAudited() || !exception.requiresAuditing()) {
        return;
    }
    Map<EventDetailsKey, String> details = Map.of(downstream_uri, exception.getUri().orElse(URI.create("uri-not-present")).toASCIIString(), EventDetailsKey.message, exception.getMessage());
    EventSinkHubEvent hubEvent = new EventSinkHubEvent(serviceInfo, NO_SESSION_CONTEXT_IN_ERROR, ERROR_EVENT, details);
    eventSinkProxy.logHubEvent(hubEvent);
    eventEmitter.record(hubEvent);
}
Also used : EventDetailsKey(uk.gov.ida.eventemitter.EventDetailsKey) EventSinkHubEvent(uk.gov.ida.hub.shared.eventsink.EventSinkHubEvent)

Example 3 with EventDetailsKey

use of uk.gov.ida.eventemitter.EventDetailsKey in project verify-hub by alphagov.

the class HubEventLogger method logRequestFromHub.

public void logRequestFromHub(SessionId sessionId, String transactionEntityId) {
    Map<EventDetailsKey, String> details = new HashMap<>();
    details.put(hub_event_type, RECEIVED_AUTHN_REQUEST_FROM_HUB);
    details.put(transaction_entity_id, transactionEntityId);
    EventSinkHubEvent eventSinkHubEvent = new EventSinkHubEvent(serviceInfo, sessionId, HUB_EVENT, details);
    eventSinkProxy.logHubEvent(eventSinkHubEvent);
    eventEmitter.record(eventSinkHubEvent);
}
Also used : HashMap(java.util.HashMap) EventDetailsKey(uk.gov.ida.eventemitter.EventDetailsKey) EventSinkHubEvent(uk.gov.ida.hub.policy.domain.EventSinkHubEvent)

Example 4 with EventDetailsKey

use of uk.gov.ida.eventemitter.EventDetailsKey in project verify-hub by alphagov.

the class HubEventLogger method logSessionTimeoutEvent.

public void logSessionTimeoutEvent(SessionId sessionId, DateTime sessionExpiryTimestamp, String transactionEntityId, String requestId) {
    Map<EventDetailsKey, String> details = new HashMap<>();
    details.put(session_event_type, SESSION_TIMEOUT);
    details.put(session_expiry_time, sessionExpiryTimestamp.toString());
    details.put(transaction_entity_id, transactionEntityId);
    details.put(request_id, requestId);
    EventSinkHubEvent eventSinkHubEvent = new EventSinkHubEvent(serviceInfo, sessionId, SESSION_EVENT, details);
    eventSinkProxy.logHubEvent(eventSinkHubEvent);
    eventEmitter.record(eventSinkHubEvent);
}
Also used : HashMap(java.util.HashMap) EventDetailsKey(uk.gov.ida.eventemitter.EventDetailsKey) EventSinkHubEvent(uk.gov.ida.hub.policy.domain.EventSinkHubEvent)

Example 5 with EventDetailsKey

use of uk.gov.ida.eventemitter.EventDetailsKey in project verify-hub by alphagov.

the class HealthCheckEventLoggerTest method shouldLogToEventSinkIfTheExceptionIsUnaudited.

@Test
public void shouldLogToEventSinkIfTheExceptionIsUnaudited() {
    URI uri = URI.create("uri-geller");
    ApplicationException unauditedException = ApplicationException.createUnauditedException(ExceptionType.INVALID_SAML, UUID.randomUUID(), uri);
    Map<EventDetailsKey, String> details = Map.of(downstream_uri, unauditedException.getUri().orElse(URI.create("uri-not-present")).toASCIIString(), message, unauditedException.getMessage());
    EventSinkHubEvent event = new EventSinkHubEvent(serviceInfo, NO_SESSION_CONTEXT_IN_ERROR, ERROR_EVENT, details);
    eventLogger.logException(unauditedException, "test error message");
    ArgumentCaptor<EventSinkHubEvent> eventSinkCaptor = ArgumentCaptor.forClass(EventSinkHubEvent.class);
    ArgumentCaptor<EventSinkHubEvent> eventEmitterCaptor = ArgumentCaptor.forClass(EventSinkHubEvent.class);
    verify(eventSinkProxy, times(1)).logHubEvent(eventSinkCaptor.capture());
    verify(eventEmitter, times(1)).record(eventEmitterCaptor.capture());
    assertThat(event).isEqualToComparingOnlyGivenFields(eventSinkCaptor.getValue(), "originatingService", "sessionId", "eventType", "details");
    assertThat(event).isEqualToComparingOnlyGivenFields(eventEmitterCaptor.getValue(), "originatingService", "sessionId", "eventType", "details");
}
Also used : ApplicationException(uk.gov.ida.exceptions.ApplicationException) EventDetailsKey(uk.gov.ida.eventemitter.EventDetailsKey) URI(java.net.URI) EventSinkHubEvent(uk.gov.ida.hub.shared.eventsink.EventSinkHubEvent) Test(org.junit.jupiter.api.Test)

Aggregations

EventDetailsKey (uk.gov.ida.eventemitter.EventDetailsKey)6 HashMap (java.util.HashMap)4 EventSinkHubEvent (uk.gov.ida.hub.shared.eventsink.EventSinkHubEvent)4 EventSinkHubEvent (uk.gov.ida.hub.policy.domain.EventSinkHubEvent)2 URI (java.net.URI)1 UUID (java.util.UUID)1 Test (org.junit.jupiter.api.Test)1 ApplicationException (uk.gov.ida.exceptions.ApplicationException)1