Search in sources :

Example 6 with SessionStartedState

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

the class AuthnRequestFromTransactionHandler method handleRequestFromTransaction.

public SessionId handleRequestFromTransaction(SamlResponseWithAuthnRequestInformationDto samlResponse, Optional<String> relayState, String ipAddress, URI assertionConsumerServiceUri, boolean transactionSupportsEidas) {
    Duration sessionLength = policyConfiguration.getSessionLength();
    DateTime sessionExpiryTimestamp = DateTime.now().plus(sessionLength);
    SessionId sessionId = SessionId.createNewSessionId();
    SessionStartedState sessionStartedState = new SessionStartedState(samlResponse.getId(), relayState.orNull(), samlResponse.getIssuer(), assertionConsumerServiceUri, samlResponse.getForceAuthentication().orNull(), sessionExpiryTimestamp, sessionId, transactionSupportsEidas);
    final List<LevelOfAssurance> transactionLevelsOfAssurance = transactionsConfigProxy.getLevelsOfAssurance(samlResponse.getIssuer());
    hubEventLogger.logSessionStartedEvent(samlResponse, ipAddress, sessionExpiryTimestamp, sessionId, transactionLevelsOfAssurance.get(0), transactionLevelsOfAssurance.get(transactionLevelsOfAssurance.size() - 1));
    return sessionRepository.createSession(sessionStartedState);
}
Also used : LevelOfAssurance(uk.gov.ida.hub.policy.domain.LevelOfAssurance) Duration(org.joda.time.Duration) SessionId(uk.gov.ida.hub.policy.domain.SessionId) DateTime(org.joda.time.DateTime) SessionStartedState(uk.gov.ida.hub.policy.domain.state.SessionStartedState)

Example 7 with SessionStartedState

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

the class SessionRepositoryTest method getState_shouldGetAnInterfaceImplementation.

@Test
public void getState_shouldGetAnInterfaceImplementation() {
    SessionStartedState sessionStartedState = aSessionStartedState().withSessionExpiryTimestamp(defaultSessionExpiry).build();
    SessionId sessionId = sessionRepository.createSession(sessionStartedState);
    sessionRepository.getStateController(sessionId, SessionStartedState.class);
    verify(controllerFactory).build(eq(sessionStartedState), stateTransitionActionArgumentCaptor.capture());
    TestState state = new TestState();
    stateTransitionActionArgumentCaptor.getValue().transitionTo(state);
    sessionRepository.getStateController(sessionId, ResponsePreparedState.class);
    verify(controllerFactory).build(eq(state), any(StateTransitionAction.class));
}
Also used : SessionIdBuilder.aSessionId(uk.gov.ida.hub.policy.builder.domain.SessionIdBuilder.aSessionId) SessionStartedStateBuilder.aSessionStartedState(uk.gov.ida.hub.policy.builder.state.SessionStartedStateBuilder.aSessionStartedState) SessionStartedState(uk.gov.ida.hub.policy.domain.state.SessionStartedState) Test(org.junit.Test)

Example 8 with SessionStartedState

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

the class SessionRepositoryTest method getState_shouldNotThrowTimeoutStateException_whenRequestedAndActualStateIsErrorResponsePreparedStateAndSessionIsTimedout.

@Test
public void getState_shouldNotThrowTimeoutStateException_whenRequestedAndActualStateIsErrorResponsePreparedStateAndSessionIsTimedout() {
    DateTime now = DateTime.now();
    DateTimeFreezer.freezeTime(now);
    SessionStartedState sessionStartedState = aSessionStartedState().withSessionExpiryTimestamp(now).build();
    SessionId sessionId = sessionRepository.createSession(sessionStartedState);
    DateTimeFreezer.freezeTime(now.plusMinutes(3));
    try {
        sessionRepository.getStateController(sessionId, SessionStartedState.class);
    } catch (Exception e) {
    }
    sessionRepository.getStateController(sessionId, ErrorResponsePreparedState.class);
}
Also used : 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) SessionTimeoutException(uk.gov.ida.hub.policy.exception.SessionTimeoutException) InvalidSessionStateException(uk.gov.ida.hub.policy.exception.InvalidSessionStateException) Test(org.junit.Test)

Example 9 with SessionStartedState

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

the class SessionRepositoryTest method createSession_shouldCreateAndStoreSession.

@Test
public void createSession_shouldCreateAndStoreSession() {
    SessionId expectedSessionId = aSessionId().build();
    SessionStartedState sessionStartedState = aSessionStartedState().withSessionExpiryTimestamp(defaultSessionExpiry).withSessionId(expectedSessionId).build();
    SessionId sessionId = sessionRepository.createSession(sessionStartedState);
    sessionRepository.getStateController(sessionId, SessionStartedState.class);
    assertThat(sessionId).isEqualTo(expectedSessionId);
    assertThat(dataStore.containsKey(expectedSessionId)).isEqualTo(true);
    assertThat(sessionStartedMap.containsKey(expectedSessionId)).isEqualTo(true);
    verify(controllerFactory).build(eq(sessionStartedState), any(StateTransitionAction.class));
}
Also used : SessionIdBuilder.aSessionId(uk.gov.ida.hub.policy.builder.domain.SessionIdBuilder.aSessionId) SessionStartedStateBuilder.aSessionStartedState(uk.gov.ida.hub.policy.builder.state.SessionStartedStateBuilder.aSessionStartedState) SessionStartedState(uk.gov.ida.hub.policy.domain.state.SessionStartedState) Test(org.junit.Test)

Example 10 with SessionStartedState

use of uk.gov.ida.hub.policy.domain.state.SessionStartedState 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

SessionStartedState (uk.gov.ida.hub.policy.domain.state.SessionStartedState)12 Test (org.junit.Test)11 SessionIdBuilder.aSessionId (uk.gov.ida.hub.policy.builder.domain.SessionIdBuilder.aSessionId)9 SessionStartedStateBuilder.aSessionStartedState (uk.gov.ida.hub.policy.builder.state.SessionStartedStateBuilder.aSessionStartedState)9 DateTime (org.joda.time.DateTime)5 SessionTimeoutException (uk.gov.ida.hub.policy.exception.SessionTimeoutException)3 InvalidSessionStateException (uk.gov.ida.hub.policy.exception.InvalidSessionStateException)2 Duration (org.joda.time.Duration)1 LevelOfAssurance (uk.gov.ida.hub.policy.domain.LevelOfAssurance)1 ResponseFromHub (uk.gov.ida.hub.policy.domain.ResponseFromHub)1 SessionId (uk.gov.ida.hub.policy.domain.SessionId)1 StateController (uk.gov.ida.hub.policy.domain.StateController)1 IdpSelectedState (uk.gov.ida.hub.policy.domain.state.IdpSelectedState)1 TimeoutState (uk.gov.ida.hub.policy.domain.state.TimeoutState)1