use of uk.gov.ida.saml.core.domain.AuthnContext in project verify-hub by alphagov.
the class MatchingServiceResponseTranslatorService method translate.
public InboundResponseFromMatchingServiceDto translate(SamlResponseDto samlResponseDto) {
final Response response = responseUnmarshaller.apply(samlResponseDto.getSamlResponse());
MdcHelper.addContextToMdc(response);
final InboundResponseFromMatchingService responseFromMatchingService = responseToInboundResponseFromMatchingServiceTransformer.transform(response);
Optional<String> assertionBlob = Optional.empty();
Optional<LevelOfAssurance> levelOfAssurance = Optional.empty();
// FIXME?: transformer can return null
if (responseFromMatchingService.getMatchingServiceAssertion() != null && responseFromMatchingService.getMatchingServiceAssertion().isPresent()) {
assertionBlob = Optional.ofNullable(responseFromMatchingService.getMatchingServiceAssertion().get().getUnderlyingAssertionBlob());
final Optional<AuthnContext> authnContext = responseFromMatchingService.getMatchingServiceAssertion().get().getAuthnContext();
if (authnContext.isPresent()) {
levelOfAssurance = Optional.of(LevelOfAssurance.valueOf(authnContext.get().name()));
}
}
final InboundResponseFromMatchingServiceDto inboundResponseFromMatchingServiceDto = new InboundResponseFromMatchingServiceDto(responseFromMatchingService.getStatus(), responseFromMatchingService.getInResponseTo(), responseFromMatchingService.getIssuer(), assertionBlob, levelOfAssurance);
return inboundResponseFromMatchingServiceDto;
}
use of uk.gov.ida.saml.core.domain.AuthnContext in project verify-hub by alphagov.
the class MatchingServiceResponseTranslatorServiceTest method populateReturnDtoCorrectly_handleMatchResponse.
@Test
public void populateReturnDtoCorrectly_handleMatchResponse() {
final String inResponseTo = "inResponseTo";
final String issuer = "issuer";
final Optional<AuthnContext> authnContext = Optional.of(AuthnContext.LEVEL_2);
final Optional<FraudDetectedDetails> fraudDetectedDetails = Optional.empty();
final String underlyingAssertionBlob = "underlyingAssertionBlob";
final MatchingServiceIdaStatus status = MatchingServiceIdaStatus.MatchingServiceMatch;
final SamlResponseDto samlResponse = new SamlResponseDto("saml");
setUpForTranslate(authnContext, fraudDetectedDetails, underlyingAssertionBlob, inResponseTo, issuer, samlResponse.getSamlResponse(), status);
final InboundResponseFromMatchingServiceDto inboundResponseFromMatchingServiceDto = matchingServiceResponseTranslatorService.translate(samlResponse);
assertThat(inboundResponseFromMatchingServiceDto.getInResponseTo()).isEqualTo(inResponseTo);
assertThat(inboundResponseFromMatchingServiceDto.getUnderlyingMatchingServiceAssertionBlob().isPresent()).isTrue();
assertThat(inboundResponseFromMatchingServiceDto.getUnderlyingMatchingServiceAssertionBlob().get()).isEqualTo(underlyingAssertionBlob);
assertThat(inboundResponseFromMatchingServiceDto.getIssuer()).isEqualTo(issuer);
assertThat(inboundResponseFromMatchingServiceDto.getLevelOfAssurance().isPresent()).isTrue();
assertThat(inboundResponseFromMatchingServiceDto.getLevelOfAssurance().get().name()).isEqualTo(authnContext.get().name());
assertThat(inboundResponseFromMatchingServiceDto.getStatus()).isEqualTo(status);
}
use of uk.gov.ida.saml.core.domain.AuthnContext in project verify-hub by alphagov.
the class MatchingServiceResponseTranslatorServiceTest method populateReturnDtoCorrectly_handleRequesterError.
@Test
public void populateReturnDtoCorrectly_handleRequesterError() {
final String inResponseTo = "inResponseTo";
final String issuer = "issuer";
final Optional<AuthnContext> authnContext = Optional.empty();
final Optional<FraudDetectedDetails> fraudDetectedDetails = Optional.empty();
final String underlyingAssertionBlob = null;
final MatchingServiceIdaStatus status = MatchingServiceIdaStatus.RequesterError;
final SamlResponseDto samlResponse = new SamlResponseDto("saml");
setUpForTranslate(authnContext, fraudDetectedDetails, underlyingAssertionBlob, inResponseTo, issuer, samlResponse.getSamlResponse(), status);
final InboundResponseFromMatchingServiceDto inboundResponseFromMatchingServiceDto = matchingServiceResponseTranslatorService.translate(samlResponse);
assertThat(inboundResponseFromMatchingServiceDto.getInResponseTo()).isEqualTo(inResponseTo);
assertThat(inboundResponseFromMatchingServiceDto.getUnderlyingMatchingServiceAssertionBlob().isPresent()).isFalse();
assertThat(inboundResponseFromMatchingServiceDto.getIssuer()).isEqualTo(issuer);
assertThat(inboundResponseFromMatchingServiceDto.getLevelOfAssurance().isPresent()).isFalse();
assertThat(inboundResponseFromMatchingServiceDto.getStatus()).isEqualTo(status);
}
use of uk.gov.ida.saml.core.domain.AuthnContext in project verify-hub by alphagov.
the class CountryAuthnResponseTranslatorService method toModel.
private InboundResponseFromCountry toModel(ValidatedResponse response, Optional<Assertion> validatedIdentityAssertionOptional, String matchingServiceEntityId) {
Optional<PassthroughAssertion> passthroughAssertion = validatedIdentityAssertionOptional.map(validatedIdentityAssertion -> passthroughAssertionUnmarshaller.fromAssertion(validatedIdentityAssertion, true));
Optional<LevelOfAssurance> levelOfAssurance = passthroughAssertion.flatMap(assertion -> assertion.getAuthnContext()).map(AuthnContext::name).filter(string -> !isNullOrEmpty(string)).map(LevelOfAssurance::valueOf);
IdpIdaStatus status = statusUnmarshaller.fromSaml(response.getStatus());
return new InboundResponseFromCountry(response.getIssuer().getValue(), validatedIdentityAssertionOptional.map(Assertion::getSubject).map(Subject::getNameID).map(NameID::getValue), Optional.ofNullable(status).map(IdpIdaStatus::getStatusCode).map(IdpIdaStatus.Status::name), status.getMessage(), passthroughAssertion.map(assertion -> assertionBlobEncrypter.encryptAssertionBlob(matchingServiceEntityId, assertion.getUnderlyingAssertionBlob())), levelOfAssurance);
}
use of uk.gov.ida.saml.core.domain.AuthnContext in project verify-hub by alphagov.
the class IdpAuthnResponseTranslatorServiceTest method shouldExtractLevelOfAssurance.
@Test
public void shouldExtractLevelOfAssurance() {
AuthnContext authnContext = AuthnContext.LEVEL_1;
when(authStatementAssertion.getAuthnContext()).thenReturn(Optional.of(authnContext));
when(responseFromIdp.getAuthnStatementAssertion()).thenReturn(of(authStatementAssertion));
InboundResponseFromIdpDto result = translateAndCheckCommonFields();
checkAuthnStatementValues(result);
assertThat(result.getLevelOfAssurance().get().name()).isEqualTo(authnContext.name());
}
Aggregations