Search in sources :

Example 1 with OutboundResponseFromHub

use of uk.gov.ida.saml.core.domain.OutboundResponseFromHub in project verify-hub by alphagov.

the class SamlMessageSenderApiResourceTest method sendJsonErrorResponseFromHub_shouldRespondWithNextLocation.

@Test
public void sendJsonErrorResponseFromHub_shouldRespondWithNextLocation() throws Exception {
    URI uri = URI.create("http://blah");
    String requestId = UUID.randomUUID().toString();
    final SessionId sessionId = SessionId.createNewSessionId();
    OutboundResponseFromHub authnResponseFromHub = anAuthnResponse().withInResponseTo(requestId).withIssuerId(HUB_ENTITY_ID).withTransactionIdaStatus(TransactionIdaStatus.RequesterError).buildOutboundResponseFromHub();
    Function<OutboundResponseFromHub, String> outboundResponseFromHubToStringTransformer = new HubTransformersFactory().getOutboundResponseFromHubToStringTransformer(new HardCodedKeyStore(HUB_ENTITY_ID), getKeyStore(), new IdpHardCodedEntityToEncryptForLocator(), SIGNATURE_ALGORITHM, DIGEST_ALGORITHM);
    String samlString = outboundResponseFromHubToStringTransformer.apply(authnResponseFromHub);
    AuthnResponseFromHubContainerDto authnResponseFromHubContainerDto = new AuthnResponseFromHubContainerDto(samlString, uri, com.google.common.base.Optional.absent(), authnResponseFromHub.getId());
    policyStubRule.anErrorResponseFromHubToRp(sessionId, authnResponseFromHubContainerDto);
    javax.ws.rs.core.Response response = getResponseFromSamlProxy(Urls.SamlProxyUrls.SEND_ERROR_RESPONSE_FROM_HUB_API_RESOURCE, sessionId);
    assertThat(response.getStatus()).isEqualTo(200);
    assertThat(response.readEntity(SamlMessageSenderHandler.SamlMessage.class).getPostEndpoint()).isEqualTo(uri.toASCIIString());
}
Also used : HubTransformersFactory(uk.gov.ida.saml.hub.api.HubTransformersFactory) HardCodedKeyStore(uk.gov.ida.saml.core.test.HardCodedKeyStore) AuthnResponseFromHubContainerDto(uk.gov.ida.hub.samlproxy.contracts.AuthnResponseFromHubContainerDto) URI(java.net.URI) OutboundResponseFromHub(uk.gov.ida.saml.core.domain.OutboundResponseFromHub) Response(javax.ws.rs.core.Response) SessionId(uk.gov.ida.common.SessionId) Test(org.junit.Test)

Example 2 with OutboundResponseFromHub

use of uk.gov.ida.saml.core.domain.OutboundResponseFromHub in project verify-hub by alphagov.

the class SamlMessageSenderApiResourceTest method sendJsonErrorResponseFromHub_shouldErrorWhenAValidationFailureOccurs.

@Test
public void sendJsonErrorResponseFromHub_shouldErrorWhenAValidationFailureOccurs() throws Exception {
    URI uri = URI.create("http://blah");
    String requestId = UUID.randomUUID().toString();
    final SessionId sessionId = SessionId.createNewSessionId();
    OutboundResponseFromHub authnResponseFromHub = anAuthnResponse().withInResponseTo(requestId).withIssuerId(HUB_ENTITY_ID).withTransactionIdaStatus(TransactionIdaStatus.RequesterError).buildOutboundResponseFromHub();
    AuthnResponseFromHubContainerDto authnResponseFromHubContainerDto = new AuthnResponseFromHubContainerDto("invalid saml", uri, com.google.common.base.Optional.absent(), authnResponseFromHub.getId());
    policyStubRule.anErrorResponseFromHubToRp(sessionId, authnResponseFromHubContainerDto);
    javax.ws.rs.core.Response response = getResponseFromSamlProxy(Urls.SamlProxyUrls.SEND_ERROR_RESPONSE_FROM_HUB_API_RESOURCE, sessionId);
    assertThat(response.getStatus()).isEqualTo(500);
}
Also used : AuthnResponseFromHubContainerDto(uk.gov.ida.hub.samlproxy.contracts.AuthnResponseFromHubContainerDto) OutboundResponseFromHub(uk.gov.ida.saml.core.domain.OutboundResponseFromHub) Response(javax.ws.rs.core.Response) URI(java.net.URI) SessionId(uk.gov.ida.common.SessionId) Test(org.junit.Test)

