Search in sources :

Example 1 with AuthnRequestFromRelyingParty

use of uk.gov.ida.saml.hub.domain.AuthnRequestFromRelyingParty in project verify-hub by alphagov.

the class RpAuthnRequestTranslatorService method translate.

public TranslatedAuthnRequestDto translate(SamlRequestWithAuthnRequestInformationDto samlRequestWithAuthnRequestInformationDto) {
    AuthnRequest authnRequest = stringToAuthnRequestTransformer.apply(samlRequestWithAuthnRequestInformationDto.getSamlMessage());
    MdcHelper.addContextToMdc(authnRequest.getID(), authnRequest.getIssuer().getValue());
    AuthnRequestFromRelyingParty authnRequestFromRelyingParty = authnRequestToIdaRequestFromRelyingPartyTransformer.apply(authnRequest);
    if (authnRequestFromRelyingParty.getVerifyServiceProviderVersion().isPresent()) {
        LOG.info(String.format("Issuer %s uses VSP version %s", authnRequestFromRelyingParty.getIssuer(), authnRequestFromRelyingParty.getVerifyServiceProviderVersion().get()));
    }
    UnknownMethodAlgorithmLogger.probeAuthnRequestForMethodAlgorithm(authnRequestFromRelyingParty);
    return new TranslatedAuthnRequestDto(authnRequestFromRelyingParty.getId(), authnRequestFromRelyingParty.getIssuer(), authnRequestFromRelyingParty.getForceAuthentication(), authnRequestFromRelyingParty.getAssertionConsumerServiceUrl(), authnRequestFromRelyingParty.getAssertionConsumerServiceIndex());
}
Also used : AuthnRequest(org.opensaml.saml.saml2.core.AuthnRequest) AuthnRequestFromRelyingParty(uk.gov.ida.saml.hub.domain.AuthnRequestFromRelyingParty) TranslatedAuthnRequestDto(uk.gov.ida.hub.samlengine.contracts.TranslatedAuthnRequestDto)

Example 2 with AuthnRequestFromRelyingParty

use of uk.gov.ida.saml.hub.domain.AuthnRequestFromRelyingParty in project verify-hub by alphagov.

the class UnknownMethodAlgorithmLoggerTest method shouldReportUnknownDigestAlgorithmInSPAuthnRequest.

@Test
public void shouldReportUnknownDigestAlgorithmInSPAuthnRequest() throws Exception {
    AuthnRequestFromRelyingParty authnRequestFromRelyingParty = anAuthnRequestFromRelyingParty().withId(ID).withIssuer(ISSUER_SP).withSignature(signatureWithUnknownDigestAlgorithm.get()).build();
    UnknownMethodAlgorithmLogger.probeAuthnRequestForMethodAlgorithm(authnRequestFromRelyingParty);
    verifyLog(mockAppender, captorLoggingEvent, 1, String.format(UnknownMethodAlgorithmLogger.DIGEST_ALGORITHM_MESSAGE, SP, DIGEST_SHA1_ID, AuthnRequest.DEFAULT_ELEMENT_LOCAL_NAME));
}
Also used : AuthnRequestFromRelyingParty(uk.gov.ida.saml.hub.domain.AuthnRequestFromRelyingParty) AuthnRequestFromRelyingPartyBuilder.anAuthnRequestFromRelyingParty(uk.gov.ida.hub.samlengine.builders.AuthnRequestFromRelyingPartyBuilder.anAuthnRequestFromRelyingParty) Test(org.junit.Test)

Example 3 with AuthnRequestFromRelyingParty

use of uk.gov.ida.saml.hub.domain.AuthnRequestFromRelyingParty in project verify-hub by alphagov.

the class UnknownMethodAlgorithmLoggerTest method shouldNotReportStrongAlgorithmsInSPAuthnRequest.

@Test
public void shouldNotReportStrongAlgorithmsInSPAuthnRequest() throws Exception {
    AuthnRequestFromRelyingParty authnRequestFromRelyingParty = anAuthnRequestFromRelyingParty().withId(ID).withIssuer(ISSUER_SP).withSignature(signature.get()).build();
    UnknownMethodAlgorithmLogger.probeAuthnRequestForMethodAlgorithm(authnRequestFromRelyingParty);
    verify(mockAppender, times(0)).doAppend(captorLoggingEvent.capture());
}
Also used : AuthnRequestFromRelyingParty(uk.gov.ida.saml.hub.domain.AuthnRequestFromRelyingParty) AuthnRequestFromRelyingPartyBuilder.anAuthnRequestFromRelyingParty(uk.gov.ida.hub.samlengine.builders.AuthnRequestFromRelyingPartyBuilder.anAuthnRequestFromRelyingParty) Test(org.junit.Test)

Example 4 with AuthnRequestFromRelyingParty

use of uk.gov.ida.saml.hub.domain.AuthnRequestFromRelyingParty in project verify-hub by alphagov.

the class UnknownMethodAlgorithmLoggerTest method shouldReportUnknownSignatureAlgorithmInSPAuthnRequest.

@Test
public void shouldReportUnknownSignatureAlgorithmInSPAuthnRequest() throws Exception {
    AuthnRequestFromRelyingParty authnRequestFromRelyingParty = anAuthnRequestFromRelyingParty().withId(ID).withIssuer(ISSUER_SP).withSignature(signatureWithUnknownSignatureAlgorithm.get()).build();
    UnknownMethodAlgorithmLogger.probeAuthnRequestForMethodAlgorithm(authnRequestFromRelyingParty);
    verifyLog(mockAppender, captorLoggingEvent, 1, String.format(UnknownMethodAlgorithmLogger.SIGNATURE_ALGORITHM_MESSAGE, SP, SIGNATURE_RSASHA1_ID, AuthnRequest.DEFAULT_ELEMENT_LOCAL_NAME));
}
Also used : AuthnRequestFromRelyingParty(uk.gov.ida.saml.hub.domain.AuthnRequestFromRelyingParty) AuthnRequestFromRelyingPartyBuilder.anAuthnRequestFromRelyingParty(uk.gov.ida.hub.samlengine.builders.AuthnRequestFromRelyingPartyBuilder.anAuthnRequestFromRelyingParty) Test(org.junit.Test)

