Search in sources :

Example 46 with Response

use of org.opensaml.saml.saml2.ecp.Response in project verify-hub by alphagov.

the class ExecuteAttributeQueryRequestTest method run_shouldLogStatusMessageIfItExists.

@Test
public void run_shouldLogStatusMessageIfItExists() throws MarshallingException, SignatureException {
    final Element matchingServiceResponse = mock(Element.class);
    when(attributeQueryRequestClient.sendQuery(any(Element.class), anyString(), any(SessionId.class), any(URI.class))).thenReturn(matchingServiceResponse);
    String message = "Some message";
    StatusMessage statusMessage = StatusMessageBuilder.aStatusMessage().withMessage(message).build();
    Response response = aResponse().withStatus(StatusBuilder.aStatus().withMessage(statusMessage).build()).build();
    when(elementToResponseTransformer.apply(matchingServiceResponse)).thenReturn(response);
    executeAttributeQueryRequest.execute(sessionId, attributeQueryContainerDto);
    verify(protectiveMonitoringLogger).logAttributeQueryResponse(response.getID(), response.getInResponseTo(), response.getIssuer().getValue(), true, response.getStatus().getStatusCode().getValue(), message);
}
Also used : Response(org.opensaml.saml.saml2.core.Response) ResponseBuilder.aResponse(uk.gov.ida.saml.core.test.builders.ResponseBuilder.aResponse) SamlValidationResponse(uk.gov.ida.saml.core.validation.SamlValidationResponse) Element(org.w3c.dom.Element) Matchers.anyString(org.mockito.Matchers.anyString) SessionId(uk.gov.ida.common.SessionId) URI(java.net.URI) StatusMessage(org.opensaml.saml.saml2.core.StatusMessage) Test(org.junit.Test)

Example 47 with Response

use of org.opensaml.saml.saml2.ecp.Response in project verify-hub by alphagov.

the class ExecuteAttributeQueryRequestTest method run_shouldLogProtectiveMonitoringCorrectly.

@Test
public void run_shouldLogProtectiveMonitoringCorrectly() throws Exception {
    final Element matchingServiceResponse = mock(Element.class);
    when(attributeQueryRequestClient.sendQuery(any(Element.class), anyString(), any(SessionId.class), any(URI.class))).thenReturn(matchingServiceResponse);
    Response response = aResponse().build();
    when(elementToResponseTransformer.apply(matchingServiceResponse)).thenReturn(response);
    executeAttributeQueryRequest.execute(sessionId, attributeQueryContainerDto);
    verify(protectiveMonitoringLogger).logAttributeQuery(attributeQuery.getID(), attributeQueryContainerDto.getMatchingServiceUri().toASCIIString(), attributeQuery.getIssuer().getValue(), true);
    verify(protectiveMonitoringLogger).logAttributeQueryResponse(response.getID(), response.getInResponseTo(), response.getIssuer().getValue(), true, response.getStatus().getStatusCode().getValue(), "");
}
Also used : Response(org.opensaml.saml.saml2.core.Response) ResponseBuilder.aResponse(uk.gov.ida.saml.core.test.builders.ResponseBuilder.aResponse) SamlValidationResponse(uk.gov.ida.saml.core.validation.SamlValidationResponse) Element(org.w3c.dom.Element) SessionId(uk.gov.ida.common.SessionId) URI(java.net.URI) Test(org.junit.Test)

Example 48 with Response

use of org.opensaml.saml.saml2.ecp.Response in project verify-hub by alphagov.

the class ExecuteAttributeQueryRequestTest method run_shouldCallInboundMessageValidatorWithAttributeQuery.

@Test
public void run_shouldCallInboundMessageValidatorWithAttributeQuery() throws Exception {
    when(attributeQueryRequestClient.sendQuery(any(Element.class), anyString(), any(SessionId.class), any(URI.class))).thenReturn(matchingServiceResponse);
    Response response = aResponse().build();
    when(elementToResponseTransformer.apply(matchingServiceResponse)).thenReturn(response);
    executeAttributeQueryRequest.execute(sessionId, attributeQueryContainerDto);
    verify(matchingRequestSignatureValidator).validate(attributeQuery, AttributeAuthorityDescriptor.DEFAULT_ELEMENT_NAME);
}
Also used : Response(org.opensaml.saml.saml2.core.Response) ResponseBuilder.aResponse(uk.gov.ida.saml.core.test.builders.ResponseBuilder.aResponse) SamlValidationResponse(uk.gov.ida.saml.core.validation.SamlValidationResponse) Element(org.w3c.dom.Element) SessionId(uk.gov.ida.common.SessionId) URI(java.net.URI) Test(org.junit.Test)

Example 49 with Response

use of org.opensaml.saml.saml2.ecp.Response in project verify-hub by alphagov.

the class ExecuteAttributeQueryRequestTest method run_shouldUseCorrectSignatureValidators.

