Search in sources :

Example 41 with SessionId

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

the class SessionResourceIntegrationTest method shouldGetRpResponseGivenASessionExistsInPolicy.

@Test
public void shouldGetRpResponseGivenASessionExistsInPolicy() throws JsonProcessingException {
    // Given
    SessionId sessionId = SessionId.createNewSessionId();
    configStub.setupStubForEnabledIdps(rpEntityId, SIGNING_IN, REQUESTED_LOA, singletonList(idpEntityId));
    Response sessionCreatedResponse = TestSessionResourceHelper.createSessionInSuccessfulMatchState(sessionId, rpEntityId, idpEntityId, client, policy.uri(UriBuilder.fromPath(TEST_SESSION_RESOURCE_PATH + SUCCESSFUL_MATCH_STATE).build().toASCIIString()));
    assertThat(sessionCreatedResponse.getStatus()).isEqualTo(Response.Status.OK.getStatusCode());
    AuthnResponseFromHubContainerDto expectedAuthnResponseFromHub = anAuthnResponseFromHubContainerDto().build();
    samlEngineStub.setUpStubForAuthnResponseGenerate(expectedAuthnResponseFromHub);
    // When
    URI rpAuthResponseUri = UriBuilder.fromPath(Urls.PolicyUrls.RP_AUTHN_RESPONSE_RESOURCE).build(sessionId);
    Response responseForRp = client.target(policy.uri(rpAuthResponseUri.toASCIIString())).request().get();
    // Then
    assertThat(responseForRp.getStatus()).isEqualTo(Response.Status.OK.getStatusCode());
    AuthnResponseFromHubContainerDto authnResponseFromHub = responseForRp.readEntity(AuthnResponseFromHubContainerDto.class);
    assertThat(authnResponseFromHub).isEqualToComparingFieldByField(expectedAuthnResponseFromHub);
}
Also used : Response(javax.ws.rs.core.Response) AuthnResponseFromHubContainerDto(uk.gov.ida.hub.policy.contracts.AuthnResponseFromHubContainerDto) AuthnResponseFromHubContainerDtoBuilder.anAuthnResponseFromHubContainerDto(uk.gov.ida.integrationtest.hub.policy.builders.AuthnResponseFromHubContainerDtoBuilder.anAuthnResponseFromHubContainerDto) SessionId(uk.gov.ida.hub.policy.domain.SessionId) URI(java.net.URI) Test(org.junit.Test)

Example 42 with SessionId

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

the class SessionResourceIntegrationTest method shouldReturnOkWhenGeneratingIdpAuthnRequestFromHubIsSuccessfulOnRegistration.

@Test
public void shouldReturnOkWhenGeneratingIdpAuthnRequestFromHubIsSuccessfulOnRegistration() throws Exception {
    // Given
    SessionId sessionId = aSessionIsCreated();
    anIdpIsSelectedForRegistration(sessionId, idpEntityId);
    final SamlRequestDto samlRequestDto = new SamlRequestDto("coffee-pasta", idpSsoUri);
    final AuthnRequestFromHubContainerDto expectedResult = anAuthnRequestFromHubContainerDtoWithRegistering(samlRequestDto, true);
    samlEngineStub.setupStubForIdpAuthnRequestGenerate(samlRequestDto);
    // When
    AuthnRequestFromHubContainerDto result = getEntity(UriBuilder.fromPath(Urls.PolicyUrls.IDP_AUTHN_REQUEST_RESOURCE).build(sessionId), AuthnRequestFromHubContainerDto.class);
    // Then
    assertThat(result).isEqualToComparingFieldByField(expectedResult);
}
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) SessionId(uk.gov.ida.hub.policy.domain.SessionId) Test(org.junit.Test)

Example 43 with SessionId

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

the class SessionTimeoutIntegrationTests method selectIdpShouldReturnErrorWhenSessionHasTimedOut.

@Test
public void selectIdpShouldReturnErrorWhenSessionHasTimedOut() {
    DateTimeFreezer.freezeTime(SOME_TIME);
    SessionId sessionId = client.target(policy.uri(Urls.PolicyUrls.NEW_SESSION_RESOURCE)).request().post(Entity.entity(samlRequest, MediaType.APPLICATION_JSON_TYPE), SessionId.class);
    DateTimeFreezer.freezeTime(SOME_TIME.plusMinutes(SOME_TIMEOUT + 1));
    URI uri = UriBuilder.fromPath(Urls.PolicyUrls.AUTHN_REQUEST_SELECT_IDP_RESOURCE).buildFromEncoded(sessionId);
    confirmError(policy.uri(uri.getPath()), new IdpSelected(STUB_IDP_ONE, "some-ip-address", REGISTERING, REQUESTED_LOA), SESSION_TIMEOUT);
}
Also used : IdpSelected(uk.gov.ida.hub.policy.domain.IdpSelected) SessionId(uk.gov.ida.hub.policy.domain.SessionId) URI(java.net.URI) Test(org.junit.Test)

Example 44 with SessionId

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

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

the class AbstractAwaitingCycle3DataStateController method handleCancellation.

public void handleCancellation() {
    hubEventLogger.logCycle3DataInputCancelled(state.getSessionId(), state.getRequestIssuerEntityId(), state.getSessionExpiryTimestamp(), state.getRequestId());
    Cycle3DataInputCancelledState cycle3DataInputCancelledState = new Cycle3DataInputCancelledState(state.getRequestId(), state.getSessionExpiryTimestamp(), state.getRelayState(), state.getRequestIssuerEntityId(), state.getAssertionConsumerServiceUri(), new SessionId(state.getSessionId().getSessionId()), state.getTransactionSupportsEidas());
    stateTransitionAction.transitionTo(cycle3DataInputCancelledState);
}
Also used : Cycle3DataInputCancelledState(uk.gov.ida.hub.policy.domain.state.Cycle3DataInputCancelledState) SessionId(uk.gov.ida.hub.policy.domain.SessionId)

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