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);
}
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));
}
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);
}
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));
}
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());
}
Aggregations