Search in sources :

Example 1 with AuthnResponseFromHubContainerDto

use of uk.gov.ida.hub.samlengine.contracts.AuthnResponseFromHubContainerDto in project verify-hub by alphagov.

the class RpAuthnResponseGeneratorResourceTest method shouldGenerateRpAuthnResponseWithMessageSignedByHubUsingLegacySamlStandard.

@Test
public void shouldGenerateRpAuthnResponseWithMessageSignedByHubUsingLegacySamlStandard() throws Exception {
    // Given
    ResponseFromHubDto responseFromHubDto = aResponseFromHubDto().withStatus(TransactionIdaStatus.NoMatchingServiceMatchFromHub).withAuthnRequestIssuerEntityId(TestEntityIds.TEST_RP).withAssertion(createAssertionString()).build();
    configStub.setupCertificatesForEntity(responseFromHubDto.getAuthnRequestIssuerEntityId());
    configStub.signResponsesAndUseLegacyStandard(responseFromHubDto.getAuthnRequestIssuerEntityId());
    // When
    URI generateAuthnResponseEndpoint = samlEngineAppRule.getUri(Urls.SamlEngineUrls.GENERATE_RP_AUTHN_RESPONSE_RESOURCE);
    Response rpAuthnResponse = client.target(generateAuthnResponseEndpoint).request().post(Entity.entity(responseFromHubDto, MediaType.APPLICATION_JSON_TYPE));
    // Then
    assertThat(rpAuthnResponse.getStatus()).isEqualTo(Response.Status.OK.getStatusCode());
    AuthnResponseFromHubContainerDto result = rpAuthnResponse.readEntity(AuthnResponseFromHubContainerDto.class);
    org.opensaml.saml.saml2.core.Response response = extractResponse(result);
    assertThat(response.getStatus().getStatusCode().getValue()).isEqualTo(StatusCode.SUCCESS);
    assertThat(response.getEncryptedAssertions()).isNotEmpty();
    assertThat(response.getID()).isEqualTo(responseFromHubDto.getResponseId());
    assertThat(response.getInResponseTo()).isEqualTo(responseFromHubDto.getInResponseTo());
    assertThat(response.getIssuer().getValue()).isEqualTo(TestEntityIds.HUB_ENTITY_ID);
}
Also used : Response(javax.ws.rs.core.Response) AuthnResponseFromHubContainerDto(uk.gov.ida.hub.samlengine.contracts.AuthnResponseFromHubContainerDto) ResponseFromHubDtoBuilder.aResponseFromHubDto(uk.gov.ida.integrationtest.hub.samlengine.builders.ResponseFromHubDtoBuilder.aResponseFromHubDto) ResponseFromHubDto(uk.gov.ida.hub.samlengine.contracts.ResponseFromHubDto) URI(java.net.URI) Test(org.junit.Test)

Example 2 with AuthnResponseFromHubContainerDto

use of uk.gov.ida.hub.samlengine.contracts.AuthnResponseFromHubContainerDto in project verify-hub by alphagov.

the class RpAuthnResponseGeneratorResourceTest method shouldGenerateRpAuthnResponseWithUnsignedMessage.

@Test
public void shouldGenerateRpAuthnResponseWithUnsignedMessage() throws Exception {
    // Given
    String assertion = createAssertionString();
    ResponseFromHubDto responseFromHubDto = aResponseFromHubDto().withAuthnRequestIssuerEntityId(TestEntityIds.TEST_RP).withAssertion(assertion).withStatus(TransactionIdaStatus.Success).build();
    configStub.setupCertificatesForEntity(responseFromHubDto.getAuthnRequestIssuerEntityId());
    configStub.doNotSignResponseMessages(responseFromHubDto.getAuthnRequestIssuerEntityId());
    // When
    URI generateAuthnResponseEndpoint = samlEngineAppRule.getUri(Urls.SamlEngineUrls.GENERATE_RP_AUTHN_RESPONSE_RESOURCE);
    Response rpAuthnResponse = client.target(generateAuthnResponseEndpoint).request().post(Entity.entity(responseFromHubDto, MediaType.APPLICATION_JSON_TYPE));
    // Then
    assertThat(rpAuthnResponse.getStatus()).isEqualTo(Response.Status.OK.getStatusCode());
    AuthnResponseFromHubContainerDto result = rpAuthnResponse.readEntity(AuthnResponseFromHubContainerDto.class);
    org.opensaml.saml.saml2.core.Response response = extractResponse(result);
    assertThat(response.getStatus().getStatusCode().getValue()).isEqualTo(StatusCode.SUCCESS);
    assertThat(response.getEncryptedAssertions()).isNotEmpty();
    assertThat(response.getID()).isEqualTo(responseFromHubDto.getResponseId());
    assertThat(response.getInResponseTo()).isEqualTo(responseFromHubDto.getInResponseTo());
    assertThat(response.getSignature()).isNull();
    assertThat(response.getIssuer()).isNull();
}
Also used : Response(javax.ws.rs.core.Response) AuthnResponseFromHubContainerDto(uk.gov.ida.hub.samlengine.contracts.AuthnResponseFromHubContainerDto) ResponseFromHubDtoBuilder.aResponseFromHubDto(uk.gov.ida.integrationtest.hub.samlengine.builders.ResponseFromHubDtoBuilder.aResponseFromHubDto) ResponseFromHubDto(uk.gov.ida.hub.samlengine.contracts.ResponseFromHubDto) URI(java.net.URI) Test(org.junit.Test)

