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);
}
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();
}
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());
}
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();
}
Aggregations