Search in sources :

Example 1 with AuthnRequestFromHub

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

the class IdpSelectedStateController method getRequestFromHub.

public AuthnRequestFromHub getRequestFromHub() {
    AuthnRequestFromHub requestToSendFromHub = new AuthnRequestFromHub(state.getRequestId(), state.getLevelsOfAssurance(), state.getUseExactComparisonType(), state.getIdpEntityId(), state.getForceAuthentication(), state.getSessionExpiryTimestamp(), state.isRegistering(), null);
    hubEventLogger.logRequestFromHub(state.getSessionId(), state.getRequestIssuerEntityId());
    return requestToSendFromHub;
}
Also used : AuthnRequestFromHub(uk.gov.ida.hub.policy.domain.AuthnRequestFromHub)

Example 2 with AuthnRequestFromHub

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

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

use of uk.gov.ida.hub.policy.domain.AuthnRequestFromHub 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)

Example 5 with AuthnRequestFromHub

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

the class CountrySelectedStateController method getRequestFromHub.

public AuthnRequestFromHub getRequestFromHub() {
    // Use TransactionConfigProxy to lookup list of countries and findFirst matching by entityId
    Optional<EidasCountryDto> countryDto = this.transactionsConfigProxy.getEidasSupportedCountries().stream().filter(eidasCountryDto -> eidasCountryDto.getEntityId().equals(state.getCountryEntityId())).findFirst();
    AuthnRequestFromHub requestToSendFromHub = new AuthnRequestFromHub(state.getRequestId(), state.getLevelsOfAssurance(), false, state.getCountryEntityId(), com.google.common.base.Optional.of(true), state.getSessionExpiryTimestamp(), false, countryDto.map(EidasCountryDto::getOverriddenSsoUrl).orElse(null));
    hubEventLogger.logRequestFromHub(state.getSessionId(), state.getRequestIssuerEntityId());
    return requestToSendFromHub;
}
Also used : AuthnRequestFromHub(uk.gov.ida.hub.policy.domain.AuthnRequestFromHub) ResponseFromHub(uk.gov.ida.hub.policy.domain.ResponseFromHub) SessionId(uk.gov.ida.hub.policy.domain.SessionId) StateTransitionAction(uk.gov.ida.hub.policy.domain.StateTransitionAction) TransactionsConfigProxy(uk.gov.ida.hub.policy.proxy.TransactionsConfigProxy) EidasCycle0And1MatchRequestSentState(uk.gov.ida.hub.policy.domain.state.EidasCycle0And1MatchRequestSentState) CountrySelectedState(uk.gov.ida.hub.policy.domain.state.CountrySelectedState) EidasCountryDto(uk.gov.ida.hub.policy.domain.EidasCountryDto) StateProcessingValidationException(uk.gov.ida.hub.policy.domain.exception.StateProcessingValidationException) StateController(uk.gov.ida.hub.policy.domain.StateController) HubEventLogger(uk.gov.ida.hub.policy.logging.HubEventLogger) List(java.util.List) State(uk.gov.ida.hub.policy.domain.State) EidasAttributeQueryRequestDto(uk.gov.ida.hub.policy.contracts.EidasAttributeQueryRequestDto) LevelOfAssurance(uk.gov.ida.hub.policy.domain.LevelOfAssurance) Optional(java.util.Optional) URI(java.net.URI) EidasCountryDto(uk.gov.ida.hub.policy.domain.EidasCountryDto) AuthnRequestFromHub(uk.gov.ida.hub.policy.domain.AuthnRequestFromHub)

Aggregations

AuthnRequestFromHub (uk.gov.ida.hub.policy.domain.AuthnRequestFromHub)5 URI (java.net.URI)3 SamlRequestDto (uk.gov.ida.hub.policy.contracts.SamlRequestDto)3 AuthnRequestFromHubContainerDto (uk.gov.ida.hub.policy.domain.AuthnRequestFromHubContainerDto)3 IdaAuthnRequestFromHubDto (uk.gov.ida.hub.policy.domain.IdaAuthnRequestFromHubDto)3 SessionId (uk.gov.ida.hub.policy.domain.SessionId)3 Test (org.junit.Test)2 AuthnRequestFromHubBuilder.anAuthnRequestFromHub (uk.gov.ida.hub.policy.builder.domain.AuthnRequestFromHubBuilder.anAuthnRequestFromHub)2 SessionId.createNewSessionId (uk.gov.ida.hub.policy.domain.SessionId.createNewSessionId)2 List (java.util.List)1 Optional (java.util.Optional)1 EidasAttributeQueryRequestDto (uk.gov.ida.hub.policy.contracts.EidasAttributeQueryRequestDto)1 EidasCountryDto (uk.gov.ida.hub.policy.domain.EidasCountryDto)1 LevelOfAssurance (uk.gov.ida.hub.policy.domain.LevelOfAssurance)1 ResponseFromHub (uk.gov.ida.hub.policy.domain.ResponseFromHub)1 State (uk.gov.ida.hub.policy.domain.State)1 StateController (uk.gov.ida.hub.policy.domain.StateController)1 StateTransitionAction (uk.gov.ida.hub.policy.domain.StateTransitionAction)1 StateProcessingValidationException (uk.gov.ida.hub.policy.domain.exception.StateProcessingValidationException)1 CountrySelectedState (uk.gov.ida.hub.policy.domain.state.CountrySelectedState)1