Search in sources :

Example 1 with EventSinkHubEvent

use of uk.gov.ida.hub.shared.eventsink.EventSinkHubEvent in project verify-hub by alphagov.

the class ExternalCommunicationEventLogger method logExternalCommunicationEvent.

private void logExternalCommunicationEvent(String messageId, SessionId sessionId, URI targetUrl, String externalCommunicationType, IncludeIpAddressState includeIpAddressState, Map<EventDetailsKey, String> details) {
    details.put(external_communication_type, externalCommunicationType);
    details.put(message_id, messageId);
    details.put(external_endpoint, targetUrl.toString());
    if (includeIpAddressState == IncludeIpAddressState.WITH_RESOLVED_IP_ADDRESS) {
        details.put(external_ip_address, ipAddressResolver.lookupIpAddress(targetUrl));
    }
    final EventSinkHubEvent hubEvent = new EventSinkHubEvent(serviceInfo, sessionId, EXTERNAL_COMMUNICATION_EVENT, details);
    eventSinkProxy.logHubEvent(hubEvent);
    eventEmitter.record(hubEvent);
}
Also used : EventSinkHubEvent(uk.gov.ida.hub.shared.eventsink.EventSinkHubEvent)

Example 2 with EventSinkHubEvent

use of uk.gov.ida.hub.shared.eventsink.EventSinkHubEvent 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 3 with EventSinkHubEvent

use of uk.gov.ida.hub.shared.eventsink.EventSinkHubEvent 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 4 with EventSinkHubEvent

use of uk.gov.ida.hub.shared.eventsink.EventSinkHubEvent in project verify-hub by alphagov.

the class ExternalCommunicationEventLoggerTest method logAuthenticationRequest_shouldPassHubEventToEventSinkProxy.

@Test
public void logAuthenticationRequest_shouldPassHubEventToEventSinkProxy() {
    externalCommunicationEventLogger.logIdpAuthnRequest(MESSAGE_ID, SESSION_ID, ENDPOINT_URL, PRINCIPAL_IP_ADDRESS_AS_SEEN_BY_THE_HUB);
    final EventSinkHubEvent expectedEvent = new EventSinkHubEvent(SERVICE_INFO, SESSION_ID, EXTERNAL_COMMUNICATION_EVENT, Map.of(external_communication_type, AUTHN_REQUEST, message_id, MESSAGE_ID, external_endpoint, ENDPOINT_URL.toString(), principal_ip_address_as_seen_by_hub, PRINCIPAL_IP_ADDRESS_AS_SEEN_BY_THE_HUB));
    verify(eventSinkProxy).logHubEvent(argThat(new EventMatching(expectedEvent)));
    verify(eventEmitter).record(argThat(new EventMatching(expectedEvent)));
}
Also used : EventSinkHubEvent(uk.gov.ida.hub.shared.eventsink.EventSinkHubEvent) Test(org.junit.jupiter.api.Test)

Example 5 with EventSinkHubEvent

use of uk.gov.ida.hub.shared.eventsink.EventSinkHubEvent in project verify-hub by alphagov.

the class ExternalCommunicationEventLoggerTest method logResponseFromHub_shouldPassHubEventToEventSinkProxy.

@Test
public void logResponseFromHub_shouldPassHubEventToEventSinkProxy() {
    externalCommunicationEventLogger.logResponseFromHub(MESSAGE_ID, SESSION_ID, ENDPOINT_URL, PRINCIPAL_IP_ADDRESS_AS_SEEN_BY_THE_HUB);
    final EventSinkHubEvent expectedEvent = new EventSinkHubEvent(SERVICE_INFO, SESSION_ID, EXTERNAL_COMMUNICATION_EVENT, Map.of(external_communication_type, RESPONSE_FROM_HUB, message_id, MESSAGE_ID, external_endpoint, ENDPOINT_URL.toString(), principal_ip_address_as_seen_by_hub, PRINCIPAL_IP_ADDRESS_AS_SEEN_BY_THE_HUB));
    verify(eventSinkProxy).logHubEvent(argThat(new EventMatching(expectedEvent)));
    verify(eventEmitter).record(argThat(new EventMatching(expectedEvent)));
}
Also used : EventSinkHubEvent(uk.gov.ida.hub.shared.eventsink.EventSinkHubEvent) Test(org.junit.jupiter.api.Test)

Aggregations

EventSinkHubEvent (uk.gov.ida.hub.shared.eventsink.EventSinkHubEvent)18 Test (org.junit.jupiter.api.Test)13 AttributeQueryTimeoutException (uk.gov.ida.hub.samlsoapproxy.exceptions.AttributeQueryTimeoutException)5 EventDetailsKey (uk.gov.ida.eventemitter.EventDetailsKey)4 SamlTransformationErrorException (uk.gov.ida.saml.core.validation.SamlTransformationErrorException)3 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 SAXException (org.xml.sax.SAXException)2 CertificateChainValidationException (uk.gov.ida.common.shared.security.verification.exceptions.CertificateChainValidationException)2 InvalidSamlRequestInAttributeQueryException (uk.gov.ida.hub.samlsoapproxy.exceptions.InvalidSamlRequestInAttributeQueryException)2 URI (java.net.URI)1 UUID (java.util.UUID)1 Element (org.w3c.dom.Element)1 ApplicationException (uk.gov.ida.exceptions.ApplicationException)1