Search in sources :

Example 21 with AuthnRequest

use of org.opensaml.saml.saml2.core.AuthnRequest in project verify-hub by alphagov.

the class ProtectiveMonitoringLogFormatterTest method shouldFormatAuthnRequestWithoutIssuer.

@Test
public void shouldFormatAuthnRequestWithoutIssuer() throws IOException, URISyntaxException {
    AuthnRequest authnRequest = anAuthnRequest().withId("test-id").withDestination("veganistan").withIssuer(null).build();
    String logString = new ProtectiveMonitoringLogFormatter().formatAuthnRequest(authnRequest, Direction.INBOUND, true);
    assertThat(logString).contains("issuerId: ,");
}
Also used : AuthnRequest(org.opensaml.saml.saml2.core.AuthnRequest) AuthnRequestBuilder.anAuthnRequest(uk.gov.ida.saml.core.test.builders.AuthnRequestBuilder.anAuthnRequest) Test(org.junit.Test)

Example 22 with AuthnRequest

use of org.opensaml.saml.saml2.core.AuthnRequest in project verify-hub by alphagov.

the class ProtectiveMonitoringLogFormatterTest method shouldFormatAuthnRequest.

@Test
public void shouldFormatAuthnRequest() throws IOException, URISyntaxException {
    AuthnRequest authnRequest = anAuthnRequest().withId("test-id").withDestination("veganistan").build();
    String logString = new ProtectiveMonitoringLogFormatter().formatAuthnRequest(authnRequest, Direction.INBOUND, true);
    String expectedLogMessage = "Protective Monitoring – Authn Request Event – {" + "requestId: test-id, " + "direction: INBOUND, " + "destination: veganistan, " + "issuerId: a-test-entity, " + "validSignature: true}";
    assertThat(logString).isEqualTo(expectedLogMessage);
}
Also used : AuthnRequest(org.opensaml.saml.saml2.core.AuthnRequest) AuthnRequestBuilder.anAuthnRequest(uk.gov.ida.saml.core.test.builders.AuthnRequestBuilder.anAuthnRequest) Test(org.junit.Test)

Example 23 with AuthnRequest

use of org.opensaml.saml.saml2.core.AuthnRequest 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 24 with AuthnRequest

use of org.opensaml.saml.saml2.core.AuthnRequest 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)

Example 25 with AuthnRequest

use of org.opensaml.saml.saml2.core.AuthnRequest in project verify-hub by alphagov.

the class SamlMessageReceiverApiResourceTest method shouldErrorWhenAuthnRequestIsNotSigned.

@Test
public void shouldErrorWhenAuthnRequestIsNotSigned() throws Exception {
    AuthnRequest authnRequest = anAuthnRequest().withIssuer(anIssuer().withIssuerId(TEST_RP).build()).withDestination(Endpoints.SSO_REQUEST_ENDPOINT).withId(AuthnRequestIdGenerator.generateRequestId()).withoutSignatureElement().build();
    SamlRequestDto authnRequestWrapper = new SamlRequestDto(authnRequestToStringTransformer.apply(authnRequest), "relayState", "ipAddress");
    Response clientResponse = postSAML(authnRequestWrapper, Urls.SamlProxyUrls.SAML2_SSO_RECEIVER_API_ROOT);
    assertError(clientResponse, ExceptionType.INVALID_SAML);
}
Also used : Response(javax.ws.rs.core.Response) ResponseBuilder.aResponse(uk.gov.ida.saml.core.test.builders.ResponseBuilder.aResponse) AuthnRequest(org.opensaml.saml.saml2.core.AuthnRequest) AuthnRequestBuilder.anAuthnRequest(uk.gov.ida.saml.core.test.builders.AuthnRequestBuilder.anAuthnRequest) SamlRequestDto(uk.gov.ida.hub.samlproxy.contracts.SamlRequestDto) Test(org.junit.Test)

Aggregations

AuthnRequest (org.opensaml.saml.saml2.core.AuthnRequest)40 Test (org.junit.Test)11 IOException (java.io.IOException)9 AuthnRequestBuilder.anAuthnRequest (uk.gov.ida.saml.core.test.builders.AuthnRequestBuilder.anAuthnRequest)9 WSSecurityException (org.apache.wss4j.common.ext.WSSecurityException)7 Assertion (org.jasig.cas.client.validation.Assertion)7 MessageContext (org.opensaml.messaging.context.MessageContext)7 Document (org.w3c.dom.Document)7 ZonedDateTime (java.time.ZonedDateTime)6 HttpServletResponse (javax.servlet.http.HttpServletResponse)6 SamlRegisteredService (org.apereo.cas.support.saml.services.SamlRegisteredService)6 SamlRegisteredServiceServiceProviderMetadataFacade (org.apereo.cas.support.saml.services.idp.metadata.SamlRegisteredServiceServiceProviderMetadataFacade)6 Assertion (org.opensaml.saml.saml2.core.Assertion)6 AuthnContextClassRef (org.opensaml.saml.saml2.core.AuthnContextClassRef)6 NameID (org.opensaml.saml.saml2.core.NameID)6 RequestedAuthnContext (org.opensaml.saml.saml2.core.RequestedAuthnContext)6 Envelope (org.opensaml.soap.soap11.Envelope)6 Response (javax.ws.rs.core.Response)5 AssertionConsumerService (org.opensaml.saml.saml2.metadata.AssertionConsumerService)5 SimpleSign (ddf.security.samlp.SimpleSign)4