Search in sources :

Example 1 with SessionId

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

the class PolicyExceptionMapper method getSessionId.

protected Optional<SessionId> getSessionId() {
    // Are there any uris in Policy that contain the session id as a query string rather than as part of the path or is this just here coz it was copied from shared-rest   ?
    String parameter = httpServletRequest.getParameter(Urls.SharedUrls.SESSION_ID_PARAM);
    if (Strings.isNullOrEmpty(parameter)) {
        parameter = httpServletRequest.getParameter(Urls.SharedUrls.RELAY_STATE_PARAM);
    }
    if (Strings.isNullOrEmpty(parameter)) {
        MultivaluedMap<String, String> pathParameters = uriInfo.getPathParameters();
        parameter = pathParameters.getFirst(Urls.SharedUrls.SESSION_ID_PARAM);
    }
    if (Strings.isNullOrEmpty(parameter)) {
        return Optional.absent();
    } else {
        return Optional.fromNullable(new SessionId(parameter));
    }
}
Also used : SessionId(uk.gov.ida.hub.policy.domain.SessionId)

Example 2 with SessionId

use of uk.gov.ida.hub.policy.domain.SessionId 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 3 with SessionId

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

the class AuthnRequestFromTransactionHandlerTest method stateControllerInvokedFromSessionRepositoryForselectedIdp.

@Test
public void stateControllerInvokedFromSessionRepositoryForselectedIdp() {
    SessionId sessionId = new SessionId("aSessionId");
    IdpSelected idpSelected = new IdpSelected(IDP_ENTITY_ID, PRINCIPAL_IP_ADDRESS, REGISTERING, REQUESTED_LOA);
    IdpSelectingStateControllerSpy idpSelectingStateController = new IdpSelectingStateControllerSpy();
    when(sessionRepository.getStateController(sessionId, IdpSelectingState.class)).thenReturn((idpSelectingStateController));
    authnRequestFromTransactionHandler.selectIdpForGivenSessionId(sessionId, idpSelected);
    assertThat(idpSelectingStateController.idpEntityId()).isEqualTo(IDP_ENTITY_ID);
    assertThat(idpSelectingStateController.principalIpAddress()).isEqualTo(PRINCIPAL_IP_ADDRESS);
    assertThat(idpSelectingStateController.registering()).isEqualTo(REGISTERING);
    assertThat(idpSelectingStateController.getRequestedLoa()).isEqualTo(REQUESTED_LOA);
}
Also used : IdpSelected(uk.gov.ida.hub.policy.domain.IdpSelected) SessionId(uk.gov.ida.hub.policy.domain.SessionId) Test(org.junit.Test)

Example 4 with SessionId

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

the class AwaitingCycle3DataStateControllerTest method cycle3dataInputCancelledFromFrontEnd_shouldLogCancellation.

@Test
public void cycle3dataInputCancelledFromFrontEnd_shouldLogCancellation() throws Exception {
    final String requestId = "requestId";
    final SessionId sessionId = aSessionId().build();
    final AwaitingCycle3DataStateController awaitingCycle3DataStateController = setUpAwaitingCycle3DataStateController(requestId, sessionId);
    awaitingCycle3DataStateController.handleCancellation();
    ArgumentCaptor<EventSinkHubEvent> argumentCaptor = ArgumentCaptor.forClass(EventSinkHubEvent.class);
    verify(eventSinkProxy, atLeastOnce()).logHubEvent(argumentCaptor.capture());
    Condition<EventSinkHubEvent> combinedConditions = AllOf.allOf(hasSessionId(sessionId), hasDetail(EventDetailsKey.session_event_type, CYCLE3_CANCEL), hasDetail(EventDetailsKey.request_id, requestId));
    assertThat(argumentCaptor.getAllValues()).haveAtLeast(1, combinedConditions);
}
Also used : SessionId(uk.gov.ida.hub.policy.domain.SessionId) SessionIdBuilder.aSessionId(uk.gov.ida.hub.policy.builder.domain.SessionIdBuilder.aSessionId) HasSessionId.hasSessionId(uk.gov.ida.hub.policy.matchers.HasSessionId.hasSessionId) EventSinkHubEvent(uk.gov.ida.hub.policy.domain.EventSinkHubEvent) Test(org.junit.Test)

Example 5 with SessionId

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

the class CountrySelectedStateControllerTest method shouldTransitionToEidasCycle0And1MatchRequestSentState.

