Search in sources :

Example 41 with AuthnRequest

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

the class AuthnRequestFromRelyingPartyUnmarshallerTest method fromSamlMessage_shouldNotComplainWhenExceptionDuringDecryption.

@Test
public void fromSamlMessage_shouldNotComplainWhenExceptionDuringDecryption() throws Exception {
    AuthnRequest authnRequest = new AuthnRequestBuilder().buildObject();
    authnRequest.setIssuer(new IssuerBuilder().buildObject());
    authnRequest.setDestination("http://example.com");
    authnRequest.setExtensions(createApplicationVersionExtensions(null));
    AuthnRequestFromRelyingParty authnRequestFromRelyingParty = unmarshaller.fromSamlMessage(authnRequest);
    assertThat(authnRequestFromRelyingParty.getVerifyServiceProviderVersion()).isEqualTo(Optional.empty());
}
Also used : AuthnRequest(org.opensaml.saml.saml2.core.AuthnRequest) AuthnRequestFromRelyingParty(uk.gov.ida.saml.hub.domain.AuthnRequestFromRelyingParty) AuthnRequestBuilder(org.opensaml.saml.saml2.core.impl.AuthnRequestBuilder) IssuerBuilder(org.opensaml.saml.saml2.core.impl.IssuerBuilder) Test(org.junit.jupiter.api.Test)

Example 42 with AuthnRequest

use of org.opensaml.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()) {
        logAndSendMetricForVspVersion(authnRequestFromRelyingParty);
    }
    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 43 with AuthnRequest

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

the class ProtectiveMonitoringLogFormatterTest method shouldFormatAuthnRequestWithoutIssuer.

@Test
public void shouldFormatAuthnRequestWithoutIssuer() {
    AuthnRequest authnRequest = anAuthnRequest().withId("test-id").withDestination("veganistan").withIssuer(null).build();
    String logString = new ProtectiveMonitoringLogFormatter().formatAuthnRequest(authnRequest, Direction.INBOUND, SignatureStatus.VALID_SIGNATURE);
    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.jupiter.api.Test)

Example 44 with AuthnRequest

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

the class ProtectiveMonitoringLogFormatterTest method shouldFormatAuthnRequest.

@Test
public void shouldFormatAuthnRequest() {
    AuthnRequest authnRequest = anAuthnRequest().withId("test-id").withDestination("veganistan").build();
    String logString = new ProtectiveMonitoringLogFormatter().formatAuthnRequest(authnRequest, Direction.INBOUND, SignatureStatus.VALID_SIGNATURE);
    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.jupiter.api.Test)

Example 45 with AuthnRequest

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

the class IdaAuthnRequestFromHubToAuthnRequestTransformerTest method shouldUseTheOriginalExpiryTimestampToSetTheNotOnOrAfter.

@Test
public void shouldUseTheOriginalExpiryTimestampToSetTheNotOnOrAfter() {
    DateTime sessionExpiry = DateTime.now().plusHours(2);
    IdaAuthnRequestFromHub originalRequestFromHub = anIdaAuthnRequest().withSessionExpiryTimestamp(sessionExpiry).buildFromHub();
    AuthnRequest transformedRequest = transformer.apply(originalRequestFromHub);
    assertThat(transformedRequest.getConditions().getNotOnOrAfter()).isEqualTo(sessionExpiry);
}
Also used : IdaAuthnRequestFromHub(uk.gov.ida.saml.hub.domain.IdaAuthnRequestFromHub) IdaAuthnRequestBuilder.anIdaAuthnRequest(uk.gov.ida.saml.hub.test.builders.IdaAuthnRequestBuilder.anIdaAuthnRequest) AuthnRequest(org.opensaml.saml.saml2.core.AuthnRequest) DateTime(org.joda.time.DateTime) Test(org.junit.jupiter.api.Test)

Aggregations

AuthnRequest (org.opensaml.saml.saml2.core.AuthnRequest)113 Test (org.junit.jupiter.api.Test)35 lombok.val (lombok.val)26 Issuer (org.opensaml.saml.saml2.core.Issuer)21 AuthnRequestBuilder.anAuthnRequest (uk.gov.ida.saml.core.test.builders.AuthnRequestBuilder.anAuthnRequest)15 IdaAuthnRequestFromHub (uk.gov.ida.saml.hub.domain.IdaAuthnRequestFromHub)12 IdaAuthnRequestBuilder.anIdaAuthnRequest (uk.gov.ida.saml.hub.test.builders.IdaAuthnRequestBuilder.anIdaAuthnRequest)12 SAMLObjectBuilder (org.opensaml.saml.common.SAMLObjectBuilder)11 DateTime (org.joda.time.DateTime)10 MessageContext (org.opensaml.messaging.context.MessageContext)9 NameIDPolicy (org.opensaml.saml.saml2.core.NameIDPolicy)9 RequestedAuthnContext (org.opensaml.saml.saml2.core.RequestedAuthnContext)9 Document (org.w3c.dom.Document)9 SamlRegisteredService (org.apereo.cas.support.saml.services.SamlRegisteredService)8 SamlRegisteredServiceServiceProviderMetadataFacade (org.apereo.cas.support.saml.services.idp.metadata.SamlRegisteredServiceServiceProviderMetadataFacade)8 XMLObject (org.opensaml.core.xml.XMLObject)7 IOException (java.io.IOException)6 WSSecurityException (org.apache.wss4j.common.ext.WSSecurityException)6 AuthnRequestBuilder (org.opensaml.saml.saml2.core.impl.AuthnRequestBuilder)6 IssuerBuilder (org.opensaml.saml.saml2.core.impl.IssuerBuilder)6