Search in sources :

Example 1 with AuthnRequestFromHubContainerDto

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

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

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

the class SessionServiceTest method shouldGetACountryAuthnRequestWithOverriddenSsoUrl.

@Test
public void shouldGetACountryAuthnRequestWithOverriddenSsoUrl() throws Exception {
    // Given
    SessionId sessionId = createNewSessionId();
    when(sessionRepository.sessionExists(sessionId)).thenReturn(true);
    when(sessionRepository.isSessionInState(sessionId, CountrySelectedState.class)).thenReturn(true);
    AuthnRequestFromHub authnRequestFromHub = anAuthnRequestFromHub().withSsoUrl(URI.create("/theSsoUri")).build();
    when(authnRequestHandler.getIdaAuthnRequestFromHub(sessionId)).thenReturn(authnRequestFromHub);
    URI ssoUri = UriBuilder.fromUri(UUID.randomUUID().toString()).build();
    SamlRequestDto samlRequest = new SamlRequestDto("samlRequest", ssoUri);
    when(samlEngineProxy.generateCountryAuthnRequestFromHub(any(IdaAuthnRequestFromHubDto.class))).thenReturn(samlRequest);
    // When
    AuthnRequestFromHubContainerDto countryAuthnRequest = service.getIdpAuthnRequest(sessionId);
    // Then
    AuthnRequestFromHubContainerDto expected = new AuthnRequestFromHubContainerDto(samlRequest.getSamlRequest(), ssoUri, authnRequestFromHub.getRegistering());
    assertThat(countryAuthnRequest).isEqualToComparingFieldByField(expected);
    ArgumentCaptor<IdaAuthnRequestFromHubDto> requestFromHubDtoArgumentCaptor = ArgumentCaptor.forClass(IdaAuthnRequestFromHubDto.class);
    verify(samlEngineProxy).generateCountryAuthnRequestFromHub(requestFromHubDtoArgumentCaptor.capture());
    assertThat(requestFromHubDtoArgumentCaptor.getValue().getOverriddenSsoUrl(), notNullValue());
}
Also used : IdaAuthnRequestFromHubDto(uk.gov.ida.hub.policy.domain.IdaAuthnRequestFromHubDto) SamlRequestDto(uk.gov.ida.hub.policy.contracts.SamlRequestDto) AuthnRequestFromHub(uk.gov.ida.hub.policy.domain.AuthnRequestFromHub) AuthnRequestFromHubBuilder.anAuthnRequestFromHub(uk.gov.ida.hub.policy.builder.domain.AuthnRequestFromHubBuilder.anAuthnRequestFromHub) AuthnRequestFromHubContainerDto(uk.gov.ida.hub.policy.domain.AuthnRequestFromHubContainerDto) SessionId(uk.gov.ida.hub.policy.domain.SessionId) SessionId.createNewSessionId(uk.gov.ida.hub.policy.domain.SessionId.createNewSessionId) URI(java.net.URI) Test(org.junit.Test)

Example 4 with AuthnRequestFromHubContainerDto

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

the class SessionServiceTest method shouldGetIdpAuthnRequest.

