use of uk.gov.ida.hub.samlproxy.contracts.AuthnResponseFromHubContainerDto 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());
}
use of uk.gov.ida.hub.samlproxy.contracts.AuthnResponseFromHubContainerDto 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);
}
use of uk.gov.ida.hub.samlproxy.contracts.AuthnResponseFromHubContainerDto in project verify-hub by alphagov.
the class SamlMessageSenderHandler method generateErrorResponseFromHub.
public SamlMessage generateErrorResponseFromHub(final SessionId sessionId, String principalIpAddressAsSeenByHub) {
AuthnResponseFromHubContainerDto authnResponseFromHub = sessionProxy.getErrorResponseFromHub(sessionId);
Response samlResponse = responseTransformer.apply(authnResponseFromHub.getSamlResponse());
validateAndLogSamlResponseSignature(samlResponse);
SamlMessage samlMessage = new SamlMessage(authnResponseFromHub.getSamlResponse(), SamlMessageType.SAML_RESPONSE, authnResponseFromHub.getRelayState(), authnResponseFromHub.getPostEndpoint().toString(), Optional.<Boolean>absent());
externalCommunicationEventLogger.logResponseFromHub(authnResponseFromHub.getResponseId(), sessionId, authnResponseFromHub.getPostEndpoint(), principalIpAddressAsSeenByHub);
return samlMessage;
}
use of uk.gov.ida.hub.samlproxy.contracts.AuthnResponseFromHubContainerDto in project verify-hub by alphagov.
the class SamlMessageSenderHandlerTest method setUpErrorResponseFromHub.
private Response setUpErrorResponseFromHub(SessionId sessionId, String expectedSamlMessageId) throws MarshallingException, SignatureException {
AuthnResponseFromHubContainerDto hubContainerDto = new AuthnResponseFromHubContainerDto(samlRequest, postEndPoint, relayState, expectedSamlMessageId);
when(sessionProxy.getErrorResponseFromHub(sessionId)).thenReturn(hubContainerDto);
Response openSamlResponse = aResponse().withId(expectedSamlMessageId).build();
when(responseTransformer.apply(anyString())).thenReturn(openSamlResponse);
return openSamlResponse;
}
use of uk.gov.ida.hub.samlproxy.contracts.AuthnResponseFromHubContainerDto 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);
}
Aggregations