Search in sources :

Example 1 with AuthnResponseFromHubContainerDto

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;
}
Also used : AuthnResponseFromHubContainerDto(uk.gov.ida.hub.policy.contracts.AuthnResponseFromHubContainerDto) SamlMessageDto(uk.gov.ida.hub.policy.contracts.SamlMessageDto) RequestForErrorResponseFromHubDto(uk.gov.ida.hub.policy.contracts.RequestForErrorResponseFromHubDto) ResponseFromHub(uk.gov.ida.hub.policy.domain.ResponseFromHub)

Example 2 with 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());
}
Also used : AuthnResponseFromHubContainerDto(uk.gov.ida.hub.policy.contracts.AuthnResponseFromHubContainerDto) AuthnResponseFromHubContainerDtoBuilder.anAuthnResponseFromHubContainerDto(uk.gov.ida.hub.policy.builder.AuthnResponseFromHubContainerDtoBuilder.anAuthnResponseFromHubContainerDto) SamlMessageDto(uk.gov.ida.hub.policy.contracts.SamlMessageDto) SessionId(uk.gov.ida.hub.policy.domain.SessionId) SessionId.createNewSessionId(uk.gov.ida.hub.policy.domain.SessionId.createNewSessionId) ResponseFromHub(uk.gov.ida.hub.policy.domain.ResponseFromHub) Test(org.junit.Test)

Example 3 with AuthnResponseFromHubContainerDto

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);
}
Also used : Response(javax.ws.rs.core.Response) AuthnResponseFromHubContainerDto(uk.gov.ida.hub.policy.contracts.AuthnResponseFromHubContainerDto) AuthnResponseFromHubContainerDtoBuilder.anAuthnResponseFromHubContainerDto(uk.gov.ida.integrationtest.hub.policy.builders.AuthnResponseFromHubContainerDtoBuilder.anAuthnResponseFromHubContainerDto) SessionId(uk.gov.ida.hub.policy.domain.SessionId) URI(java.net.URI) Test(org.junit.Test)

Example 4 with AuthnResponseFromHubContainerDto

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);
}
Also used : Response(javax.ws.rs.core.Response) AuthnResponseFromHubContainerDto(uk.gov.ida.hub.policy.contracts.AuthnResponseFromHubContainerDto) AuthnResponseFromHubContainerDtoBuilder.anAuthnResponseFromHubContainerDto(uk.gov.ida.integrationtest.hub.policy.builders.AuthnResponseFromHubContainerDtoBuilder.anAuthnResponseFromHubContainerDto) SessionId(uk.gov.ida.hub.policy.domain.SessionId) URI(java.net.URI) Test(org.junit.Test)

Example 5 with AuthnResponseFromHubContainerDto

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);
}
Also used : AuthnResponseFromHubContainerDto(uk.gov.ida.hub.policy.contracts.AuthnResponseFromHubContainerDto) AuthnResponseFromHubContainerDtoBuilder.anAuthnResponseFromHubContainerDto(uk.gov.ida.hub.policy.builder.AuthnResponseFromHubContainerDtoBuilder.anAuthnResponseFromHubContainerDto) SessionId(uk.gov.ida.hub.policy.domain.SessionId) SessionId.createNewSessionId(uk.gov.ida.hub.policy.domain.SessionId.createNewSessionId) ResponseFromHub(uk.gov.ida.hub.policy.domain.ResponseFromHub) Test(org.junit.Test)

Aggregations

AuthnResponseFromHubContainerDto (uk.gov.ida.hub.policy.contracts.AuthnResponseFromHubContainerDto)6 Test (org.junit.Test)5 SessionId (uk.gov.ida.hub.policy.domain.SessionId)5 URI (java.net.URI)3 Response (javax.ws.rs.core.Response)3 SamlMessageDto (uk.gov.ida.hub.policy.contracts.SamlMessageDto)3 ResponseFromHub (uk.gov.ida.hub.policy.domain.ResponseFromHub)3 AuthnResponseFromHubContainerDtoBuilder.anAuthnResponseFromHubContainerDto (uk.gov.ida.hub.policy.builder.AuthnResponseFromHubContainerDtoBuilder.anAuthnResponseFromHubContainerDto)2 SessionId.createNewSessionId (uk.gov.ida.hub.policy.domain.SessionId.createNewSessionId)2 AuthnResponseFromHubContainerDtoBuilder.anAuthnResponseFromHubContainerDto (uk.gov.ida.integrationtest.hub.policy.builders.AuthnResponseFromHubContainerDtoBuilder.anAuthnResponseFromHubContainerDto)2 RequestForErrorResponseFromHubDto (uk.gov.ida.hub.policy.contracts.RequestForErrorResponseFromHubDto)1