Search in sources :

Example 1 with State

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

the class CountriesService method setSelectedCountry.

public void setSelectedCountry(SessionId sessionId, String countryCode) {
    ensureTransactionSupportsEidas(sessionId);
    List<EidasCountryDto> supportedCountries = getCountries(sessionId);
    Optional<EidasCountryDto> selectedCountry = supportedCountries.stream().filter(country -> country.getSimpleId().equals(countryCode)).findFirst();
    if (!selectedCountry.isPresent()) {
        throw new EidasCountryNotSupportedException(sessionId, countryCode);
    }
    Class<? extends State> expectedStateClass = SessionStartedState.class;
    if (sessionRepository.isSessionInState(sessionId, CountrySelectedState.class)) {
        expectedStateClass = CountrySelectedState.class;
    }
    CountrySelectingStateController countrySelectingStateController = (CountrySelectingStateController) sessionRepository.getStateController(sessionId, expectedStateClass);
    countrySelectingStateController.selectCountry(selectedCountry.get().getEntityId());
}
Also used : SessionId(uk.gov.ida.hub.policy.domain.SessionId) TransactionsConfigProxy(uk.gov.ida.hub.policy.proxy.TransactionsConfigProxy) SessionStartedState(uk.gov.ida.hub.policy.domain.state.SessionStartedState) CountrySelectedState(uk.gov.ida.hub.policy.domain.state.CountrySelectedState) EidasCountryDto(uk.gov.ida.hub.policy.domain.EidasCountryDto) CountrySelectingStateController(uk.gov.ida.hub.policy.domain.controller.CountrySelectingStateController) Collectors(java.util.stream.Collectors) SessionRepository(uk.gov.ida.hub.policy.domain.SessionRepository) Inject(javax.inject.Inject) EidasCountryNotSupportedException(uk.gov.ida.hub.policy.exception.EidasCountryNotSupportedException) List(java.util.List) State(uk.gov.ida.hub.policy.domain.State) Optional(java.util.Optional) CountrySelectingStateController(uk.gov.ida.hub.policy.domain.controller.CountrySelectingStateController) EidasCountryNotSupportedException(uk.gov.ida.hub.policy.exception.EidasCountryNotSupportedException) EidasCountryDto(uk.gov.ida.hub.policy.domain.EidasCountryDto) SessionStartedState(uk.gov.ida.hub.policy.domain.state.SessionStartedState)

Example 2 with State

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

the class Cycle0And1MatchRequestSentStateControllerTest method getNextState_shouldReturnNoMatchStateWhenTransactionDoesNotSupportCycle3AndMatchingServiceReturnsNoMatchAndUserAccountCreationIsDisabled.

@Test
public void getNextState_shouldReturnNoMatchStateWhenTransactionDoesNotSupportCycle3AndMatchingServiceReturnsNoMatchAndUserAccountCreationIsDisabled() throws Exception {
    // Given
    when(transactionsConfigProxy.getMatchingProcess(TRANSACTION_ENTITY_ID)).thenReturn(new MatchingProcess(Optional.absent()));
    when(transactionsConfigProxy.getUserAccountCreationAttributes(TRANSACTION_ENTITY_ID)).thenReturn(Collections.emptyList());
    // When
    final State nextState = controller.getNextStateForNoMatch();
    // Then
    assertThat(nextState).isInstanceOf(NoMatchState.class);
}
Also used : NoMatchState(uk.gov.ida.hub.policy.domain.state.NoMatchState) SuccessfulMatchState(uk.gov.ida.hub.policy.domain.state.SuccessfulMatchState) Cycle0And1MatchRequestSentStateBuilder.aCycle0And1MatchRequestSentState(uk.gov.ida.hub.policy.builder.state.Cycle0And1MatchRequestSentStateBuilder.aCycle0And1MatchRequestSentState) AwaitingCycle3DataState(uk.gov.ida.hub.policy.domain.state.AwaitingCycle3DataState) State(uk.gov.ida.hub.policy.domain.State) Cycle0And1MatchRequestSentState(uk.gov.ida.hub.policy.domain.state.Cycle0And1MatchRequestSentState) UserAccountCreationRequestSentState(uk.gov.ida.hub.policy.domain.state.UserAccountCreationRequestSentState) MatchingProcess(uk.gov.ida.hub.policy.domain.MatchingProcess) Test(org.junit.Test)

Example 3 with State

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

the class Cycle0And1MatchRequestSentStateControllerTest method getNextState_shouldGetAwaitingCycle3DataStateWhenTransactionSupportsCycle3.

