use of uk.gov.ida.hub.policy.contracts.AuthnResponseFromHubContainerDto in project verify-hub by alphagov.
the class SessionService method getRpErrorResponse.
public AuthnResponseFromHubContainerDto getRpErrorResponse(SessionId sessionId) {
getSessionIfItExists(sessionId);
final ResponseFromHub errorResponseFromHub = authnRequestHandler.getErrorResponseFromHub(sessionId);
final RequestForErrorResponseFromHubDto requestForErrorResponseFromHubDto = new RequestForErrorResponseFromHubDto(errorResponseFromHub.getAuthnRequestIssuerEntityId(), errorResponseFromHub.getResponseId(), errorResponseFromHub.getInResponseTo(), errorResponseFromHub.getAssertionConsumerServiceUri(), errorResponseFromHub.getStatus());
final SamlMessageDto samlMessageDto = samlEngineProxy.generateErrorResponseFromHub(requestForErrorResponseFromHubDto);
final AuthnResponseFromHubContainerDto authnResponseFromHubContainerDto = new AuthnResponseFromHubContainerDto(samlMessageDto.getSamlMessage(), errorResponseFromHub.getAssertionConsumerServiceUri(), errorResponseFromHub.getRelayState(), errorResponseFromHub.getResponseId());
return authnResponseFromHubContainerDto;
}
use of uk.gov.ida.hub.policy.contracts.AuthnResponseFromHubContainerDto in project verify-hub by alphagov.
the class SessionServiceTest method sendErrorResponseFromHub_shouldReturnDtoWithSamlRequestPostLocationAndRelayState.
@Test
public void sendErrorResponseFromHub_shouldReturnDtoWithSamlRequestPostLocationAndRelayState() throws Exception {
SessionId sessionId = createNewSessionId();
when(sessionRepository.sessionExists(sessionId)).thenReturn(true);
ResponseFromHub responseFromHub = aResponseFromHubDto().withRelayState("relayState").build();
when(authnRequestHandler.getErrorResponseFromHub(sessionId)).thenReturn(responseFromHub);
final SamlMessageDto samlMessageDto = new SamlMessageDto("saml");
when(samlEngineProxy.generateErrorResponseFromHub(any())).thenReturn(samlMessageDto);
AuthnResponseFromHubContainerDto dto = service.getRpErrorResponse(sessionId);
assertThat(dto.getSamlResponse()).isEqualTo(samlMessageDto.getSamlMessage());
assertThat(dto.getPostEndpoint()).isEqualTo(responseFromHub.getAssertionConsumerServiceUri());
assertThat(dto.getRelayState()).isEqualTo(responseFromHub.getRelayState());
assertThat(dto.getResponseId()).isEqualTo(responseFromHub.getResponseId());
}
use of uk.gov.ida.hub.policy.contracts.AuthnResponseFromHubContainerDto in project verify-hub by alphagov.
the class SessionResourceIntegrationTest method shouldGetRpResponseGivenASessionInEidasSuccessfulMatchStateExists.
@Test
public void shouldGetRpResponseGivenASessionInEidasSuccessfulMatchStateExists() throws JsonProcessingException {
SessionId sessionId = SessionId.createNewSessionId();
Response sessionCreatedResponse = TestSessionResourceHelper.createSessionInEidasSuccessfulMatchState(sessionId, rpEntityId, countryEntityId, client, policy.uri(UriBuilder.fromPath(TEST_SESSION_RESOURCE_PATH + EIDAS_SUCCESSFUL_MATCH_STATE).build().toASCIIString()));
assertThat(sessionCreatedResponse.getStatus()).isEqualTo(Response.Status.OK.getStatusCode());
AuthnResponseFromHubContainerDto expectedAuthnResponseFromHub = anAuthnResponseFromHubContainerDto().build();
samlEngineStub.setUpStubForAuthnResponseGenerate(expectedAuthnResponseFromHub);
URI rpAuthResponseUri = UriBuilder.fromPath(Urls.PolicyUrls.RP_AUTHN_RESPONSE_RESOURCE).build(sessionId);
Response responseForRp = client.target(policy.uri(rpAuthResponseUri.toASCIIString())).request().get();
assertThat(responseForRp.getStatus()).isEqualTo(Response.Status.OK.getStatusCode());
AuthnResponseFromHubContainerDto authnResponseFromHub = responseForRp.readEntity(AuthnResponseFromHubContainerDto.class);
assertThat(authnResponseFromHub).isEqualToComparingFieldByField(expectedAuthnResponseFromHub);
}
use of uk.gov.ida.hub.policy.contracts.AuthnResponseFromHubContainerDto in project verify-hub by alphagov.
the class SessionResourceIntegrationTest method shouldGetRpResponseGivenASessionExistsInPolicy.
@Test
public void shouldGetRpResponseGivenASessionExistsInPolicy() throws JsonProcessingException {
// Given
SessionId sessionId = SessionId.createNewSessionId();
configStub.setupStubForEnabledIdps(rpEntityId, SIGNING_IN, REQUESTED_LOA, singletonList(idpEntityId));
Response sessionCreatedResponse = TestSessionResourceHelper.createSessionInSuccessfulMatchState(sessionId, rpEntityId, idpEntityId, client, policy.uri(UriBuilder.fromPath(TEST_SESSION_RESOURCE_PATH + SUCCESSFUL_MATCH_STATE).build().toASCIIString()));
assertThat(sessionCreatedResponse.getStatus()).isEqualTo(Response.Status.OK.getStatusCode());
AuthnResponseFromHubContainerDto expectedAuthnResponseFromHub = anAuthnResponseFromHubContainerDto().build();
samlEngineStub.setUpStubForAuthnResponseGenerate(expectedAuthnResponseFromHub);
// When
URI rpAuthResponseUri = UriBuilder.fromPath(Urls.PolicyUrls.RP_AUTHN_RESPONSE_RESOURCE).build(sessionId);
Response responseForRp = client.target(policy.uri(rpAuthResponseUri.toASCIIString())).request().get();
// Then
assertThat(responseForRp.getStatus()).isEqualTo(Response.Status.OK.getStatusCode());
AuthnResponseFromHubContainerDto authnResponseFromHub = responseForRp.readEntity(AuthnResponseFromHubContainerDto.class);
assertThat(authnResponseFromHub).isEqualToComparingFieldByField(expectedAuthnResponseFromHub);
}
use of uk.gov.ida.hub.policy.contracts.AuthnResponseFromHubContainerDto in project verify-hub by alphagov.
the class SessionServiceTest method shouldUpdateSessionStateAndCallSamlEngineWhenResponseFromHubIsRequested.
@Test
public void shouldUpdateSessionStateAndCallSamlEngineWhenResponseFromHubIsRequested() {
// Given
SessionId sessionId = createNewSessionId();
when(sessionRepository.sessionExists(sessionId)).thenReturn(true);
ResponseFromHub responseFromHub = aResponseFromHubDto().build();
when(authnRequestHandler.getResponseFromHub(sessionId)).thenReturn(responseFromHub);
AuthnResponseFromHubContainerDto expected = anAuthnResponseFromHubContainerDto().build();
when(samlEngineProxy.generateRpAuthnResponse(responseFromHub)).thenReturn(expected);
// When
AuthnResponseFromHubContainerDto actual = service.getRpAuthnResponse(sessionId);
// Then
assertThat(actual).isEqualTo(expected);
}
Aggregations