Search in sources :

Example 6 with InboundResponseFromIdpDto

use of uk.gov.ida.hub.policy.domain.InboundResponseFromIdpDto in project verify-hub by alphagov.

the class AuthnResponseFromIdpServiceTest method mapFailedUpliftResponseFromIDP.

@Test
public void mapFailedUpliftResponseFromIDP() {
    // Given
    stub(idpSelectedStateController.isRegistrationContext()).toReturn(REGISTERING);
    InboundResponseFromIdpDto noAuthenticationContextResponse = InboundResponseFromIdpDtoBuilder.errorResponse(UUID.randomUUID().toString(), IdpIdaStatus.Status.UpliftFailed);
    stub(samlEngineProxy.translateAuthnResponseFromIdp(any(SamlAuthnResponseTranslatorDto.class))).toReturn(noAuthenticationContextResponse);
    // When
    ResponseAction responseAction = service.receiveAuthnResponseFromIdp(sessionId, samlAuthnResponseContainerDto);
    // Then
    verify(samlEngineProxy).translateAuthnResponseFromIdp(any(SamlAuthnResponseTranslatorDto.class));
    verifyNoMoreInteractions(samlEngineProxy);
    verify(idpSelectedStateController).handleNoAuthenticationContextResponseFromIdp(any(AuthenticationErrorResponse.class));
    ResponseAction expectedResponseAction = ResponseAction.failedUplift(sessionId, REGISTERING);
    assertThat(responseAction).isEqualToComparingFieldByField(expectedResponseAction);
    verifyIdpStateControllerIsCalledWithRightDataOnNonFraudNoAuthenticationContext(noAuthenticationContextResponse);
}
Also used : InboundResponseFromIdpDto(uk.gov.ida.hub.policy.domain.InboundResponseFromIdpDto) AuthenticationErrorResponse(uk.gov.ida.hub.policy.domain.AuthenticationErrorResponse) AuthenticationErrorResponseBuilder.anAuthenticationErrorResponse(uk.gov.ida.hub.policy.builder.domain.AuthenticationErrorResponseBuilder.anAuthenticationErrorResponse) SamlAuthnResponseTranslatorDto(uk.gov.ida.hub.policy.contracts.SamlAuthnResponseTranslatorDto) ResponseAction(uk.gov.ida.hub.policy.domain.ResponseAction) Test(org.junit.Test)

Example 7 with InboundResponseFromIdpDto

use of uk.gov.ida.hub.policy.domain.InboundResponseFromIdpDto 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 8 with InboundResponseFromIdpDto

use of uk.gov.ida.hub.policy.domain.InboundResponseFromIdpDto in project verify-hub by alphagov.

the class AuthnResponseFromIdpServiceTest method shouldOnlyUpdateSessionStateWhenANonFraudAuthenticationFailedResponseIsReceived.

@Test
public void shouldOnlyUpdateSessionStateWhenANonFraudAuthenticationFailedResponseIsReceived() {
    // Given
    stub(idpSelectedStateController.isRegistrationContext()).toReturn(REGISTERING);
    InboundResponseFromIdpDto authenticationFailedResponse = InboundResponseFromIdpDtoBuilder.errorResponse(UUID.randomUUID().toString(), IdpIdaStatus.Status.AuthenticationFailed);
    stub(samlEngineProxy.translateAuthnResponseFromIdp(any(SamlAuthnResponseTranslatorDto.class))).toReturn(authenticationFailedResponse);
    // When
    ResponseAction responseAction = service.receiveAuthnResponseFromIdp(sessionId, samlAuthnResponseContainerDto);
    // Then
    verify(samlEngineProxy).translateAuthnResponseFromIdp(any(SamlAuthnResponseTranslatorDto.class));
    verifyNoMoreInteractions(samlEngineProxy);
    ResponseAction expectedResponseAction = ResponseAction.other(sessionId, REGISTERING);
    assertThat(responseAction).isEqualToComparingFieldByField(expectedResponseAction);
    verifyIdpStateControllerIsCalledWithRightDataOnNonFraudAuthenticationFailed(authenticationFailedResponse);
}
Also used : InboundResponseFromIdpDto(uk.gov.ida.hub.policy.domain.InboundResponseFromIdpDto) SamlAuthnResponseTranslatorDto(uk.gov.ida.hub.policy.contracts.SamlAuthnResponseTranslatorDto) ResponseAction(uk.gov.ida.hub.policy.domain.ResponseAction) Test(org.junit.Test)

Example 9 with InboundResponseFromIdpDto

use of uk.gov.ida.hub.policy.domain.InboundResponseFromIdpDto in project verify-hub by alphagov.

the class AuthnResponseFromIdpService method receiveAuthnResponseFromIdp.