@Test
public void getNextState_shouldGetAwaitingCycle3DataStateWhenTransactionSupportsCycle3() {
    // Given
    when(transactionsConfigProxy.getMatchingProcess(TRANSACTION_ENTITY_ID)).thenReturn(matchingProcess);
    when(matchingProcess.getAttributeName()).thenReturn(Optional.of("somestring"));
    // When
    final State nextState = controller.getNextStateForNoMatch();
    // Then
    assertThat(nextState).isInstanceOf(AwaitingCycle3DataState.class);
    assertThat(((AwaitingCycle3DataState) nextState).getEncryptedMatchingDatasetAssertion()).isEqualTo(state.getEncryptedMatchingDatasetAssertion());
    verify(transactionsConfigProxy, times(0)).getUserAccountCreationAttributes(TRANSACTION_ENTITY_ID);
}
Also used : AwaitingCycle3DataState(uk.gov.ida.hub.policy.domain.state.AwaitingCycle3DataState) NoMatchState(uk.gov.ida.hub.policy.domain.state.NoMatchState) SuccessfulMatchState(uk.gov.ida.hub.policy.domain.state.SuccessfulMatchState) Cycle0And1MatchRequestSentStateBuilder.aCycle0And1MatchRequestSentState(uk.gov.ida.hub.policy.builder.state.Cycle0And1MatchRequestSentStateBuilder.aCycle0And1MatchRequestSentState) AwaitingCycle3DataState(uk.gov.ida.hub.policy.domain.state.AwaitingCycle3DataState) State(uk.gov.ida.hub.policy.domain.State) Cycle0And1MatchRequestSentState(uk.gov.ida.hub.policy.domain.state.Cycle0And1MatchRequestSentState) UserAccountCreationRequestSentState(uk.gov.ida.hub.policy.domain.state.UserAccountCreationRequestSentState) Test(org.junit.Test)

Example 4 with State

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

the class Cycle3MatchRequestSentStateControllerTest method getNextStateForNoMatch_shouldReturnNoMatchWhenNoAttributesArePresent.

@Test
public void getNextStateForNoMatch_shouldReturnNoMatchWhenNoAttributesArePresent() {
    Cycle3MatchRequestSentState state = aCycle3MatchRequestSentState().build();
    ImmutableList<UserAccountCreationAttribute> userAccountCreationAttributes = ImmutableList.of();
    when(transactionsConfigProxy.getUserAccountCreationAttributes("request issuer id")).thenReturn(userAccountCreationAttributes);
    Cycle3MatchRequestSentStateController controller = new Cycle3MatchRequestSentStateController(state, hubEventLogger, null, null, null, null, transactionsConfigProxy, null, null, null);
    State nextState = controller.getNextStateForNoMatch();
    assertThat(nextState).isInstanceOf(NoMatchState.class);
}
Also used : UserAccountCreationAttribute(uk.gov.ida.hub.policy.domain.UserAccountCreationAttribute) NoMatchState(uk.gov.ida.hub.policy.domain.state.NoMatchState) State(uk.gov.ida.hub.policy.domain.State) Cycle3MatchRequestSentState(uk.gov.ida.hub.policy.domain.state.Cycle3MatchRequestSentState) UserAccountCreationRequestSentState(uk.gov.ida.hub.policy.domain.state.UserAccountCreationRequestSentState) Cycle3MatchRequestSentStateBuilder.aCycle3MatchRequestSentState(uk.gov.ida.hub.policy.builder.state.Cycle3MatchRequestSentStateBuilder.aCycle3MatchRequestSentState) Cycle3MatchRequestSentState(uk.gov.ida.hub.policy.domain.state.Cycle3MatchRequestSentState) Cycle3MatchRequestSentStateBuilder.aCycle3MatchRequestSentState(uk.gov.ida.hub.policy.builder.state.Cycle3MatchRequestSentStateBuilder.aCycle3MatchRequestSentState) Test(org.junit.Test)

Example 5 with State

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

the class EidasCycle0And1MatchRequestSentStateControllerTest method shouldReturnEidasAwaitingCycle3DataState.

