Search in sources :

Example 6 with AttributeQueryContainerDto

use of uk.gov.ida.hub.policy.contracts.AttributeQueryContainerDto in project verify-hub by alphagov.

the class AuthnResponseFromIdpServiceTest method shouldSendRequestToMatchingServiceViaAttributeQueryServiceAndUpdateSessionStateWhenSuccessfulResponseIsReceived.

@Test
public void shouldSendRequestToMatchingServiceViaAttributeQueryServiceAndUpdateSessionStateWhenSuccessfulResponseIsReceived() {
    // Given
    final String msaEntityId = "a-msa-entity-id";
    LevelOfAssurance loaAchieved = LevelOfAssurance.LEVEL_2;
    stub(idpSelectedStateController.isRegistrationContext()).toReturn(REGISTERING);
    when(idpSelectedStateController.getMatchingServiceEntityId()).thenReturn(msaEntityId);
    InboundResponseFromIdpDto successResponseFromIdp = InboundResponseFromIdpDtoBuilder.successResponse(UUID.randomUUID().toString(), loaAchieved);
    SamlAuthnResponseTranslatorDto samlAuthnResponseTranslatorDto = SamlAuthnResponseTranslatorDtoBuilder.aSamlAuthnResponseTranslatorDto().build();
    when(samlAuthnResponseTranslatorDtoFactory.fromSamlAuthnResponseContainerDto(samlAuthnResponseContainerDto, msaEntityId)).thenReturn(samlAuthnResponseTranslatorDto);
    stub(samlEngineProxy.translateAuthnResponseFromIdp(any(SamlAuthnResponseTranslatorDto.class))).toReturn(successResponseFromIdp);
    AttributeQueryRequestDto attributeQueryRequestDto = AttributeQueryRequestBuilder.anAttributeQueryRequest().build();
    stub(idpSelectedStateController.createAttributeQuery(any(SuccessFromIdp.class))).toReturn(attributeQueryRequestDto);
    AttributeQueryContainerDto msaRequest = AttributeQueryContainerDtoBuilder.anAttributeQueryContainerDto().build();
    stub(samlEngineProxy.generateAttributeQuery(attributeQueryRequestDto)).toReturn(msaRequest);
    // When
    ResponseAction responseAction = service.receiveAuthnResponseFromIdp(sessionId, samlAuthnResponseContainerDto);
    // Then
    verify(samlAuthnResponseTranslatorDtoFactory).fromSamlAuthnResponseContainerDto(samlAuthnResponseContainerDto, msaEntityId);
    verify(attributeQueryService).sendAttributeQueryRequest(sessionId, attributeQueryRequestDto);
    verifyIdpStateControllerIsCalledWithRightDataOnSuccess(successResponseFromIdp);
    ResponseAction expectedResponseAction = ResponseAction.success(sessionId, REGISTERING, loaAchieved);
    assertThat(responseAction).isEqualToComparingFieldByField(expectedResponseAction);
}
Also used : LevelOfAssurance(uk.gov.ida.hub.policy.domain.LevelOfAssurance) SuccessFromIdp(uk.gov.ida.hub.policy.domain.SuccessFromIdp) AttributeQueryContainerDto(uk.gov.ida.hub.policy.contracts.AttributeQueryContainerDto) InboundResponseFromIdpDto(uk.gov.ida.hub.policy.domain.InboundResponseFromIdpDto) SamlAuthnResponseTranslatorDto(uk.gov.ida.hub.policy.contracts.SamlAuthnResponseTranslatorDto) AttributeQueryRequestDto(uk.gov.ida.hub.policy.contracts.AttributeQueryRequestDto) ResponseAction(uk.gov.ida.hub.policy.domain.ResponseAction) Test(org.junit.Test)

Example 7 with AttributeQueryContainerDto

use of uk.gov.ida.hub.policy.contracts.AttributeQueryContainerDto in project verify-hub by alphagov.

the class AuthnResponseFromCountryService method receiveAuthnResponseFromCountry.