@Test
public void shouldGetIdpAuthnRequest() throws Exception {
    SessionId sessionId = createNewSessionId();
    when(sessionRepository.sessionExists(sessionId)).thenReturn(true);
    AuthnRequestFromHub authnRequestFromHub = anAuthnRequestFromHub().build();
    when(authnRequestHandler.getIdaAuthnRequestFromHub(sessionId)).thenReturn(authnRequestFromHub);
    URI ssoUri = UriBuilder.fromUri(UUID.randomUUID().toString()).build();
    SamlRequestDto samlRequest = new SamlRequestDto("samlRequest", ssoUri);
    when(samlEngineProxy.generateIdpAuthnRequestFromHub(any(IdaAuthnRequestFromHubDto.class))).thenReturn(samlRequest);
    AuthnRequestFromHubContainerDto idpAuthnRequest = service.getIdpAuthnRequest(sessionId);
    AuthnRequestFromHubContainerDto expected = new AuthnRequestFromHubContainerDto(samlRequest.getSamlRequest(), ssoUri, authnRequestFromHub.getRegistering());
    assertThat(idpAuthnRequest).isEqualToComparingFieldByField(expected);
}
Also used : IdaAuthnRequestFromHubDto(uk.gov.ida.hub.policy.domain.IdaAuthnRequestFromHubDto) SamlRequestDto(uk.gov.ida.hub.policy.contracts.SamlRequestDto) AuthnRequestFromHub(uk.gov.ida.hub.policy.domain.AuthnRequestFromHub) AuthnRequestFromHubBuilder.anAuthnRequestFromHub(uk.gov.ida.hub.policy.builder.domain.AuthnRequestFromHubBuilder.anAuthnRequestFromHub) AuthnRequestFromHubContainerDto(uk.gov.ida.hub.policy.domain.AuthnRequestFromHubContainerDto) SessionId(uk.gov.ida.hub.policy.domain.SessionId) SessionId.createNewSessionId(uk.gov.ida.hub.policy.domain.SessionId.createNewSessionId) URI(java.net.URI) Test(org.junit.Test)

Example 5 with AuthnRequestFromHubContainerDto

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

the class SessionService method getIdpAuthnRequest.

public AuthnRequestFromHubContainerDto getIdpAuthnRequest(SessionId sessionId) {
    getSessionIfItExists(sessionId);
    final AuthnRequestFromHub request = authnRequestHandler.getIdaAuthnRequestFromHub(sessionId);
    final IdaAuthnRequestFromHubDto authnRequestFromHub = new IdaAuthnRequestFromHubDto(request.getId(), request.getForceAuthentication(), request.getSessionExpiryTimestamp(), request.getRecipientEntityId(), request.getLevelsOfAssurance(), request.getUseExactComparisonType(), request.getOverriddenSsoUrl());
    boolean countryIdentityProvider = sessionRepository.isSessionInState(sessionId, CountrySelectedState.class);
    final SamlRequestDto samlRequest = countryIdentityProvider ? samlEngineProxy.generateCountryAuthnRequestFromHub(authnRequestFromHub) : samlEngineProxy.generateIdpAuthnRequestFromHub(authnRequestFromHub);
    return new AuthnRequestFromHubContainerDto(samlRequest.getSamlRequest(), samlRequest.getSsoUri(), request.getRegistering());
}
Also used : IdaAuthnRequestFromHubDto(uk.gov.ida.hub.policy.domain.IdaAuthnRequestFromHubDto) SamlRequestDto(uk.gov.ida.hub.policy.contracts.SamlRequestDto) AuthnRequestFromHub(uk.gov.ida.hub.policy.domain.AuthnRequestFromHub) AuthnRequestFromHubContainerDto(uk.gov.ida.hub.policy.domain.AuthnRequestFromHubContainerDto)

Aggregations

SamlRequestDto (uk.gov.ida.hub.policy.contracts.SamlRequestDto)5 AuthnRequestFromHubContainerDto (uk.gov.ida.hub.policy.domain.AuthnRequestFromHubContainerDto)5 Test (org.junit.Test)4 SessionId (uk.gov.ida.hub.policy.domain.SessionId)4 AuthnRequestFromHub (uk.gov.ida.hub.policy.domain.AuthnRequestFromHub)3 IdaAuthnRequestFromHubDto (uk.gov.ida.hub.policy.domain.IdaAuthnRequestFromHubDto)3 URI (java.net.URI)2 AuthnRequestFromHubBuilder.anAuthnRequestFromHub (uk.gov.ida.hub.policy.builder.domain.AuthnRequestFromHubBuilder.anAuthnRequestFromHub)2 SessionId.createNewSessionId (uk.gov.ida.hub.policy.domain.SessionId.createNewSessionId)2 AuthnRequestFromHubContainerDtoBuilder.anAuthnRequestFromHubContainerDto (uk.gov.ida.integrationtest.hub.policy.builders.AuthnRequestFromHubContainerDtoBuilder.anAuthnRequestFromHubContainerDto)2 IdpSelectedState (uk.gov.ida.hub.policy.domain.state.IdpSelectedState)1