Example 3 with OutboundResponseFromHub

use of uk.gov.ida.saml.core.domain.OutboundResponseFromHub in project verify-hub by alphagov.

the class RpErrorResponseGeneratorService method generate.

public SamlMessageDto generate(RequestForErrorResponseFromHubDto requestForErrorResponseFromHubDto) {
    try {
        final OutboundResponseFromHub response = new OutboundResponseFromHub(requestForErrorResponseFromHubDto.getResponseId(), requestForErrorResponseFromHubDto.getInResponseTo(), hubEntityId, DateTime.now(), TransactionIdaStatus.valueOf(requestForErrorResponseFromHubDto.getStatus().name()), empty(), requestForErrorResponseFromHubDto.getAssertionConsumerServiceUri());
        final String errorResponse = outboundResponseFromHubToResponseTransformerFactory.get(requestForErrorResponseFromHubDto.getAuthnRequestIssuerEntityId()).apply(response);
        return new SamlMessageDto(errorResponse);
    } catch (Exception e) {
        throw new UnableToGenerateSamlException("Unable to generate RP error response", e, Level.ERROR);
    }
}
Also used : SamlMessageDto(uk.gov.ida.hub.samlengine.domain.SamlMessageDto) OutboundResponseFromHub(uk.gov.ida.saml.core.domain.OutboundResponseFromHub) UnableToGenerateSamlException(uk.gov.ida.hub.samlengine.exceptions.UnableToGenerateSamlException) UnableToGenerateSamlException(uk.gov.ida.hub.samlengine.exceptions.UnableToGenerateSamlException)

Example 4 with OutboundResponseFromHub

use of uk.gov.ida.saml.core.domain.OutboundResponseFromHub in project verify-hub by alphagov.

the class SamlMessageSenderApiResourceTest method sendJsonAuthnResponseFromHub_shouldErrorWhenAValidationFailureOccurs.

@Test
public void sendJsonAuthnResponseFromHub_shouldErrorWhenAValidationFailureOccurs() throws Exception {
    String responseId = "my-request";
    SessionId sessionId = SessionId.createNewSessionId();
    URI nextLocationUri = URI.create("http://blah");
    OutboundResponseFromHub authnResponseFromHub = anAuthnResponse().withInResponseTo(responseId).withIssuerId(HUB_ENTITY_ID).withTransactionIdaStatus(TransactionIdaStatus.Success).buildOutboundResponseFromHub();
    AuthnResponseFromHubContainerDto invalidAuthnResponseFromHubContainerDto = new AuthnResponseFromHubContainerDto("something not valid", nextLocationUri, com.google.common.base.Optional.absent(), authnResponseFromHub.getId());
    policyStubRule.anAuthnResponseFromHubToRp(sessionId, invalidAuthnResponseFromHubContainerDto);
    javax.ws.rs.core.Response response = getResponseFromSamlProxy(Urls.SamlProxyUrls.SEND_RESPONSE_FROM_HUB_API_RESOURCE, sessionId);
    assertThat(response.getStatus()).isEqualTo(500);
}
Also used : AuthnResponseFromHubContainerDto(uk.gov.ida.hub.samlproxy.contracts.AuthnResponseFromHubContainerDto) OutboundResponseFromHub(uk.gov.ida.saml.core.domain.OutboundResponseFromHub) Response(javax.ws.rs.core.Response) SessionId(uk.gov.ida.common.SessionId) URI(java.net.URI) Test(org.junit.Test)

