Search in sources :

Example 21 with SessionId

use of uk.gov.ida.common.SessionId in project verify-hub by alphagov.

the class SamlMessageReceiverApiResourceTest method shouldCreateSessionForAuthnRequest.

@Test
public void shouldCreateSessionForAuthnRequest() throws Exception {
    SamlRequestDto authnRequestWrapper = createAuthnRequest(TEST_RP, "relayState", TEST_RP_PUBLIC_SIGNING_CERT, TEST_RP_PRIVATE_SIGNING_KEY);
    configStubRule.setupStubForCertificates(TEST_RP);
    SessionId sessionId = SessionId.createNewSessionId();
    policyStubRule.stubCreateSession(sessionId);
    Response clientResponse = postSAML(authnRequestWrapper, Urls.SamlProxyUrls.SAML2_SSO_RECEIVER_API_ROOT);
    assertThat(clientResponse.getStatus()).isEqualTo(Response.Status.OK.getStatusCode());
    assertThat(clientResponse.readEntity(SessionId.class)).isEqualTo(sessionId);
}
Also used : Response(javax.ws.rs.core.Response) ResponseBuilder.aResponse(uk.gov.ida.saml.core.test.builders.ResponseBuilder.aResponse) SamlRequestDto(uk.gov.ida.hub.samlproxy.contracts.SamlRequestDto) SessionId(uk.gov.ida.common.SessionId) Test(org.junit.Test)

Example 22 with SessionId

use of uk.gov.ida.common.SessionId 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 23 with SessionId

use of uk.gov.ida.common.SessionId 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)

Example 24 with SessionId

use of uk.gov.ida.common.SessionId in project verify-hub by alphagov.

the class CountryAuthnResponseTranslatorResourceTest method createAuthnResponseSignedByKeyPair.

private SamlAuthnResponseTranslatorDto createAuthnResponseSignedByKeyPair(String publicKey, String privateKey) throws Exception {
    SessionId sessionId = SessionId.createNewSessionId();
    String samlResponse = authnResponseFactory.aSamlResponseFromCountry("a-request", samlEngineAppRule.getCountryMetadataUri(), publicKey, privateKey, DESTINATION, SIGNATURE_ALGORITHM, DIGEST_ALGORITHM, EncryptionConstants.ALGO_ID_BLOCKCIPHER_AES256_GCM, EidasAuthnContext.EIDAS_LOA_SUBSTANTIAL, DESTINATION, samlEngineAppRule.getCountryMetadataUri());
    return new SamlAuthnResponseTranslatorDto(samlResponse, sessionId, "127.0.0.1", matchingServiceEntityId);
}
Also used : SamlAuthnResponseTranslatorDto(uk.gov.ida.hub.samlengine.contracts.SamlAuthnResponseTranslatorDto) SessionId(uk.gov.ida.common.SessionId)

Example 25 with SessionId

use of uk.gov.ida.common.SessionId in project verify-hub by alphagov.

the class CountryMetadataConsumerTest method shouldServeCountryMetadata.

@Test
public void shouldServeCountryMetadata() throws Exception {
    // Given
    SessionId sessionId = SessionId.createNewSessionId();
    policyStubRule.receiveAuthnResponseFromCountry(sessionId.toString(), LEVEL_2);
    String response = authnResponseFactory.aSamlResponseFromIdp("a-request", countryMetadata.getCountryMetadataUri(), idpSigningCert, idpSigningKey, "", SIGNATURE_ALGORITHM, DIGEST_ALGORITHM);
    // When
    ResponseActionDto post = postSAML(new SamlRequestDto(response, sessionId.getSessionId(), "127.0.0.1")).readEntity(ResponseActionDto.class);
    // Then
    assertThat(post.getSessionId()).isEqualTo(sessionId);
    assertThat(post.getLoaAchieved()).isEqualTo(LEVEL_2);
}
Also used : ResponseActionDto(uk.gov.ida.hub.samlproxy.domain.ResponseActionDto) SamlRequestDto(uk.gov.ida.hub.samlproxy.contracts.SamlRequestDto) SessionId(uk.gov.ida.common.SessionId) Test(org.junit.Test)

Aggregations

SessionId (uk.gov.ida.common.SessionId)39 Test (org.junit.Test)32 URI (java.net.URI)17 ResponseBuilder.aResponse (uk.gov.ida.saml.core.test.builders.ResponseBuilder.aResponse)15 SamlValidationResponse (uk.gov.ida.saml.core.validation.SamlValidationResponse)15 Response (javax.ws.rs.core.Response)12 Response (org.opensaml.saml.saml2.core.Response)12 Element (org.w3c.dom.Element)10 Matchers.anyString (org.mockito.Matchers.anyString)7 AuthnResponseFromHubContainerDto (uk.gov.ida.hub.samlproxy.contracts.AuthnResponseFromHubContainerDto)6 SamlRequestDto (uk.gov.ida.hub.samlproxy.contracts.SamlRequestDto)5 OutboundResponseFromHub (uk.gov.ida.saml.core.domain.OutboundResponseFromHub)5 ResponseActionDto (uk.gov.ida.hub.samlproxy.domain.ResponseActionDto)4 HubTransformersFactory (uk.gov.ida.saml.hub.api.HubTransformersFactory)4 Timed (com.codahale.metrics.annotation.Timed)3 Consumes (javax.ws.rs.Consumes)3 POST (javax.ws.rs.POST)3 Produces (javax.ws.rs.Produces)3 AuthnRequest (org.opensaml.saml.saml2.core.AuthnRequest)3 SamlMessage (uk.gov.ida.hub.samlproxy.controllogic.SamlMessageSenderHandler.SamlMessage)3