Search in sources :

Example 6 with IdpSelectedState

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

the class HubEventLoggerTest method logIdpSelectedEvent_shouldLogEventWithIdpSelected.

@Test
public void logIdpSelectedEvent_shouldLogEventWithIdpSelected() {
    final IdpSelectedState state = IdpSelectedStateBuilder.anIdpSelectedState().withLevelsOfAssurance(Arrays.asList(LevelOfAssurance.LEVEL_1, LevelOfAssurance.LEVEL_2)).withSessionExpiryTimestamp(SESSION_EXPIRY_TIMESTAMP).withIdpEntityId(IDP_ENTITY_ID).withRequestIssuerEntityId(TRANSACTION_ENTITY_ID).withRequestId(REQUEST_ID).withSessionId(SESSION_ID).build();
    eventLogger.logIdpSelectedEvent(state, PRINCIPAL_IP_ADDRESS_SEEN_BY_HUB);
    final Map<EventDetailsKey, String> details = Maps.newHashMap();
    details.put(session_event_type, IDP_SELECTED);
    details.put(idp_entity_id, IDP_ENTITY_ID);
    details.put(principal_ip_address_as_seen_by_hub, PRINCIPAL_IP_ADDRESS_SEEN_BY_HUB);
    details.put(minimum_level_of_assurance, MINIMUM_LEVEL_OF_ASSURANCE.name());
    details.put(required_level_of_assurance, REQUIRED_LEVEL_OF_ASSURANCE.name());
    final EventSinkHubEvent expectedEvent = createExpectedEventSinkHubEvent(details);
    verify(eventSinkProxy).logHubEvent(argThat(new EventMatching(expectedEvent)));
    verify(eventEmitter).record(argThat(new EventMatching(expectedEvent)));
}
Also used : EventDetailsKey(uk.gov.ida.eventsink.EventDetailsKey) IdpSelectedState(uk.gov.ida.hub.policy.domain.state.IdpSelectedState) EventSinkHubEvent(uk.gov.ida.hub.policy.domain.EventSinkHubEvent) Test(org.junit.Test)

Example 7 with IdpSelectedState

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

the class SessionResourceIntegrationTest method shouldReturnOkWhenGeneratingIdpAuthnRequestFromHubIsSuccessfulOnSignIn.

@Test
public void shouldReturnOkWhenGeneratingIdpAuthnRequestFromHubIsSuccessfulOnSignIn() throws Exception {
    // Given
    final SamlRequestDto samlRequestDto = new SamlRequestDto("coffee-pasta", idpSsoUri);
    samlEngineStub.setupStubForIdpAuthnRequestGenerate(samlRequestDto);
    configStub.setupStubForEnabledIdps(rpEntityId, false, REQUESTED_LOA, singletonList(idpEntityId));
    SessionId sessionId = aSessionIsCreated();
    anIdpIsSelectedForSignIn(sessionId, idpEntityId);
    final AuthnRequestFromHubContainerDto expectedResult = anAuthnRequestFromHubContainerDtoWithRegistering(samlRequestDto, false);
    // When
    AuthnRequestFromHubContainerDto result = getEntity(UriBuilder.fromPath(Urls.PolicyUrls.IDP_AUTHN_REQUEST_RESOURCE).build(sessionId), AuthnRequestFromHubContainerDto.class);
    // Then
    assertThat(result).isEqualToComparingFieldByField(expectedResult);
    IdpSelectedState sessionState = policy.getSessionState(sessionId, IdpSelectedState.class);
    assertThat(sessionState.getMatchingServiceEntityId()).isEqualTo(msEntityId);
}
Also used : SamlRequestDto(uk.gov.ida.hub.policy.contracts.SamlRequestDto) AuthnRequestFromHubContainerDtoBuilder.anAuthnRequestFromHubContainerDto(uk.gov.ida.integrationtest.hub.policy.builders.AuthnRequestFromHubContainerDtoBuilder.anAuthnRequestFromHubContainerDto) AuthnRequestFromHubContainerDto(uk.gov.ida.hub.policy.domain.AuthnRequestFromHubContainerDto) IdpSelectedState(uk.gov.ida.hub.policy.domain.state.IdpSelectedState) SessionId(uk.gov.ida.hub.policy.domain.SessionId) Test(org.junit.Test)

Example 8 with IdpSelectedState

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

the class IdpSelector method buildIdpSelectedState.