Example 5 with OutboundResponseFromHub

use of uk.gov.ida.saml.core.domain.OutboundResponseFromHub in project verify-hub by alphagov.

the class SamlMessageSenderApiResourceTest method sendUnsignedJsonAuthnResponseFromHub_shouldRespondWithNextLocation.

@Test
public void sendUnsignedJsonAuthnResponseFromHub_shouldRespondWithNextLocation() throws Exception {
    SessionId sessionId = SessionId.createNewSessionId();
    URI nextLocationUri = URI.create("http://blah");
    String requestId = UUID.randomUUID().toString();
    Function<OutboundResponseFromHub, String> outboundResponseFromHubToStringTransformer = new HubTransformersFactory().getOutboundResponseFromHubToStringTransformer(new HardCodedKeyStore(HUB_ENTITY_ID), getKeyStore(), new IdpHardCodedEntityToEncryptForLocator(), SIGNATURE_ALGORITHM, DIGEST_ALGORITHM);
    OutboundResponseFromHub authnResponseFromHub = anAuthnResponse().withInResponseTo(requestId).withIssuerId(HUB_ENTITY_ID).withTransactionIdaStatus(TransactionIdaStatus.Success).buildOutboundResponseFromHub();
    String samlString = outboundResponseFromHubToStringTransformer.apply(authnResponseFromHub);
    AuthnResponseFromHubContainerDto authnResponseFromHubContainerDto = new AuthnResponseFromHubContainerDto(samlString, nextLocationUri, com.google.common.base.Optional.absent(), authnResponseFromHub.getId());
    policyStubRule.anAuthnResponseFromHubToRp(sessionId, authnResponseFromHubContainerDto);
    javax.ws.rs.core.Response response = getResponseFromSamlProxy(Urls.SamlProxyUrls.SEND_RESPONSE_FROM_HUB_API_RESOURCE, sessionId);
    assertThat(response.readEntity(SamlMessageSenderHandler.SamlMessage.class).getPostEndpoint()).isEqualTo(nextLocationUri.toASCIIString());
}
Also used : HubTransformersFactory(uk.gov.ida.saml.hub.api.HubTransformersFactory) HardCodedKeyStore(uk.gov.ida.saml.core.test.HardCodedKeyStore) AuthnResponseFromHubContainerDto(uk.gov.ida.hub.samlproxy.contracts.AuthnResponseFromHubContainerDto) URI(java.net.URI) OutboundResponseFromHub(uk.gov.ida.saml.core.domain.OutboundResponseFromHub) Response(javax.ws.rs.core.Response) SessionId(uk.gov.ida.common.SessionId) Test(org.junit.Test)

Aggregations

OutboundResponseFromHub (uk.gov.ida.saml.core.domain.OutboundResponseFromHub)7 URI (java.net.URI)5 Response (javax.ws.rs.core.Response)5 Test (org.junit.Test)5 SessionId (uk.gov.ida.common.SessionId)5 AuthnResponseFromHubContainerDto (uk.gov.ida.hub.samlproxy.contracts.AuthnResponseFromHubContainerDto)5 HardCodedKeyStore (uk.gov.ida.saml.core.test.HardCodedKeyStore)3 HubTransformersFactory (uk.gov.ida.saml.hub.api.HubTransformersFactory)3 AuthnResponseFromHubContainerDto (uk.gov.ida.hub.samlengine.contracts.AuthnResponseFromHubContainerDto)1 SamlMessageDto (uk.gov.ida.hub.samlengine.domain.SamlMessageDto)1 UnableToGenerateSamlException (uk.gov.ida.hub.samlengine.exceptions.UnableToGenerateSamlException)1 ResponseAssertionSigner (uk.gov.ida.saml.core.transformers.outbound.decorators.ResponseAssertionSigner)1 IdaKeyStoreCredentialRetriever (uk.gov.ida.saml.security.IdaKeyStoreCredentialRetriever)1 SignatureFactory (uk.gov.ida.saml.security.SignatureFactory)1