Search in sources :

Example 1 with SessionTimeoutException

use of uk.gov.ida.hub.policy.exception.SessionTimeoutException in project verify-hub by alphagov.

the class SessionRepository method handleTimeout.

private void handleTimeout(SessionId sessionId, State state, Class<? extends State> stateClass, Class<? extends State> expectedStateClass) {
    boolean needsStateChangedToTimeout = isTimedOut(sessionId) && !stateClass.equals(TimeoutState.class);
    if (needsStateChangedToTimeout) {
        dataStore.replace(sessionId, new TimeoutState(state.getRequestId(), state.getRequestIssuerEntityId(), state.getSessionExpiryTimestamp(), state.getAssertionConsumerServiceUri(), state.getSessionId(), state.getTransactionSupportsEidas()));
    }
    boolean unexpectedErrorState = isErrorState(stateClass) && !isErrorState(expectedStateClass);
    if (needsStateChangedToTimeout || unexpectedErrorState) {
        throw new SessionTimeoutException(format("Session {0} timed out.", sessionId.getSessionId()), sessionId, state.getRequestIssuerEntityId(), state.getSessionExpiryTimestamp(), state.getRequestId());
    }
}
Also used : TimeoutState(uk.gov.ida.hub.policy.domain.state.TimeoutState) SessionTimeoutException(uk.gov.ida.hub.policy.exception.SessionTimeoutException)

Example 2 with SessionTimeoutException

use of uk.gov.ida.hub.policy.exception.SessionTimeoutException in project verify-hub by alphagov.

the class SessionRepositoryTest method getState_shouldReturnTimeoutController_whenTimeoutStateRequestedAndStateHasTimedOut.

@Test
public void getState_shouldReturnTimeoutController_whenTimeoutStateRequestedAndStateHasTimedOut() {
    DateTime now = DateTime.now();
    DateTimeFreezer.freezeTime(now);
    SessionStartedState sessionStartedState = aSessionStartedState().withSessionExpiryTimestamp(now).build();
    SessionId sessionId = sessionRepository.createSession(sessionStartedState);
    DateTimeFreezer.freezeTime(now.plusMinutes(3));
    // this action will implicitly move the session state to TimedOut
    try {
        sessionRepository.getStateController(sessionId, SessionStartedState.class);
    } catch (SessionTimeoutException e) {
    }
    sessionRepository.getStateController(sessionId, TimeoutState.class);
    verify(controllerFactory).build(timeoutStateArgumentCaptor.capture(), any(StateTransitionAction.class));
    TimeoutState timeoutState = timeoutStateArgumentCaptor.getValue();
    assertThat(timeoutState.getRequestId()).isEqualTo(sessionStartedState.getRequestId());
    assertThat(timeoutState.getRequestIssuerEntityId()).isEqualTo(sessionStartedState.getRequestIssuerEntityId());
    assertThat(timeoutState.getAssertionConsumerServiceUri()).isEqualTo(sessionStartedState.getAssertionConsumerServiceUri());
}
Also used : TimeoutState(uk.gov.ida.hub.policy.domain.state.TimeoutState) SessionTimeoutException(uk.gov.ida.hub.policy.exception.SessionTimeoutException) SessionIdBuilder.aSessionId(uk.gov.ida.hub.policy.builder.domain.SessionIdBuilder.aSessionId) DateTime(org.joda.time.DateTime) SessionStartedStateBuilder.aSessionStartedState(uk.gov.ida.hub.policy.builder.state.SessionStartedStateBuilder.aSessionStartedState) SessionStartedState(uk.gov.ida.hub.policy.domain.state.SessionStartedState) Test(org.junit.Test)

Aggregations

TimeoutState (uk.gov.ida.hub.policy.domain.state.TimeoutState)2 SessionTimeoutException (uk.gov.ida.hub.policy.exception.SessionTimeoutException)2 DateTime (org.joda.time.DateTime)1 Test (org.junit.Test)1 SessionIdBuilder.aSessionId (uk.gov.ida.hub.policy.builder.domain.SessionIdBuilder.aSessionId)1 SessionStartedStateBuilder.aSessionStartedState (uk.gov.ida.hub.policy.builder.state.SessionStartedStateBuilder.aSessionStartedState)1 SessionStartedState (uk.gov.ida.hub.policy.domain.state.SessionStartedState)1