@Test
public void run_shouldUseCorrectSignatureValidators() throws Exception {
    when(attributeQueryRequestClient.sendQuery(any(Element.class), anyString(), any(SessionId.class), any(URI.class))).thenReturn(matchingServiceResponse);
    final Response response = aResponse().build();
    when(elementToResponseTransformer.apply(matchingServiceResponse)).thenReturn(response);
    executeAttributeQueryRequest.execute(sessionId, attributeQueryContainerDto);
    verify(matchingRequestSignatureValidator).validate(attributeQuery, AttributeAuthorityDescriptor.DEFAULT_ELEMENT_NAME);
    verify(matchingResponseSignatureValidator).validate(response, AttributeAuthorityDescriptor.DEFAULT_ELEMENT_NAME);
}
Also used : Response(org.opensaml.saml.saml2.core.Response) ResponseBuilder.aResponse(uk.gov.ida.saml.core.test.builders.ResponseBuilder.aResponse) SamlValidationResponse(uk.gov.ida.saml.core.validation.SamlValidationResponse) Element(org.w3c.dom.Element) SessionId(uk.gov.ida.common.SessionId) URI(java.net.URI) Test(org.junit.Test)

Example 50 with Response

use of org.opensaml.saml.saml2.ecp.Response in project verify-hub by alphagov.

the class MatchingServiceResponseTranslatorService method translate.

public InboundResponseFromMatchingServiceDto translate(SamlResponseDto samlResponseDto) {
    final Response response = responseUnmarshaller.apply(samlResponseDto.getSamlResponse());
    MdcHelper.addContextToMdc(response);
    final InboundResponseFromMatchingService responseFromMatchingService = responseToInboundResponseFromMatchingServiceTransformer.transform(response);
    Optional<String> assertionBlob = Optional.empty();
    Optional<LevelOfAssurance> levelOfAssurance = Optional.empty();
    // FIXME?: transformer can return null
    if (responseFromMatchingService.getMatchingServiceAssertion() != null && responseFromMatchingService.getMatchingServiceAssertion().isPresent()) {
        assertionBlob = Optional.ofNullable(responseFromMatchingService.getMatchingServiceAssertion().get().getUnderlyingAssertionBlob());
        final Optional<AuthnContext> authnContext = responseFromMatchingService.getMatchingServiceAssertion().get().getAuthnContext();
        if (authnContext.isPresent()) {
            levelOfAssurance = Optional.of(LevelOfAssurance.valueOf(authnContext.get().name()));
        }
    }
    final InboundResponseFromMatchingServiceDto inboundResponseFromMatchingServiceDto = new InboundResponseFromMatchingServiceDto(responseFromMatchingService.getStatus(), responseFromMatchingService.getInResponseTo(), responseFromMatchingService.getIssuer(), assertionBlob, levelOfAssurance);
    return inboundResponseFromMatchingServiceDto;
}
Also used : Response(org.opensaml.saml.saml2.core.Response) LevelOfAssurance(uk.gov.ida.hub.samlengine.domain.LevelOfAssurance) InboundResponseFromMatchingServiceDto(uk.gov.ida.hub.samlengine.contracts.InboundResponseFromMatchingServiceDto) InboundResponseFromMatchingService(uk.gov.ida.saml.hub.domain.InboundResponseFromMatchingService) AuthnContext(uk.gov.ida.saml.core.domain.AuthnContext)

Aggregations

Response (org.opensaml.saml.saml2.core.Response)82 WSSecurityException (org.apache.wss4j.common.ext.WSSecurityException)41 Test (org.junit.Test)41 Element (org.w3c.dom.Element)35 Document (org.w3c.dom.Document)31 DateTime (org.joda.time.DateTime)30 Status (org.opensaml.saml.saml2.core.Status)30 Response (javax.ws.rs.core.Response)29 ResponseBuilder.aResponse (uk.gov.ida.saml.core.test.builders.ResponseBuilder.aResponse)27 LogoutResponse (org.opensaml.saml.saml2.core.LogoutResponse)25 SamlAssertionWrapper (org.apache.wss4j.common.saml.SamlAssertionWrapper)23 SamlValidationResponse (uk.gov.ida.saml.core.validation.SamlValidationResponse)21 Matchers.anyString (org.mockito.Matchers.anyString)20 SAMLCallback (org.apache.wss4j.common.saml.SAMLCallback)18 SubjectConfirmationDataBean (org.apache.wss4j.common.saml.bean.SubjectConfirmationDataBean)18 Assertion (org.opensaml.saml.saml2.core.Assertion)18 AuthnRequest (org.opensaml.saml.saml2.core.AuthnRequest)18 InputStream (java.io.InputStream)15 IOException (java.io.IOException)13 Crypto (org.apache.wss4j.common.crypto.Crypto)13