public ResponseAction receiveAuthnResponseFromIdp(SessionId sessionId, SamlAuthnResponseContainerDto samlResponseDto) {
    IdpSelectedStateController idpSelectedController = (IdpSelectedStateController) sessionRepository.getStateController(sessionId, IdpSelectedState.class);
    String matchingServiceEntityId = idpSelectedController.getMatchingServiceEntityId();
    final SamlAuthnResponseTranslatorDto samlAuthnResponseTranslatorDto = samlAuthnResponseTranslatorDtoFactory.fromSamlAuthnResponseContainerDto(samlResponseDto, matchingServiceEntityId);
    final InboundResponseFromIdpDto idaResponseFromIdpDto = samlEngineProxy.translateAuthnResponseFromIdp(samlAuthnResponseTranslatorDto);
    final String principalIPAddressAsSeenByHub = samlResponseDto.getPrincipalIPAddressAsSeenByHub();
    ResponseAction responseAction;
    if (isFraudulent(idaResponseFromIdpDto)) {
        responseAction = handleFraudResponse(idaResponseFromIdpDto, sessionId, principalIPAddressAsSeenByHub, idpSelectedController);
    } else {
        responseAction = handleNonFraudResponse(idaResponseFromIdpDto, sessionId, principalIPAddressAsSeenByHub, idpSelectedController);
    }
    return responseAction;
}
Also used : IdpSelectedStateController(uk.gov.ida.hub.policy.domain.controller.IdpSelectedStateController) InboundResponseFromIdpDto(uk.gov.ida.hub.policy.domain.InboundResponseFromIdpDto) SamlAuthnResponseTranslatorDto(uk.gov.ida.hub.policy.contracts.SamlAuthnResponseTranslatorDto) IdpSelectedState(uk.gov.ida.hub.policy.domain.state.IdpSelectedState) ResponseAction(uk.gov.ida.hub.policy.domain.ResponseAction)

Example 10 with InboundResponseFromIdpDto

use of uk.gov.ida.hub.policy.domain.InboundResponseFromIdpDto in project verify-hub by alphagov.

the class MatchingServiceResourcesIntegrationTest method anAuthnResponseFromIdpWasReceivedAndMatchingRequestSent.

private void anAuthnResponseFromIdpWasReceivedAndMatchingRequestSent(SessionId sessionId) throws JsonProcessingException {
    final URI policyUri = policy.uri(UriBuilder.fromPath(Urls.PolicyUrls.IDP_AUTHN_RESPONSE_RESOURCE).build(sessionId).getPath());
    SamlAuthnResponseContainerDto samlAuthnResponseContainerDto = new SamlAuthnResponseContainerDto("saml-response", new SessionId(sessionId.getSessionId()), "principal-ip-address");
    InboundResponseFromIdpDto inboundResponseFromIdpDto = InboundResponseFromIdpDtoBuilder.successResponse(idpEntityId, LEVEL_2);
    configStub.setUpStubForMatchingServiceRequest(rpEntityId, msaEntityId);
    samlEngineStub.setupStubForAttributeQueryRequest(AttributeQueryContainerDtoBuilder.anAttributeQueryContainerDto().build());
    samlEngineStub.setupStubForIdpAuthnResponseTranslate(inboundResponseFromIdpDto);
    samlSoapProxyProxyStubRule.setUpStubForSendHubMatchingServiceRequest(sessionId);
    postResponse(policyUri, samlAuthnResponseContainerDto);
}
Also used : InboundResponseFromIdpDto(uk.gov.ida.hub.policy.domain.InboundResponseFromIdpDto) SamlAuthnResponseContainerDto(uk.gov.ida.hub.policy.contracts.SamlAuthnResponseContainerDto) URI(java.net.URI) SessionId(uk.gov.ida.hub.policy.domain.SessionId)

Aggregations

InboundResponseFromIdpDto (uk.gov.ida.hub.policy.domain.InboundResponseFromIdpDto)10 SamlAuthnResponseTranslatorDto (uk.gov.ida.hub.policy.contracts.SamlAuthnResponseTranslatorDto)9 ResponseAction (uk.gov.ida.hub.policy.domain.ResponseAction)9 Test (org.junit.Test)8 AuthenticationErrorResponseBuilder.anAuthenticationErrorResponse (uk.gov.ida.hub.policy.builder.domain.AuthenticationErrorResponseBuilder.anAuthenticationErrorResponse)3 AuthenticationErrorResponse (uk.gov.ida.hub.policy.domain.AuthenticationErrorResponse)3 URI (java.net.URI)1 RequesterErrorResponseBuilder.aRequesterErrorResponse (uk.gov.ida.hub.policy.builder.domain.RequesterErrorResponseBuilder.aRequesterErrorResponse)1 AttributeQueryContainerDto (uk.gov.ida.hub.policy.contracts.AttributeQueryContainerDto)1 AttributeQueryRequestDto (uk.gov.ida.hub.policy.contracts.AttributeQueryRequestDto)1 SamlAuthnResponseContainerDto (uk.gov.ida.hub.policy.contracts.SamlAuthnResponseContainerDto)1 LevelOfAssurance (uk.gov.ida.hub.policy.domain.LevelOfAssurance)1 RequesterErrorResponse (uk.gov.ida.hub.policy.domain.RequesterErrorResponse)1 SessionId (uk.gov.ida.hub.policy.domain.SessionId)1 SuccessFromIdp (uk.gov.ida.hub.policy.domain.SuccessFromIdp)1 IdpSelectedStateController (uk.gov.ida.hub.policy.domain.controller.IdpSelectedStateController)1 IdpSelectedState (uk.gov.ida.hub.policy.domain.state.IdpSelectedState)1