use of uk.gov.ida.saml.hub.domain.InboundResponseFromIdp in project verify-hub by alphagov.
the class IdaResponseFromIdpUnmarshallerTest method transform_shouldTransformTheSamlResponseToIdaResponseByIdp.
@Test
public void transform_shouldTransformTheSamlResponseToIdaResponseByIdp() {
Assertion mdsAssertion = anAssertion().addAttributeStatement(anAttributeStatement().build()).buildUnencrypted();
Assertion authnStatementAssertion = anAssertion().addAuthnStatement(anAuthnStatement().build()).buildUnencrypted();
when(response.getAssertions()).thenReturn(List.of(mdsAssertion, authnStatementAssertion));
PassthroughAssertion passthroughMdsAssertion = aPassthroughAssertion().buildMatchingDatasetAssertion();
when(passthroughAssertionUnmarshaller.fromAssertion(mdsAssertion)).thenReturn(passthroughMdsAssertion);
PassthroughAssertion passthroughAuthnAssertion = aPassthroughAssertion().buildAuthnStatementAssertion();
when(passthroughAssertionUnmarshaller.fromAssertion(authnStatementAssertion)).thenReturn(passthroughAuthnAssertion);
InboundResponseFromIdp inboundResponseFromIdp = unmarshaller.fromSaml(new ValidatedResponse(response), new ValidatedAssertions(response.getAssertions()));
assertThat(inboundResponseFromIdp.getSignature().isPresent()).isEqualTo(true);
assertThat(inboundResponseFromIdp.getMatchingDatasetAssertion().isPresent()).isEqualTo(true);
assertThat(inboundResponseFromIdp.getAuthnStatementAssertion().isPresent()).isEqualTo(true);
assertThat(inboundResponseFromIdp.getSignature().get()).isEqualTo(signature);
assertThat(inboundResponseFromIdp.getAuthnStatementAssertion().get()).isEqualTo(passthroughAuthnAssertion);
assertThat(inboundResponseFromIdp.getMatchingDatasetAssertion().get()).isEqualTo(passthroughMdsAssertion);
}
use of uk.gov.ida.saml.hub.domain.InboundResponseFromIdp in project verify-hub by alphagov.
the class UnknownMethodAlgorithmLoggerTest method shouldReportUnknownSignatureAlgorithmInIDPResponse.
@Test
public void shouldReportUnknownSignatureAlgorithmInIDPResponse() throws Exception {
InboundResponseFromIdp inboundResponseFromIdp = new InboundResponseFromIdp(ID, IN_RESPONSE_TO, ISSUER_IDP, ISSUE_INSTANT, NOT_ON_OR_AFTER, STATUS, signatureWithUnknownSignatureAlgorithm, MATCHING_DATASET_ASSERTION, DESTINATION, AUTHN_STATEMENT_ASSERTION);
UnknownMethodAlgorithmLogger.probeResponseForMethodAlgorithm(inboundResponseFromIdp);
verifyLog(mockAppender, captorLoggingEvent, 1, String.format(UnknownMethodAlgorithmLogger.SIGNATURE_ALGORITHM_MESSAGE, IDP, SIGNATURE_RSA_SHA1_ID, Response.DEFAULT_ELEMENT_LOCAL_NAME));
}
use of uk.gov.ida.saml.hub.domain.InboundResponseFromIdp in project verify-hub by alphagov.
the class IdaResponseFromIdpUnmarshaller method fromSaml.
public InboundResponseFromIdp fromSaml(ValidatedResponse validatedResponse, ValidatedAssertions validatedAssertions) {
Optional<PassthroughAssertion> matchingDatasetAssertion = validatedAssertions.getMatchingDatasetAssertion().map(passthroughAssertionUnmarshaller::fromAssertion);
Optional<PassthroughAssertion> authnStatementAssertion = validatedAssertions.getAuthnStatementAssertion().map(passthroughAssertionUnmarshaller::fromAssertion);
IdpIdaStatus transformedStatus = statusUnmarshaller.fromSaml(validatedResponse.getStatus());
URI destination = URI.create(validatedResponse.getDestination());
Optional<DateTime> notOnOrAfter = validatedAssertions.getMatchingDatasetAssertion().flatMap(a -> Optional.ofNullable(a.getSubject())).flatMap(s -> Optional.ofNullable(s.getSubjectConfirmations().get(0).getSubjectConfirmationData().getNotOnOrAfter()));
return new InboundResponseFromIdp(validatedResponse.getID(), validatedResponse.getInResponseTo(), validatedResponse.getIssuer().getValue(), validatedResponse.getIssueInstant(), notOnOrAfter, transformedStatus, Optional.ofNullable(validatedResponse.getSignature()), matchingDatasetAssertion, destination, authnStatementAssertion);
}
use of uk.gov.ida.saml.hub.domain.InboundResponseFromIdp in project verify-hub by alphagov.
the class IdpAuthnResponseTranslatorService method translate.
public InboundResponseFromIdpDto translate(SamlAuthnResponseTranslatorDto samlResponseDto) {
Response response = stringToOpenSamlResponseTransformer.apply(samlResponseDto.getSamlResponse());
MdcHelper.addContextToMdc(response);
try {
InboundResponseFromIdp idaResponseFromIdp = samlResponseToIdaResponseIssuedByIdpTransformer.apply(response);
UnknownMethodAlgorithmLogger.probeResponseForMethodAlgorithm(idaResponseFromIdp);
if (idaResponseFromIdp.getAuthnStatementAssertion().isPresent()) {
Assertion authnStatementAssertion = stringToAssertionTransformer.apply(idaResponseFromIdp.getAuthnStatementAssertion().get().getUnderlyingAssertionBlob());
logAnalytics(authnStatementAssertion, AUTHN_STATEMENT);
}
Assertion matchingDatasetAssertion = null;
if (idaResponseFromIdp.getMatchingDatasetAssertion().isPresent()) {
matchingDatasetAssertion = stringToAssertionTransformer.apply(idaResponseFromIdp.getMatchingDatasetAssertion().get().getUnderlyingAssertionBlob());
logAnalytics(matchingDatasetAssertion, MATCHING_DATASET);
}
InboundResponseFromIdpData inboundResponseFromIdpData = inboundResponseFromIdpDataGenerator.generate(idaResponseFromIdp, samlResponseDto.getMatchingServiceEntityId());
Optional<LevelOfAssurance> levelOfAssurance = Optional.empty();
if (!Strings.isNullOrEmpty(inboundResponseFromIdpData.getLevelOfAssurance())) {
levelOfAssurance = Optional.of(LevelOfAssurance.valueOf(inboundResponseFromIdpData.getLevelOfAssurance()));
}
logVerifiedAttributes(idaResponseFromIdp, matchingDatasetAssertion, levelOfAssurance);
return new InboundResponseFromIdpDto(inboundResponseFromIdpData.getStatus(), inboundResponseFromIdpData.getStatusMessage(), inboundResponseFromIdpData.getIssuer(), inboundResponseFromIdpData.getEncryptedAuthnAssertion(), inboundResponseFromIdpData.getEncryptedMatchingDatasetAssertion(), inboundResponseFromIdpData.getPersistentId(), inboundResponseFromIdpData.getPrincipalIpAddressAsSeenByIdp(), levelOfAssurance, inboundResponseFromIdpData.getIdpFraudEventId(), inboundResponseFromIdpData.getFraudIndicator(), inboundResponseFromIdpData.getNotOnOrAfter());
} catch (SamlTransformationErrorException e) {
throw new SamlContextException(response.getID(), response.getIssuer().getValue(), e);
}
}
use of uk.gov.ida.saml.hub.domain.InboundResponseFromIdp in project verify-hub by alphagov.
the class UnknownMethodAlgorithmLoggerTest method shouldReportUnknownDigestAlgorithmInIDPResponse.
@Test
public void shouldReportUnknownDigestAlgorithmInIDPResponse() throws Exception {
InboundResponseFromIdp inboundResponseFromIdp = new InboundResponseFromIdp(ID, IN_RESPONSE_TO, ISSUER_IDP, ISSUE_INSTANT, NOT_ON_OR_AFTER, STATUS, signatureWithUnknownDigestAlgorithm, MATCHING_DATASET_ASSERTION, DESTINATION, AUTHN_STATEMENT_ASSERTION);
UnknownMethodAlgorithmLogger.probeResponseForMethodAlgorithm(inboundResponseFromIdp);
verifyLog(mockAppender, captorLoggingEvent, 1, String.format(UnknownMethodAlgorithmLogger.DIGEST_ALGORITHM_MESSAGE, IDP, DIGEST_SHA1_ID, Response.DEFAULT_ELEMENT_LOCAL_NAME));
}
Aggregations