Search in sources :

Example 1 with AttributeQueryRequestDto

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

the class AuthnResponseFromIdpService method handleSuccessResponse.

private ResponseAction handleSuccessResponse(InboundResponseFromIdpDto inboundResponseFromIdpDto, SessionId sessionId, String principalIPAddressAsSeenByHub, IdpSelectedStateController idpSelectedStateController) {
    LevelOfAssurance loaAchieved = inboundResponseFromIdpDto.getLevelOfAssurance().get();
    SuccessFromIdp successFromIdp = new SuccessFromIdp(inboundResponseFromIdpDto.getIssuer(), inboundResponseFromIdpDto.getEncryptedMatchingDatasetAssertion().get(), inboundResponseFromIdpDto.getAuthnStatementAssertionBlob().get(), new PersistentId(inboundResponseFromIdpDto.getPersistentId().get()), loaAchieved, principalIPAddressAsSeenByHub, inboundResponseFromIdpDto.getPrincipalIpAddressAsSeenByIdp());
    AttributeQueryRequestDto attributeQuery = idpSelectedStateController.createAttributeQuery(successFromIdp);
    idpSelectedStateController.handleSuccessResponseFromIdp(successFromIdp);
    attributeQueryService.sendAttributeQueryRequest(sessionId, attributeQuery);
    return success(sessionId, idpSelectedStateController.isRegistrationContext(), loaAchieved);
}
Also used : LevelOfAssurance(uk.gov.ida.hub.policy.domain.LevelOfAssurance) SuccessFromIdp(uk.gov.ida.hub.policy.domain.SuccessFromIdp) AttributeQueryRequestDto(uk.gov.ida.hub.policy.contracts.AttributeQueryRequestDto) PersistentId(uk.gov.ida.hub.policy.domain.PersistentId)

Example 2 with AttributeQueryRequestDto

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

the class Cycle0And1MatchRequestSentStateController method getNextStateForNoMatch.

@Override
protected State getNextStateForNoMatch() {
    Optional<String> selfAssertedAttributeName = transactionsConfigProxy.getMatchingProcess(state.getRequestIssuerEntityId()).getAttributeName();
    if (selfAssertedAttributeName.isPresent()) {
        hubEventLogger.logWaitingForCycle3AttributesEvent(state.getSessionId(), state.getRequestIssuerEntityId(), state.getRequestId(), state.getSessionExpiryTimestamp());
        return getAwaitingCycle3DataState();
    }
    List<UserAccountCreationAttribute> userAccountCreationAttributes = transactionsConfigProxy.getUserAccountCreationAttributes(state.getRequestIssuerEntityId());
    if (!userAccountCreationAttributes.isEmpty()) {
        AttributeQueryRequestDto attributeQueryRequestDto = createAttributeQuery(userAccountCreationAttributes);
        return handleUserAccountCreationRequestAndGenerateState(attributeQueryRequestDto);
    }
    hubEventLogger.logCycle01NoMatchEvent(state.getSessionId(), state.getRequestIssuerEntityId(), state.getRequestId(), state.getSessionExpiryTimestamp());
    return getNoMatchState();
}
Also used : UserAccountCreationAttribute(uk.gov.ida.hub.policy.domain.UserAccountCreationAttribute) AttributeQueryRequestDto(uk.gov.ida.hub.policy.contracts.AttributeQueryRequestDto)

Example 3 with AttributeQueryRequestDto

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

the class Cycle3MatchRequestSentStateController method getNextStateForNoMatch.

@Override
protected State getNextStateForNoMatch() {
    List<UserAccountCreationAttribute> userAccountCreationAttributes = transactionsConfigProxy.getUserAccountCreationAttributes(state.getRequestIssuerEntityId());
    if (!userAccountCreationAttributes.isEmpty()) {
        AttributeQueryRequestDto attributeQueryRequestDto = createAttributeQuery(userAccountCreationAttributes);
        return handleUserAccountCreationRequestAndGenerateState(attributeQueryRequestDto);
    }
    hubEventLogger.logCycle3NoMatchEvent(state.getSessionId(), state.getRequestIssuerEntityId(), state.getSessionExpiryTimestamp(), state.getRequestId());
    return getNoMatchState();
}
Also used : UserAccountCreationAttribute(uk.gov.ida.hub.policy.domain.UserAccountCreationAttribute) AttributeQueryRequestDto(uk.gov.ida.hub.policy.contracts.AttributeQueryRequestDto)

Example 4 with AttributeQueryRequestDto

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