@Test
public void shouldTransitionToEidasCycle0And1MatchRequestSentState() {
    final String ipAddress = "ip-address";
    when(transactionsConfigProxy.getMatchingServiceEntityId(state.getRequestIssuerEntityId())).thenReturn(MSA_ID);
    EidasAttributeQueryRequestDto eidasAttributeQueryRequestDto = anEidasAttributeQueryRequestDto().build();
    EidasCycle0And1MatchRequestSentState eidasCycle0And1MatchRequestSentState = new EidasCycle0And1MatchRequestSentState(state.getRequestId(), state.getRequestIssuerEntityId(), state.getSessionExpiryTimestamp(), state.getAssertionConsumerServiceUri(), new SessionId(state.getSessionId().getSessionId()), state.getTransactionSupportsEidas(), COUNTRY_ENTITY_ID, state.getRelayState().orNull(), eidasAttributeQueryRequestDto.getLevelOfAssurance(), MSA_ID, eidasAttributeQueryRequestDto.getEncryptedIdentityAssertion(), eidasAttributeQueryRequestDto.getPersistentId());
    controller.transitionToEidasCycle0And1MatchRequestSentState(eidasAttributeQueryRequestDto, ipAddress, COUNTRY_ENTITY_ID);
    verify(hubEventLogger).logIdpAuthnSucceededEvent(state.getSessionId(), state.getSessionExpiryTimestamp(), state.getCountryEntityId(), state.getRequestIssuerEntityId(), eidasAttributeQueryRequestDto.getPersistentId(), state.getRequestId(), state.getLevelsOfAssurance().get(0), state.getLevelsOfAssurance().get(state.getLevelsOfAssurance().size() - 1), eidasAttributeQueryRequestDto.getLevelOfAssurance(), com.google.common.base.Optional.absent(), ipAddress);
    verify(stateTransitionAction).transitionTo(eidasCycle0And1MatchRequestSentState);
}
Also used : EidasCycle0And1MatchRequestSentState(uk.gov.ida.hub.policy.domain.state.EidasCycle0And1MatchRequestSentState) SessionId(uk.gov.ida.hub.policy.domain.SessionId) EidasAttributeQueryRequestDtoBuilder.anEidasAttributeQueryRequestDto(uk.gov.ida.hub.policy.builder.EidasAttributeQueryRequestDtoBuilder.anEidasAttributeQueryRequestDto) EidasAttributeQueryRequestDto(uk.gov.ida.hub.policy.contracts.EidasAttributeQueryRequestDto) Test(org.junit.Test)

Aggregations

SessionId (uk.gov.ida.hub.policy.domain.SessionId)92 Test (org.junit.Test)83 Response (javax.ws.rs.core.Response)41 URI (java.net.URI)33 ResponseProcessingDetails (uk.gov.ida.hub.policy.domain.ResponseProcessingDetails)14 SessionId.createNewSessionId (uk.gov.ida.hub.policy.domain.SessionId.createNewSessionId)13 Cycle3MatchRequestSentState (uk.gov.ida.hub.policy.domain.state.Cycle3MatchRequestSentState)12 Matchers.anyString (org.mockito.Matchers.anyString)9 Cycle3MatchRequestSentStateBuilder.aCycle3MatchRequestSentState (uk.gov.ida.hub.policy.builder.state.Cycle3MatchRequestSentStateBuilder.aCycle3MatchRequestSentState)9 InboundResponseFromMatchingServiceDto (uk.gov.ida.hub.policy.contracts.InboundResponseFromMatchingServiceDto)6 MatchingServiceRequestErrorState (uk.gov.ida.hub.policy.domain.state.MatchingServiceRequestErrorState)6 SessionIdBuilder.aSessionId (uk.gov.ida.hub.policy.builder.domain.SessionIdBuilder.aSessionId)5 AuthnResponseFromHubContainerDto (uk.gov.ida.hub.policy.contracts.AuthnResponseFromHubContainerDto)5 Cycle3AttributeRequestData (uk.gov.ida.hub.policy.domain.Cycle3AttributeRequestData)5 EventSinkHubEvent (uk.gov.ida.hub.policy.domain.EventSinkHubEvent)5 NoMatchFromMatchingService (uk.gov.ida.hub.policy.domain.NoMatchFromMatchingService)5 ResponseFromHub (uk.gov.ida.hub.policy.domain.ResponseFromHub)5 SamlRequestDto (uk.gov.ida.hub.policy.contracts.SamlRequestDto)4 SamlResponseWithAuthnRequestInformationDto (uk.gov.ida.hub.policy.contracts.SamlResponseWithAuthnRequestInformationDto)4 AuthnRequestFromHubContainerDto (uk.gov.ida.hub.policy.domain.AuthnRequestFromHubContainerDto)4