Example 5 with AuthnRequestFromRelyingParty

use of uk.gov.ida.saml.hub.domain.AuthnRequestFromRelyingParty in project verify-hub by alphagov.

the class RpAuthnRequestTranslatorServiceTest method shouldTranslateSamlAuthnRequest.

@Test
public void shouldTranslateSamlAuthnRequest() throws Exception {
    RpAuthnRequestTranslatorService service = new RpAuthnRequestTranslatorService(stringToAuthnRequestTransformer, samlAuthnRequestToAuthnRequestFromRelyingPartyTransformer);
    boolean forceAuthentication = true;
    String id = UUID.randomUUID().toString();
    String issuer = UUID.randomUUID().toString();
    URI assertionConsumerServiceUrl = URI.create("http://someassertionuri");
    int assertionConsumerServiceIndex = 1;
    Signature signature = aSignature().withSignatureAlgorithm(SIGNATURE_ALGORITHM).build();
    ((SignatureImpl) signature).setXMLSignature(BuilderHelper.createXMLSignature(SIGNATURE_ALGORITHM, new DigestSHA256()));
    SamlRequestWithAuthnRequestInformationDto samlRequestWithAuthnRequestInformationDto = SamlAuthnRequestDtoBuilder.aSamlAuthnRequest().withId(id).withIssuer(issuer).withForceAuthentication(forceAuthentication).withAssertionConsumerIndex(assertionConsumerServiceIndex).withPublicCert(TEST_RP_PUBLIC_SIGNING_CERT).withPrivateKey(TEST_RP_PRIVATE_SIGNING_KEY).build();
    AuthnRequest authnRequest = AuthnRequestBuilder.anAuthnRequest().build();
    TranslatedAuthnRequestDto expected = TranslatedAuthnRequestDtoBuilder.aTranslatedAuthnRequest().withId(id).withIssuer(issuer).withForceAuthentication(forceAuthentication).withAssertionConsumerServiceUrl(assertionConsumerServiceUrl).withAssertionConsumerServiceIndex(assertionConsumerServiceIndex).build();
    AuthnRequestFromRelyingParty intermediateBlah = anAuthnRequestFromRelyingParty().withId(id).withIssuer(issuer).withForceAuthentication(forceAuthentication).withAssertionConsumerServiceUrl(assertionConsumerServiceUrl).withAssertionConsumerServiceIndex(assertionConsumerServiceIndex).withSignature(signature).build();
    stub(stringToAuthnRequestTransformer.apply(samlRequestWithAuthnRequestInformationDto.getSamlMessage())).toReturn(authnRequest);
    stub(samlAuthnRequestToAuthnRequestFromRelyingPartyTransformer.apply(authnRequest)).toReturn(intermediateBlah);
    TranslatedAuthnRequestDto actual = service.translate(samlRequestWithAuthnRequestInformationDto);
    assertThat(actual).isEqualToComparingFieldByField(expected);
}
Also used : SamlRequestWithAuthnRequestInformationDto(uk.gov.ida.hub.samlengine.contracts.SamlRequestWithAuthnRequestInformationDto) DigestSHA256(org.opensaml.xmlsec.algorithm.descriptors.DigestSHA256) AuthnRequest(org.opensaml.saml.saml2.core.AuthnRequest) AuthnRequestFromRelyingParty(uk.gov.ida.saml.hub.domain.AuthnRequestFromRelyingParty) AuthnRequestFromRelyingPartyBuilder.anAuthnRequestFromRelyingParty(uk.gov.ida.hub.samlengine.builders.AuthnRequestFromRelyingPartyBuilder.anAuthnRequestFromRelyingParty) Signature(org.opensaml.xmlsec.signature.Signature) SignatureBuilder.aSignature(uk.gov.ida.saml.core.test.builders.SignatureBuilder.aSignature) TranslatedAuthnRequestDto(uk.gov.ida.hub.samlengine.contracts.TranslatedAuthnRequestDto) SignatureImpl(org.opensaml.xmlsec.signature.impl.SignatureImpl) URI(java.net.URI) Test(org.junit.Test)

Aggregations

AuthnRequestFromRelyingParty (uk.gov.ida.saml.hub.domain.AuthnRequestFromRelyingParty)6 Test (org.junit.Test)5 AuthnRequestFromRelyingPartyBuilder.anAuthnRequestFromRelyingParty (uk.gov.ida.hub.samlengine.builders.AuthnRequestFromRelyingPartyBuilder.anAuthnRequestFromRelyingParty)5 AuthnRequest (org.opensaml.saml.saml2.core.AuthnRequest)2 TranslatedAuthnRequestDto (uk.gov.ida.hub.samlengine.contracts.TranslatedAuthnRequestDto)2 URI (java.net.URI)1 DigestSHA256 (org.opensaml.xmlsec.algorithm.descriptors.DigestSHA256)1 Signature (org.opensaml.xmlsec.signature.Signature)1 SignatureImpl (org.opensaml.xmlsec.signature.impl.SignatureImpl)1 SamlRequestWithAuthnRequestInformationDto (uk.gov.ida.hub.samlengine.contracts.SamlRequestWithAuthnRequestInformationDto)1 SignatureBuilder.aSignature (uk.gov.ida.saml.core.test.builders.SignatureBuilder.aSignature)1