public static IdpSelectedState buildIdpSelectedState(IdpSelectingState state, String idpEntityId, boolean registering, LevelOfAssurance requestedLoa, TransactionsConfigProxy transactionsConfigProxy, IdentityProvidersConfigProxy identityProvidersConfigProxy) {
    List<LevelOfAssurance> levelsOfAssuranceForTransaction = transactionsConfigProxy.getLevelsOfAssurance(state.getRequestIssuerEntityId());
    if (!levelsOfAssuranceForTransaction.contains(requestedLoa)) {
        throw StateProcessingValidationException.requestedLevelOfAssuranceUnsupportedByTransactionEntity(state.getRequestIssuerEntityId(), levelsOfAssuranceForTransaction, requestedLoa);
    }
    List<String> availableIdentityProviderEntityIdsForLoa = identityProvidersConfigProxy.getEnabledIdentityProviders(state.getRequestIssuerEntityId(), registering, requestedLoa);
    checkValidIdentityProvider(idpEntityId, availableIdentityProviderEntityIdsForLoa, state);
    IdpConfigDto idpConfig = identityProvidersConfigProxy.getIdpConfig(idpEntityId);
    final List<LevelOfAssurance> idpLevelsOfAssurance = idpConfig.getSupportedLevelsOfAssurance();
    List<LevelOfAssurance> levelsOfAssuranceForTransactionSupportedByIdp = levelsOfAssuranceForTransaction.stream().filter(idpLevelsOfAssurance::contains).collect(Collectors.toList());
    String matchingServiceEntityId = transactionsConfigProxy.getMatchingServiceEntityId(state.getRequestIssuerEntityId());
    return new IdpSelectedState(state.getRequestId(), idpEntityId, matchingServiceEntityId, levelsOfAssuranceForTransactionSupportedByIdp, idpConfig.getUseExactComparisonType(), state.getForceAuthentication().orNull(), state.getAssertionConsumerServiceUri(), state.getRequestIssuerEntityId(), state.getRelayState().orNull(), state.getSessionExpiryTimestamp(), registering, requestedLoa, state.getSessionId(), availableIdentityProviderEntityIdsForLoa, state.getTransactionSupportsEidas());
}
Also used : LevelOfAssurance(uk.gov.ida.hub.policy.domain.LevelOfAssurance) IdpConfigDto(uk.gov.ida.hub.policy.domain.IdpConfigDto) IdpSelectedState(uk.gov.ida.hub.policy.domain.state.IdpSelectedState)

Example 9 with IdpSelectedState

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

the class SessionStartedStateController method handleIdpSelected.

@Override
public void handleIdpSelected(final String idpEntityId, final String principalIpAddress, boolean registering, LevelOfAssurance requestedLoa) {
    IdpSelectedState idpSelectedState = IdpSelector.buildIdpSelectedState(state, idpEntityId, registering, requestedLoa, transactionsConfigProxy, identityProvidersConfigProxy);
    stateTransitionAction.transitionTo(idpSelectedState);
    hubEventLogger.logIdpSelectedEvent(idpSelectedState, principalIpAddress);
}
Also used : IdpSelectedState(uk.gov.ida.hub.policy.domain.state.IdpSelectedState)

Example 10 with IdpSelectedState

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

the class IdpSelectedStateControllerTest method idpSelectedStateBuilder.

private IdpSelectedStateController idpSelectedStateBuilder(boolean isRegistration) {
    idpSelectedState = anIdpSelectedState().withSessionId(NEW_SESSION_ID).withIdpEntityId(IDP_ENTITY_ID).withRequestId(REQUEST_ID).withLevelsOfAssurance(LEVELS_OF_ASSURANCE).withSessionExpiryTimestamp(SESSION_EXPIRY_TIMESTAMP).withRegistration(isRegistration).withTransactionSupportsEidas(true).build();
    IdpSelectedState state = idpSelectedState;
    String matchingServiceEntityId = "matching-service-entity-id";
    when(transactionsConfigProxy.getMatchingServiceEntityId(state.getRequestIssuerEntityId())).thenReturn(matchingServiceEntityId);
    when(matchingServiceConfigProxy.getMatchingService(matchingServiceEntityId)).thenReturn(aMatchingServiceConfigEntityDataDto().withUri(ATTRIBUTE_QUERY_URI).build());
    return new IdpSelectedStateController(state, hubEventLogger, stateTransitionAction, identityProvidersConfigProxy, transactionsConfigProxy, responseFromHubFactory, policyConfiguration, assertionRestrictionsFactory, matchingServiceConfigProxy);
}
Also used : IdpSelectedState(uk.gov.ida.hub.policy.domain.state.IdpSelectedState) IdpSelectedStateBuilder.anIdpSelectedState(uk.gov.ida.hub.policy.builder.state.IdpSelectedStateBuilder.anIdpSelectedState)

Aggregations

IdpSelectedState (uk.gov.ida.hub.policy.domain.state.IdpSelectedState)17 Test (org.junit.Test)10 IdpConfigDto (uk.gov.ida.hub.policy.domain.IdpConfigDto)4 IdpSelectedStateBuilder.anIdpSelectedState (uk.gov.ida.hub.policy.builder.state.IdpSelectedStateBuilder.anIdpSelectedState)2 EventDetailsKey (uk.gov.ida.eventsink.EventDetailsKey)1 SamlRequestDto (uk.gov.ida.hub.policy.contracts.SamlRequestDto)1 AuthnRequestFromHubContainerDto (uk.gov.ida.hub.policy.domain.AuthnRequestFromHubContainerDto)1 EventSinkHubEvent (uk.gov.ida.hub.policy.domain.EventSinkHubEvent)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 SessionStartedState (uk.gov.ida.hub.policy.domain.state.SessionStartedState)1 AuthnRequestFromHubContainerDtoBuilder.anAuthnRequestFromHubContainerDto (uk.gov.ida.integrationtest.hub.policy.builders.AuthnRequestFromHubContainerDtoBuilder.anAuthnRequestFromHubContainerDto)1