@Test
public void shouldReturnEidasAwaitingCycle3DataState() {
    when(transactionsConfigProxy.getMatchingProcess(state.getRequestIssuerEntityId())).thenReturn(new MatchingProcess(Optional.of("cycle3AttributeName")));
    doNothing().when(hubEventLogger).logWaitingForCycle3AttributesEvent(state.getSessionId(), state.getRequestIssuerEntityId(), state.getRequestId(), state.getSessionExpiryTimestamp());
    EidasAwaitingCycle3DataState expectedState = new EidasAwaitingCycle3DataState(state.getRequestId(), state.getRequestIssuerEntityId(), state.getSessionExpiryTimestamp(), state.getAssertionConsumerServiceUri(), state.getSessionId(), state.getTransactionSupportsEidas(), state.getIdentityProviderEntityId(), state.getMatchingServiceAdapterEntityId(), state.getRelayState(), state.getPersistentId(), state.getIdpLevelOfAssurance(), state.getEncryptedIdentityAssertion());
    State actualState = eidasCycle0And1MatchRequestSentStateController.getNextStateForNoMatch();
    assertThat(actualState).isEqualTo(expectedState);
}
Also used : EidasAwaitingCycle3DataState(uk.gov.ida.hub.policy.domain.state.EidasAwaitingCycle3DataState) NoMatchState(uk.gov.ida.hub.policy.domain.state.NoMatchState) EidasSuccessfulMatchState(uk.gov.ida.hub.policy.domain.state.EidasSuccessfulMatchState) EidasCycle0And1MatchRequestSentState(uk.gov.ida.hub.policy.domain.state.EidasCycle0And1MatchRequestSentState) EidasCycle0And1MatchRequestSentStateBuilder.anEidasCycle0And1MatchRequestSentState(uk.gov.ida.hub.policy.builder.state.EidasCycle0And1MatchRequestSentStateBuilder.anEidasCycle0And1MatchRequestSentState) State(uk.gov.ida.hub.policy.domain.State) EidasAwaitingCycle3DataState(uk.gov.ida.hub.policy.domain.state.EidasAwaitingCycle3DataState) MatchingProcess(uk.gov.ida.hub.policy.domain.MatchingProcess) Test(org.junit.Test)

Aggregations

State (uk.gov.ida.hub.policy.domain.State)15 Test (org.junit.Test)11 NoMatchState (uk.gov.ida.hub.policy.domain.state.NoMatchState)11 UserAccountCreationRequestSentState (uk.gov.ida.hub.policy.domain.state.UserAccountCreationRequestSentState)6 Cycle0And1MatchRequestSentState (uk.gov.ida.hub.policy.domain.state.Cycle0And1MatchRequestSentState)5 MatchingProcess (uk.gov.ida.hub.policy.domain.MatchingProcess)4 Cycle0And1MatchRequestSentStateBuilder.aCycle0And1MatchRequestSentState (uk.gov.ida.hub.policy.builder.state.Cycle0And1MatchRequestSentStateBuilder.aCycle0And1MatchRequestSentState)3 EidasCycle0And1MatchRequestSentStateBuilder.anEidasCycle0And1MatchRequestSentState (uk.gov.ida.hub.policy.builder.state.EidasCycle0And1MatchRequestSentStateBuilder.anEidasCycle0And1MatchRequestSentState)3 UserAccountCreationAttribute (uk.gov.ida.hub.policy.domain.UserAccountCreationAttribute)3 AbstractMatchRequestSentState (uk.gov.ida.hub.policy.domain.state.AbstractMatchRequestSentState)3 AbstractSuccessfulMatchState (uk.gov.ida.hub.policy.domain.state.AbstractSuccessfulMatchState)3 AwaitingCycle3DataState (uk.gov.ida.hub.policy.domain.state.AwaitingCycle3DataState)3 EidasAwaitingCycle3DataState (uk.gov.ida.hub.policy.domain.state.EidasAwaitingCycle3DataState)3 EidasCycle0And1MatchRequestSentState (uk.gov.ida.hub.policy.domain.state.EidasCycle0And1MatchRequestSentState)3 EidasSuccessfulMatchState (uk.gov.ida.hub.policy.domain.state.EidasSuccessfulMatchState)3 MatchingServiceRequestErrorState (uk.gov.ida.hub.policy.domain.state.MatchingServiceRequestErrorState)3 SessionStartedState (uk.gov.ida.hub.policy.domain.state.SessionStartedState)3 SuccessfulMatchState (uk.gov.ida.hub.policy.domain.state.SuccessfulMatchState)3 URI (java.net.URI)2 Cycle3MatchRequestSentStateBuilder.aCycle3MatchRequestSentState (uk.gov.ida.hub.policy.builder.state.Cycle3MatchRequestSentStateBuilder.aCycle3MatchRequestSentState)2