Example 3 with AuthnResponseFromHubContainerDto

use of uk.gov.ida.hub.samlengine.contracts.AuthnResponseFromHubContainerDto in project verify-hub by alphagov.

the class RpAuthnResponseGeneratorService method createSuccessResponse.

private AuthnResponseFromHubContainerDto createSuccessResponse(final ResponseFromHubDto responseFromHub) {
    String authnRequestIssuerEntityId = responseFromHub.getAuthnRequestIssuerEntityId();
    final OutboundResponseFromHub response = new OutboundResponseFromHub(responseFromHub.getResponseId(), responseFromHub.getInResponseTo(), hubEntityId, DateTime.now(), TransactionIdaStatus.valueOf(responseFromHub.getStatus().name()), responseFromHub.getMatchingServiceAssertion(), responseFromHub.getAssertionConsumerServiceUri());
    String samlMessage = outboundResponseFromHubToResponseTransformerFactory.get(authnRequestIssuerEntityId).apply(response);
    return new AuthnResponseFromHubContainerDto(samlMessage, responseFromHub.getAssertionConsumerServiceUri(), responseFromHub.getRelayState(), responseFromHub.getResponseId());
}
Also used : AuthnResponseFromHubContainerDto(uk.gov.ida.hub.samlengine.contracts.AuthnResponseFromHubContainerDto) OutboundResponseFromHub(uk.gov.ida.saml.core.domain.OutboundResponseFromHub)

Example 4 with AuthnResponseFromHubContainerDto

use of uk.gov.ida.hub.samlengine.contracts.AuthnResponseFromHubContainerDto in project verify-hub by alphagov.

the class RpAuthnResponseGeneratorResourceTest method shouldGenerateRpAuthnResponseWithMessageSignedByHubUsingSamlProfileStandard.

@Test
public void shouldGenerateRpAuthnResponseWithMessageSignedByHubUsingSamlProfileStandard() throws Exception {
    // Given
    String assertion = createAssertionString();
    ResponseFromHubDto responseFromHubDto = aResponseFromHubDto().withAuthnRequestIssuerEntityId(TestEntityIds.TEST_RP).withAssertion(assertion).withStatus(TransactionIdaStatus.Success).build();
    configStub.setupCertificatesForEntity(responseFromHubDto.getAuthnRequestIssuerEntityId());
    configStub.signResponsesAndUseSamlStandard(responseFromHubDto.getAuthnRequestIssuerEntityId());
    // When
    URI generateAuthnResponseEndpoint = samlEngineAppRule.getUri(Urls.SamlEngineUrls.GENERATE_RP_AUTHN_RESPONSE_RESOURCE);
    Response rpAuthnResponse = client.target(generateAuthnResponseEndpoint).request().post(Entity.entity(responseFromHubDto, MediaType.APPLICATION_JSON_TYPE));
    // Then
    assertThat(rpAuthnResponse.getStatus()).isEqualTo(Response.Status.OK.getStatusCode());
    AuthnResponseFromHubContainerDto actualResult = rpAuthnResponse.readEntity(AuthnResponseFromHubContainerDto.class);
    org.opensaml.saml.saml2.core.Response response = extractResponse(actualResult);
    assertThat(response.getStatus().getStatusCode().getValue()).isEqualTo(StatusCode.SUCCESS);
    assertThat(response.getEncryptedAssertions()).isNotEmpty();
    assertThat(response.getID()).isEqualTo(responseFromHubDto.getResponseId());
    assertThat(response.getInResponseTo()).isEqualTo(responseFromHubDto.getInResponseTo());
    assertThat(response.getIssuer().getValue()).isEqualTo(TestEntityIds.HUB_ENTITY_ID);
    assertThat(response.getSignature()).isNotNull();
}
Also used : Response(javax.ws.rs.core.Response) AuthnResponseFromHubContainerDto(uk.gov.ida.hub.samlengine.contracts.AuthnResponseFromHubContainerDto) ResponseFromHubDtoBuilder.aResponseFromHubDto(uk.gov.ida.integrationtest.hub.samlengine.builders.ResponseFromHubDtoBuilder.aResponseFromHubDto) ResponseFromHubDto(uk.gov.ida.hub.samlengine.contracts.ResponseFromHubDto) URI(java.net.URI) Test(org.junit.Test)

Aggregations

AuthnResponseFromHubContainerDto (uk.gov.ida.hub.samlengine.contracts.AuthnResponseFromHubContainerDto)4 URI (java.net.URI)3 Response (javax.ws.rs.core.Response)3 Test (org.junit.Test)3 ResponseFromHubDto (uk.gov.ida.hub.samlengine.contracts.ResponseFromHubDto)3 ResponseFromHubDtoBuilder.aResponseFromHubDto (uk.gov.ida.integrationtest.hub.samlengine.builders.ResponseFromHubDtoBuilder.aResponseFromHubDto)3 OutboundResponseFromHub (uk.gov.ida.saml.core.domain.OutboundResponseFromHub)1