Search in sources :

Example 6 with AttributeQueryTimeoutException

use of uk.gov.ida.hub.samlsoapproxy.exceptions.AttributeQueryTimeoutException in project verify-hub by alphagov.

the class TimeoutEvaluator method hasAttributeQueryTimedOut.

public void hasAttributeQueryTimedOut(AttributeQueryContainerDto queryContainerDto) {
    DateTime timeout = queryContainerDto.getAttributeQueryClientTimeOut();
    DateTime timeOfCheck = DateTime.now();
    if (timeout.isBefore(timeOfCheck)) {
        Duration duration = new Duration(timeout, timeOfCheck);
        throw new AttributeQueryTimeoutException(MessageFormat.format("Attribute Query timed out by {0} seconds.", duration.getStandardSeconds()));
    }
}
Also used : Duration(org.joda.time.Duration) AttributeQueryTimeoutException(uk.gov.ida.hub.samlsoapproxy.exceptions.AttributeQueryTimeoutException) DateTime(org.joda.time.DateTime)

Example 7 with AttributeQueryTimeoutException

use of uk.gov.ida.hub.samlsoapproxy.exceptions.AttributeQueryTimeoutException in project verify-hub by alphagov.

the class AttributeQueryRequestRunnable method run.

@Override
public void run() {
    counter.dec();
    // see https://github.com/google/guice/wiki/CustomScopes for details on this work
    addSessionIdToLoggingContext(sessionId);
    try {
        timeoutEvaluator.hasAttributeQueryTimedOut(attributeQueryContainerDto);
    } catch (AttributeQueryTimeoutException e) {
        auditAndLogTimeoutException(sessionId, attributeQueryContainerDto, e, "Matching service attribute timed out before even being sent.");
        return;
    }
    try {
        Element response = executeAttributeQueryRequest.execute(sessionId, attributeQueryContainerDto);
        timeoutEvaluator.hasAttributeQueryTimedOut(attributeQueryContainerDto);
        final String base64EncodedSamlResponse = Base64.encodeAsString(XmlUtils.writeToString(response).getBytes());
        hubMatchingServiceResponseReceiverProxy.notifyHubOfAResponseFromMatchingService(sessionId, base64EncodedSamlResponse);
    } catch (AttributeQueryTimeoutException e) {
        auditAndLogTimeoutException(sessionId, attributeQueryContainerDto, e, "Matching service attribute query has timed out, therefore not sending failure notification to saml engine.");
    } catch (Exception e) {
        logAndAuditMessageError(e, attributeQueryContainerDto, sessionId);
        checkTimeoutAndForwardErrorResponse(sessionId, attributeQueryContainerDto);
    }
}
Also used : Element(org.w3c.dom.Element) AttributeQueryTimeoutException(uk.gov.ida.hub.samlsoapproxy.exceptions.AttributeQueryTimeoutException) AttributeQueryTimeoutException(uk.gov.ida.hub.samlsoapproxy.exceptions.AttributeQueryTimeoutException)

Example 8 with AttributeQueryTimeoutException

use of uk.gov.ida.hub.samlsoapproxy.exceptions.AttributeQueryTimeoutException in project verify-hub by alphagov.

the class AttributeQueryRequestRunnableTest method run_shouldSayIfTimeoutWasBeforeSendingMessage.

@Test
public void run_shouldSayIfTimeoutWasBeforeSendingMessage() throws Exception {
    final Element matchingServiceResponse = XmlUtils.convertToElement("<someResponse/>");
    when(executeAttributeQueryRequest.execute(sessionId, attributeQueryContainerDto)).thenReturn(matchingServiceResponse);
    doThrow(new AttributeQueryTimeoutException()).when(timeoutEvaluator).hasAttributeQueryTimedOut(attributeQueryContainerDto);
    attributeQueryRequestRunnable.run();
    final ArgumentCaptor<EventSinkHubEvent> loggedHubEvent = ArgumentCaptor.forClass(EventSinkHubEvent.class);
    final ArgumentCaptor<EventSinkHubEvent> emitterLoggedHubEvent = ArgumentCaptor.forClass(EventSinkHubEvent.class);
    verify(eventSinkProxy).logHubEvent(loggedHubEvent.capture());
    verify(eventEmitter).record(emitterLoggedHubEvent.capture());
    assertThat(loggedHubEvent.getValue().getDetails().get(EventDetailsKey.message)).isEqualTo("Matching service attribute timed out before even being sent.");
    assertThat(emitterLoggedHubEvent.getValue().getDetails().get(EventDetailsKey.message)).isEqualTo("Matching service attribute timed out before even being sent.");
}
Also used : Element(org.w3c.dom.Element) AttributeQueryTimeoutException(uk.gov.ida.hub.samlsoapproxy.exceptions.AttributeQueryTimeoutException) EventSinkHubEvent(uk.gov.ida.eventsink.EventSinkHubEvent) Test(org.junit.Test)

Aggregations

AttributeQueryTimeoutException (uk.gov.ida.hub.samlsoapproxy.exceptions.AttributeQueryTimeoutException)8 Test (org.junit.Test)6 EventSinkHubEvent (uk.gov.ida.eventsink.EventSinkHubEvent)6 Element (org.w3c.dom.Element)4 SessionId (uk.gov.ida.common.SessionId)2 DateTime (org.joda.time.DateTime)1 Duration (org.joda.time.Duration)1 AttributeQueryContainerDtoBuilder.anAttributeQueryContainerDto (uk.gov.ida.hub.samlsoapproxy.builders.AttributeQueryContainerDtoBuilder.anAttributeQueryContainerDto)1 AttributeQueryContainerDto (uk.gov.ida.hub.samlsoapproxy.domain.AttributeQueryContainerDto)1 InvalidSamlRequestInAttributeQueryException (uk.gov.ida.hub.samlsoapproxy.exceptions.InvalidSamlRequestInAttributeQueryException)1