the class Cycle3MatchRequestSentStateControllerTest method shouldReturnUserAccountCreationRequestSentStateForNoMatchWhenAttributesArePresent.

@Test
public void shouldReturnUserAccountCreationRequestSentStateForNoMatchWhenAttributesArePresent() {
    ArgumentCaptor<UserAccountCreationRequestSentState> capturedState = ArgumentCaptor.forClass(UserAccountCreationRequestSentState.class);
    ArgumentCaptor<EventSinkHubEvent> eventSinkArgumentCaptor = ArgumentCaptor.forClass(EventSinkHubEvent.class);
    URI userAccountCreationUri = URI.create("a-test-user-account-creation-uri");
    Cycle3MatchRequestSentState state = aCycle3MatchRequestSentState().build();
    List<UserAccountCreationAttribute> userAccountCreationAttributes = List.of(UserAccountCreationAttribute.DATE_OF_BIRTH);
    String transactionEntityId = "request issuer id";
    when(transactionsConfigProxy.getUserAccountCreationAttributes(transactionEntityId)).thenReturn(userAccountCreationAttributes);
    when(matchingServiceConfigProxy.getMatchingService(anyString())).thenReturn(aMatchingServiceConfigEntityDataDto().withUserAccountCreationUri(userAccountCreationUri).build());
    Cycle3MatchRequestSentStateController controller = new Cycle3MatchRequestSentStateController(state, hubEventLogger, stateTransitionAction, policyConfiguration, null, null, transactionsConfigProxy, matchingServiceConfigProxy, assertionRestrictionFactory, attributeQueryService);
    controller.transitionToNextStateForNoMatchResponse();
    verify(eventSinkProxy, times(1)).logHubEvent(eventSinkArgumentCaptor.capture());
    assertThat(eventSinkArgumentCaptor.getValue().getEventType()).isEqualTo(EventSinkHubEventConstants.EventTypes.SESSION_EVENT);
    assertThat(eventSinkArgumentCaptor.getValue().getDetails().get(EventDetailsKey.session_event_type)).isEqualTo(USER_ACCOUNT_CREATION_REQUEST_SENT);
    assertThat(eventSinkArgumentCaptor.getValue().getSessionId()).isEqualTo(state.getSessionId().toString());
    assertThat(eventSinkArgumentCaptor.getValue().getDetails().get(EventDetailsKey.request_id)).isEqualTo(state.getRequestId());
    assertThat(eventSinkArgumentCaptor.getValue().getOriginatingService()).isEqualTo(serviceInfo.getName());
    verify(stateTransitionAction).transitionTo(capturedState.capture());
    verify(attributeQueryService).sendAttributeQueryRequest(eq(capturedState.getValue().getSessionId()), attributeQueryRequestCaptor.capture());
    AttributeQueryRequestDto actualAttributeQueryRequestDto = attributeQueryRequestCaptor.getValue();
    assertThat(actualAttributeQueryRequestDto.getAttributeQueryUri()).isEqualTo(userAccountCreationUri);
    assertThat(actualAttributeQueryRequestDto.getUserAccountCreationAttributes()).isEqualTo(Optional.ofNullable(userAccountCreationAttributes));
    assertThat(actualAttributeQueryRequestDto.getEncryptedMatchingDatasetAssertion()).isEqualTo(state.getEncryptedMatchingDatasetAssertion());
    assertThat(capturedState.getValue()).isInstanceOf(UserAccountCreationRequestSentState.class);
}
Also used : UserAccountCreationAttribute(uk.gov.ida.hub.policy.domain.UserAccountCreationAttribute) Cycle3MatchRequestSentState(uk.gov.ida.hub.policy.domain.state.Cycle3MatchRequestSentState) Cycle3MatchRequestSentStateBuilder.aCycle3MatchRequestSentState(uk.gov.ida.hub.policy.builder.state.Cycle3MatchRequestSentStateBuilder.aCycle3MatchRequestSentState) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) AttributeQueryRequestDto(uk.gov.ida.hub.policy.contracts.AttributeQueryRequestDto) UserAccountCreationRequestSentState(uk.gov.ida.hub.policy.domain.state.UserAccountCreationRequestSentState) URI(java.net.URI) EventSinkHubEvent(uk.gov.ida.hub.policy.domain.EventSinkHubEvent) Test(org.junit.jupiter.api.Test)

Example 5 with AttributeQueryRequestDto

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

the class Cycle0And1MatchRequestSentStateControllerTest method shouldReturnUserAccountCreationRequestSentStateWhenNoMatchAndTransactionDoesNotSupportCycle3AndSupportsUserAccountCreation.

