use of uk.gov.ida.common.SessionId in project verify-hub by alphagov.
the class MetadataConsumerTests method shouldAllowRequestsWhenMetadataIsAvailableAndValid.
@Test
public void shouldAllowRequestsWhenMetadataIsAvailableAndValid() throws Exception {
SessionId sessionId = SessionId.createNewSessionId();
policyStubRule.register(UriBuilder.fromPath(Urls.PolicyUrls.IDP_AUTHN_RESPONSE_RESOURCE).build(sessionId).getPath(), 200, ResponseActionDto.success(sessionId, true, LEVEL_2));
String response = authnResponseFactory.aSamlResponseFromIdp(TestEntityIds.STUB_IDP_ONE, STUB_IDP_PUBLIC_PRIMARY_CERT, STUB_IDP_PUBLIC_PRIMARY_PRIVATE_KEY, "", SIGNATURE_ALGORITHM, DIGEST_ALGORITHM);
ResponseActionDto post = postSAML(new SamlRequestDto(response, sessionId.getSessionId(), "127.0.0.1")).readEntity(ResponseActionDto.class);
assertThat(post.getSessionId()).isEqualTo(sessionId);
assertThat(post.getLoaAchieved()).isEqualTo(LEVEL_2);
}
use of uk.gov.ida.common.SessionId in project verify-hub by alphagov.
the class SamlMessageSenderApiResourceTest method sendJsonAuthnRequestFromHub_shouldRespondWithNextLocation.
@Test
public void sendJsonAuthnRequestFromHub_shouldRespondWithNextLocation() throws Exception {
SessionId sessionId = SessionId.createNewSessionId();
URI nextLocationUri = URI.create("http://blah");
IdaAuthnRequestFromHub authnRequestFromHub = anIdaAuthnRequest().withIssuer(HUB_ENTITY_ID).buildFromHub();
Function<IdaAuthnRequestFromHub, String> idaAuthnRequestFromHubToStringTransformer = new HubTransformersFactory().getIdaAuthnRequestFromHubToStringTransformer(getKeyStore(), SIGNATURE_ALGORITHM, DIGEST_ALGORITHM);
String samlString = idaAuthnRequestFromHubToStringTransformer.apply(authnRequestFromHub);
policyStubRule.aValidAuthnRequestFromHubToIdp(sessionId, new AuthnRequestFromHubContainerDto(samlString, nextLocationUri, false));
Response response = getResponseFromSamlProxy(Urls.SamlProxyUrls.SEND_AUTHN_REQUEST_API_RESOURCE, sessionId);
assertThat(response.readEntity(SamlMessageSenderHandler.SamlMessage.class).getPostEndpoint()).isEqualTo(nextLocationUri.toASCIIString());
}
use of uk.gov.ida.common.SessionId in project verify-hub by alphagov.
the class SamlMessageSenderApiResourceTest method sendSignedJsonAuthnResponseFromHub_shouldRespondWithNextLocation.
@Test
public void sendSignedJsonAuthnResponseFromHub_shouldRespondWithNextLocation() throws Exception {
SessionId sessionId = SessionId.createNewSessionId();
URI nextLocationUri = URI.create("http://blah");
String requestId = UUID.randomUUID().toString();
ResponseAssertionSigner responseAssertionSigner = new ResponseAssertionSigner(new SignatureFactory(new IdaKeyStoreCredentialRetriever(getKeyStore()), SIGNATURE_ALGORITHM, DIGEST_ALGORITHM));
Function<OutboundResponseFromHub, String> outboundResponseFromHubToStringTransformer = new HubTransformersFactory().getOutboundResponseFromHubToStringTransformer(new HardCodedKeyStore(HUB_ENTITY_ID), getKeyStore(), new IdpHardCodedEntityToEncryptForLocator(), responseAssertionSigner, 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());
}
use of uk.gov.ida.common.SessionId in project verify-hub by alphagov.
the class IdpAuthnResponseTranslatorResourceTest method shouldReturnOkWhenResponseIsSignedByAnIdp.
@Test
public void shouldReturnOkWhenResponseIsSignedByAnIdp() throws Exception {
final org.opensaml.saml.saml2.core.Response samlResponse = authnResponseFactory.aResponseFromIdpBuilder(STUB_IDP_ONE, "127.0.0.1").withDestination(IDP_RESPONSE_ENDPOINT).build();
final String saml = authnResponseFactory.transformResponseToSaml(samlResponse);
final SessionId sessionId = SessionId.createNewSessionId();
SamlAuthnResponseTranslatorDto dto = new SamlAuthnResponseTranslatorDto(saml, sessionId, "127.0.0.1", TEST_RP_MS);
Response response = postToSamlEngine(dto, samlEngineAppRule.getUri(Urls.SamlEngineUrls.TRANSLATE_IDP_AUTHN_RESPONSE_RESOURCE));
assertThat(response.getStatus()).isEqualTo(Response.Status.OK.getStatusCode());
}
use of uk.gov.ida.common.SessionId in project verify-hub by alphagov.
the class SamlProxySamlTransformationErrorExceptionMapper method handleException.
@Override
protected Response handleException(SamlTransformationErrorException exception) {
UUID errorId = UUID.randomUUID();
Optional<SessionId> sessionId = getSessionId();
if (sessionId.isPresent()) {
eventSinkMessageSender.audit(exception, errorId, sessionId.get());
} else {
eventSinkMessageSender.audit(exception, errorId, SessionId.NO_SESSION_CONTEXT_IN_ERROR);
}
levelLogger.log(exception.getLogLevel(), exception, errorId);
ErrorStatusDto auditedErrorStatus = ErrorStatusDto.createAuditedErrorStatus(errorId, getExceptionTypeForSamlException(exception));
return Response.serverError().entity(auditedErrorStatus).build();
}
Aggregations