use of uk.gov.ida.hub.policy.contracts.AttributeQueryContainerDto in project verify-hub by alphagov.
the class AuthnResponseFromIdpServiceTest method shouldSendRequestToMatchingServiceViaAttributeQueryServiceAndUpdateSessionStateWhenSuccessfulResponseIsReceived.
@Test
public void shouldSendRequestToMatchingServiceViaAttributeQueryServiceAndUpdateSessionStateWhenSuccessfulResponseIsReceived() {
// Given
final String msaEntityId = "a-msa-entity-id";
LevelOfAssurance loaAchieved = LevelOfAssurance.LEVEL_2;
stub(idpSelectedStateController.isRegistrationContext()).toReturn(REGISTERING);
when(idpSelectedStateController.getMatchingServiceEntityId()).thenReturn(msaEntityId);
InboundResponseFromIdpDto successResponseFromIdp = InboundResponseFromIdpDtoBuilder.successResponse(UUID.randomUUID().toString(), loaAchieved);
SamlAuthnResponseTranslatorDto samlAuthnResponseTranslatorDto = SamlAuthnResponseTranslatorDtoBuilder.aSamlAuthnResponseTranslatorDto().build();
when(samlAuthnResponseTranslatorDtoFactory.fromSamlAuthnResponseContainerDto(samlAuthnResponseContainerDto, msaEntityId)).thenReturn(samlAuthnResponseTranslatorDto);
stub(samlEngineProxy.translateAuthnResponseFromIdp(any(SamlAuthnResponseTranslatorDto.class))).toReturn(successResponseFromIdp);
AttributeQueryRequestDto attributeQueryRequestDto = AttributeQueryRequestBuilder.anAttributeQueryRequest().build();
stub(idpSelectedStateController.createAttributeQuery(any(SuccessFromIdp.class))).toReturn(attributeQueryRequestDto);
AttributeQueryContainerDto msaRequest = AttributeQueryContainerDtoBuilder.anAttributeQueryContainerDto().build();
stub(samlEngineProxy.generateAttributeQuery(attributeQueryRequestDto)).toReturn(msaRequest);
// When
ResponseAction responseAction = service.receiveAuthnResponseFromIdp(sessionId, samlAuthnResponseContainerDto);
// Then
verify(samlAuthnResponseTranslatorDtoFactory).fromSamlAuthnResponseContainerDto(samlAuthnResponseContainerDto, msaEntityId);
verify(attributeQueryService).sendAttributeQueryRequest(sessionId, attributeQueryRequestDto);
verifyIdpStateControllerIsCalledWithRightDataOnSuccess(successResponseFromIdp);
ResponseAction expectedResponseAction = ResponseAction.success(sessionId, REGISTERING, loaAchieved);
assertThat(responseAction).isEqualToComparingFieldByField(expectedResponseAction);
}
use of uk.gov.ida.hub.policy.contracts.AttributeQueryContainerDto in project verify-hub by alphagov.
the class AuthnResponseFromCountryService method receiveAuthnResponseFromCountry.
public ResponseAction receiveAuthnResponseFromCountry(SessionId sessionId, SamlAuthnResponseContainerDto responseFromCountry) {
CountrySelectedStateController stateController = (CountrySelectedStateController) sessionRepository.getStateController(sessionId, CountrySelectedState.class);
String matchingServiceEntityId = stateController.getMatchingServiceEntityId();
stateController.validateCountryIsIn(countriesService.getCountries(sessionId));
SamlAuthnResponseTranslatorDto responseToTranslate = samlAuthnResponseTranslatorDtoFactory.fromSamlAuthnResponseContainerDto(responseFromCountry, matchingServiceEntityId);
InboundResponseFromCountry translatedResponse = samlEngineProxy.translateAuthnResponseFromCountry(responseToTranslate);
if (translatedResponse.getStatus() != IdpIdaStatus.Status.Success)
return other(sessionId, false);
validateSuccessfulResponse(stateController, translatedResponse);
EidasAttributeQueryRequestDto eidasAttributeQueryRequestDto = getEidasAttributeQueryRequestDto(stateController, translatedResponse);
stateController.transitionToEidasCycle0And1MatchRequestSentState(eidasAttributeQueryRequestDto, responseFromCountry.getPrincipalIPAddressAsSeenByHub(), translatedResponse.getIssuer());
AttributeQueryContainerDto aqr = samlEngineProxy.generateEidasAttributeQuery(eidasAttributeQueryRequestDto);
samlSoapProxyProxy.sendHubMatchingServiceRequest(sessionId, getAttributeQueryRequest(aqr));
return ResponseAction.success(sessionId, false, LevelOfAssurance.LEVEL_2);
}
Aggregations