@Test
public void shouldReturnUserAccountCreationRequestSentStateWhenNoMatchAndTransactionDoesNotSupportCycle3AndSupportsUserAccountCreation() {
    URI userAccountCreationUri = URI.create("a-test-user-account-creation-uri");
    List<UserAccountCreationAttribute> userAccountCreationAttributes = singletonList(UserAccountCreationAttribute.DATE_OF_BIRTH);
    final ArgumentCaptor<UserAccountCreationRequestSentState> capturedState = ArgumentCaptor.forClass(UserAccountCreationRequestSentState.class);
    when(transactionsConfigProxy.getMatchingProcess(TRANSACTION_ENTITY_ID)).thenReturn(new MatchingProcess(Optional.empty()));
    when(transactionsConfigProxy.getUserAccountCreationAttributes(TRANSACTION_ENTITY_ID)).thenReturn(userAccountCreationAttributes);
    when(matchingServiceConfigProxy.getMatchingService(anyString())).thenReturn(aMatchingServiceConfigEntityDataDto().withUserAccountCreationUri(userAccountCreationUri).build());
    controller.transitionToNextStateForNoMatchResponse();
    verify(stateTransitionAction).transitionTo(capturedState.capture());
    verify(hubEventLogger).logMatchingServiceUserAccountCreationRequestSentEvent(state.getSessionId(), TRANSACTION_ENTITY_ID, state.getSessionExpiryTimestamp(), state.getRequestId());
    verify(attributeQueryService).sendAttributeQueryRequest(eq(capturedState.getValue().getSessionId()), attributeQueryRequestCaptor.capture());
    AttributeQueryRequestDto actualAttributeQueryRequestDto = attributeQueryRequestCaptor.getValue();
    assertThat(actualAttributeQueryRequestDto.getAttributeQueryUri()).isEqualTo(userAccountCreationUri);
    assertThat(actualAttributeQueryRequestDto.getUserAccountCreationAttributes()).isEqualTo(Optional.ofNullable(userAccountCreationAttributes));
    assertThat(capturedState.getValue()).isInstanceOf(UserAccountCreationRequestSentState.class);
}
Also used : UserAccountCreationAttribute(uk.gov.ida.hub.policy.domain.UserAccountCreationAttribute) MatchingProcess(uk.gov.ida.hub.policy.domain.MatchingProcess) AttributeQueryRequestDto(uk.gov.ida.hub.policy.contracts.AttributeQueryRequestDto) URI(java.net.URI) UserAccountCreationRequestSentState(uk.gov.ida.hub.policy.domain.state.UserAccountCreationRequestSentState) Test(org.junit.jupiter.api.Test)

Aggregations

AttributeQueryRequestDto (uk.gov.ida.hub.policy.contracts.AttributeQueryRequestDto)15 UserAccountCreationAttribute (uk.gov.ida.hub.policy.domain.UserAccountCreationAttribute)8 Test (org.junit.jupiter.api.Test)6 URI (java.net.URI)4 LevelOfAssurance (uk.gov.ida.hub.policy.domain.LevelOfAssurance)4 SuccessFromIdp (uk.gov.ida.hub.policy.domain.SuccessFromIdp)4 UserAccountCreationRequestSentState (uk.gov.ida.hub.policy.domain.state.UserAccountCreationRequestSentState)4 Test (org.junit.Test)3 AttributeQueryContainerDto (uk.gov.ida.hub.policy.contracts.AttributeQueryContainerDto)3 Cycle3MatchRequestSentStateBuilder.aCycle3MatchRequestSentState (uk.gov.ida.hub.policy.builder.state.Cycle3MatchRequestSentStateBuilder.aCycle3MatchRequestSentState)2 EventSinkHubEvent (uk.gov.ida.hub.policy.domain.EventSinkHubEvent)2 InboundResponseFromIdpDto (uk.gov.ida.hub.policy.domain.InboundResponseFromIdpDto)2 MatchingProcess (uk.gov.ida.hub.policy.domain.MatchingProcess)2 PersistentId (uk.gov.ida.hub.policy.domain.PersistentId)2 ResponseAction (uk.gov.ida.hub.policy.domain.ResponseAction)2 State (uk.gov.ida.hub.policy.domain.State)2 Cycle3MatchRequestSentState (uk.gov.ida.hub.policy.domain.state.Cycle3MatchRequestSentState)2 NoMatchState (uk.gov.ida.hub.policy.domain.state.NoMatchState)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1 Matchers.anyString (org.mockito.Matchers.anyString)1