public ResponseAction receiveAuthnResponseFromCountry(SessionId sessionId, SamlAuthnResponseContainerDto responseFromCountry) {
    CountrySelectedStateController stateController = (CountrySelectedStateController) sessionRepository.getStateController(sessionId, CountrySelectedState.class);
    String matchingServiceEntityId = stateController.getMatchingServiceEntityId();
    stateController.validateCountryIsIn(countriesService.getCountries(sessionId));
    SamlAuthnResponseTranslatorDto responseToTranslate = samlAuthnResponseTranslatorDtoFactory.fromSamlAuthnResponseContainerDto(responseFromCountry, matchingServiceEntityId);
    InboundResponseFromCountry translatedResponse = samlEngineProxy.translateAuthnResponseFromCountry(responseToTranslate);
    if (translatedResponse.getStatus() != IdpIdaStatus.Status.Success)
        return other(sessionId, false);
    validateSuccessfulResponse(stateController, translatedResponse);
    EidasAttributeQueryRequestDto eidasAttributeQueryRequestDto = getEidasAttributeQueryRequestDto(stateController, translatedResponse);
    stateController.transitionToEidasCycle0And1MatchRequestSentState(eidasAttributeQueryRequestDto, responseFromCountry.getPrincipalIPAddressAsSeenByHub(), translatedResponse.getIssuer());
    AttributeQueryContainerDto aqr = samlEngineProxy.generateEidasAttributeQuery(eidasAttributeQueryRequestDto);
    samlSoapProxyProxy.sendHubMatchingServiceRequest(sessionId, getAttributeQueryRequest(aqr));
    return ResponseAction.success(sessionId, false, LevelOfAssurance.LEVEL_2);
}
Also used : AttributeQueryContainerDto(uk.gov.ida.hub.policy.contracts.AttributeQueryContainerDto) InboundResponseFromCountry(uk.gov.ida.hub.policy.domain.InboundResponseFromCountry) SamlAuthnResponseTranslatorDto(uk.gov.ida.hub.policy.contracts.SamlAuthnResponseTranslatorDto) CountrySelectedState(uk.gov.ida.hub.policy.domain.state.CountrySelectedState) CountrySelectedStateController(uk.gov.ida.hub.policy.domain.controller.CountrySelectedStateController) EidasAttributeQueryRequestDto(uk.gov.ida.hub.policy.contracts.EidasAttributeQueryRequestDto)

Aggregations

AttributeQueryContainerDto (uk.gov.ida.hub.policy.contracts.AttributeQueryContainerDto)7 Test (org.junit.Test)3 EidasAttributeQueryRequestDto (uk.gov.ida.hub.policy.contracts.EidasAttributeQueryRequestDto)3 AttributeQueryContainerDtoBuilder.anAttributeQueryContainerDto (uk.gov.ida.hub.policy.builder.AttributeQueryContainerDtoBuilder.anAttributeQueryContainerDto)2 EidasAttributeQueryRequestDtoBuilder.anEidasAttributeQueryRequestDto (uk.gov.ida.hub.policy.builder.EidasAttributeQueryRequestDtoBuilder.anEidasAttributeQueryRequestDto)2 AttributeQueryRequestDto (uk.gov.ida.hub.policy.contracts.AttributeQueryRequestDto)2 SamlAuthnResponseTranslatorDto (uk.gov.ida.hub.policy.contracts.SamlAuthnResponseTranslatorDto)2 SuccessFromIdp (uk.gov.ida.hub.policy.domain.SuccessFromIdp)2 InboundResponseFromCountry (uk.gov.ida.hub.policy.domain.InboundResponseFromCountry)1 InboundResponseFromIdpDto (uk.gov.ida.hub.policy.domain.InboundResponseFromIdpDto)1 LevelOfAssurance (uk.gov.ida.hub.policy.domain.LevelOfAssurance)1 ResponseAction (uk.gov.ida.hub.policy.domain.ResponseAction)1 CountrySelectedStateController (uk.gov.ida.hub.policy.domain.controller.CountrySelectedStateController)1 CountrySelectedState (uk.gov.ida.hub.policy.domain.state.CountrySelectedState)1 AttributeQueryRequest (uk.gov.ida.hub.policy.proxy.AttributeQueryRequest)1