Search in sources :

Example 1 with InvalidSamlRequestInAttributeQueryException

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

the class ExecuteAttributeQueryRequest method convertToElementAndValidate.

private Element convertToElementAndValidate(AttributeQueryContainerDto attributeQueryContainerDto) {
    try {
        Element matchingServiceRequest;
        matchingServiceRequest = XmlUtils.convertToElement(attributeQueryContainerDto.getSamlRequest());
        validateRequestSignature(matchingServiceRequest, attributeQueryContainerDto.getMatchingServiceUri());
        return matchingServiceRequest;
    } catch (ParserConfigurationException | SAXException | IOException e) {
        throw new InvalidSamlRequestInAttributeQueryException("Attribute Query had invalid XML.", e);
    } catch (SamlTransformationErrorException e) {
        throw new InvalidSamlRequestInAttributeQueryException("Attribute Query had invalid Saml", e);
    }
}
Also used : InvalidSamlRequestInAttributeQueryException(uk.gov.ida.hub.samlsoapproxy.exceptions.InvalidSamlRequestInAttributeQueryException) SamlTransformationErrorException(uk.gov.ida.saml.core.validation.SamlTransformationErrorException) Element(org.w3c.dom.Element) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException)

Example 2 with InvalidSamlRequestInAttributeQueryException

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

the class AttributeQueryRequestRunnableTest method run_shouldLogToAudit_ButShouldNotNotifySamlEngine_RequestHasTimedOut_AndWhenMessageFromSamlEngineValidationFailsWithUnexpectedException.

@Test
public void run_shouldLogToAudit_ButShouldNotNotifySamlEngine_RequestHasTimedOut_AndWhenMessageFromSamlEngineValidationFailsWithUnexpectedException() throws Exception {
    when(executeAttributeQueryRequest.execute(sessionId, attributeQueryContainerDto)).thenThrow(new InvalidSamlRequestInAttributeQueryException("Attribute Query had invalid XML.", new RuntimeException("test exception")));
    doNothing().doThrow(new AttributeQueryTimeoutException()).when(timeoutEvaluator).hasAttributeQueryTimedOut(attributeQueryContainerDto);
    attributeQueryRequestRunnable.run();
    // One for the timeout, one for the message error
    verify(eventSinkProxy, times(2)).logHubEvent(isA(EventSinkHubEvent.class));
    verify(eventEmitter, times(2)).record(isA(EventSinkHubEvent.class));
    verify(hubMatchingServiceResponseReceiverProxy, never()).notifyHubOfMatchingServiceRequestFailure(sessionId);
}
Also used : InvalidSamlRequestInAttributeQueryException(uk.gov.ida.hub.samlsoapproxy.exceptions.InvalidSamlRequestInAttributeQueryException) AttributeQueryTimeoutException(uk.gov.ida.hub.samlsoapproxy.exceptions.AttributeQueryTimeoutException) EventSinkHubEvent(uk.gov.ida.eventsink.EventSinkHubEvent) Test(org.junit.Test)

Example 3 with InvalidSamlRequestInAttributeQueryException

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

the class AttributeQueryRequestRunnableTest method run_shouldNotifySamlEngineAndLogErrorWhenMatchingServiceRequestIsNotProperlySigned.

@Test
public void run_shouldNotifySamlEngineAndLogErrorWhenMatchingServiceRequestIsNotProperlySigned() {
    when(executeAttributeQueryRequest.execute(sessionId, attributeQueryContainerDto)).thenThrow(new InvalidSamlRequestInAttributeQueryException("Attribute Query had invalid Saml", new Exception()));
    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().getSessionId()).isEqualTo(sessionId.toString());
    assertThat(emitterLoggedHubEvent.getValue().getSessionId()).isEqualTo(sessionId.toString());
    verify(hubMatchingServiceResponseReceiverProxy).notifyHubOfMatchingServiceRequestFailure(sessionId);
    verify(timeoutEvaluator, times(2)).hasAttributeQueryTimedOut(attributeQueryContainerDto);
    assertThat(loggedHubEvent.getValue().getDetails().get(message)).contains("Incorrect message provided by caller");
    assertThat(emitterLoggedHubEvent.getValue().getDetails().get(message)).contains("Incorrect message provided by caller");
}
Also used : InvalidSamlRequestInAttributeQueryException(uk.gov.ida.hub.samlsoapproxy.exceptions.InvalidSamlRequestInAttributeQueryException) CertificateChainValidationException(uk.gov.ida.common.shared.security.verification.exceptions.CertificateChainValidationException) SamlTransformationErrorException(uk.gov.ida.saml.core.validation.SamlTransformationErrorException) AttributeQueryTimeoutException(uk.gov.ida.hub.samlsoapproxy.exceptions.AttributeQueryTimeoutException) InvalidSamlRequestInAttributeQueryException(uk.gov.ida.hub.samlsoapproxy.exceptions.InvalidSamlRequestInAttributeQueryException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException) EventSinkHubEvent(uk.gov.ida.eventsink.EventSinkHubEvent) Test(org.junit.Test)

Aggregations

InvalidSamlRequestInAttributeQueryException (uk.gov.ida.hub.samlsoapproxy.exceptions.InvalidSamlRequestInAttributeQueryException)3 IOException (java.io.IOException)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 Test (org.junit.Test)2 SAXException (org.xml.sax.SAXException)2 EventSinkHubEvent (uk.gov.ida.eventsink.EventSinkHubEvent)2 AttributeQueryTimeoutException (uk.gov.ida.hub.samlsoapproxy.exceptions.AttributeQueryTimeoutException)2 SamlTransformationErrorException (uk.gov.ida.saml.core.validation.SamlTransformationErrorException)2 Element (org.w3c.dom.Element)1 CertificateChainValidationException (uk.gov.ida.common.shared.security.verification.exceptions.CertificateChainValidationException)1