Search in sources :

Example 61 with AuthnRequest

use of org.opensaml.saml.saml2.core.AuthnRequest in project ddf by codice.

the class IdpHandler method doHttpPostBinding.

private void doHttpPostBinding(HttpServletRequest request, HttpServletResponse response) throws AuthenticationFailureException {
    try {
        IDPSSODescriptor idpssoDescriptor = idpMetadata.getDescriptor();
        if (idpssoDescriptor == null) {
            throw new AuthenticationFailureException(IDP_METADATA_MISSING);
        }
        response.getWriter().printf(postBindingTemplate, idpMetadata.getSingleSignOnLocation(), encodeAuthnRequest(createAndSignAuthnRequest(true, idpssoDescriptor.getWantAuthnRequestsSigned()), true), createRelayState(request));
        response.setStatus(200);
        response.flushBuffer();
    } catch (IOException e) {
        LOGGER.info("Unable to post AuthnRequest to IdP", e);
        throw new AuthenticationFailureException("Unable to post to IdP");
    }
}
Also used : IDPSSODescriptor(org.opensaml.saml.saml2.metadata.IDPSSODescriptor) AuthenticationFailureException(org.codice.ddf.platform.filter.AuthenticationFailureException) IOException(java.io.IOException)

Example 62 with AuthnRequest

use of org.opensaml.saml.saml2.core.AuthnRequest in project ddf by codice.

the class PaosInInterceptor method checkAuthnRequest.

private void checkAuthnRequest(SOAPPart soapRequest) throws IOException {
    XMLObject authnXmlObj = null;
    try {
        Node node = soapRequest.getEnvelope().getBody().getFirstChild();
        authnXmlObj = SamlProtocol.getXmlObjectFromNode(node);
    } catch (WSSecurityException | SOAPException | XMLStreamException ex) {
        throw new IOException("Unable to convert AuthnRequest document to XMLObject.");
    }
    if (authnXmlObj == null) {
        throw new IOException("AuthnRequest object is not Found.");
    }
    if (!(authnXmlObj instanceof AuthnRequest)) {
        throw new IOException("SAMLRequest object is not AuthnRequest.");
    }
}
Also used : XMLStreamException(javax.xml.stream.XMLStreamException) AuthnRequest(org.opensaml.saml.saml2.core.AuthnRequest) Node(org.w3c.dom.Node) SOAPException(javax.xml.soap.SOAPException) XMLObject(org.opensaml.core.xml.XMLObject) WSSecurityException(org.apache.wss4j.common.ext.WSSecurityException) IOException(java.io.IOException)

Example 63 with AuthnRequest

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

Example 64 with AuthnRequest

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

the class IdaAuthnRequestFromHubToAuthnRequestTransformerTest method shouldSetProtocolBindingToPost.

@Test
public void shouldSetProtocolBindingToPost() {
    IdaAuthnRequestFromHub originalRequestFromTransaction = anIdaAuthnRequest().buildFromHub();
    AuthnRequest transformedRequest = transformer.apply(originalRequestFromTransaction);
    assertThat(transformedRequest.getProtocolBinding()).isEqualTo(SAMLConstants.SAML2_POST_BINDING_URI);
}
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) Test(org.junit.jupiter.api.Test)

Example 65 with AuthnRequest

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

the class IdaAuthnRequestFromHubToAuthnRequestTransformerTest method shouldUseTheOriginalRequestIdForTheTransformedRequest.

@Test
public void shouldUseTheOriginalRequestIdForTheTransformedRequest() {
    String originalRequestId = UUID.randomUUID().toString();
    IdaAuthnRequestFromHub originalRequestFromHub = anIdaAuthnRequest().withId(originalRequestId).buildFromHub();
    AuthnRequest transformedRequest = transformer.apply(originalRequestFromHub);
    assertThat(transformedRequest.getID()).isEqualTo(originalRequestId);
}
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) Test(org.junit.jupiter.api.Test)

Aggregations

AuthnRequest (org.opensaml.saml.saml2.core.AuthnRequest)113 Test (org.junit.jupiter.api.Test)42 lombok.val (lombok.val)40 Issuer (org.opensaml.saml.saml2.core.Issuer)28 AuthnRequestBuilder.anAuthnRequest (uk.gov.ida.saml.core.test.builders.AuthnRequestBuilder.anAuthnRequest)15 SAMLObjectBuilder (org.opensaml.saml.common.SAMLObjectBuilder)14 RequestedAuthnContext (org.opensaml.saml.saml2.core.RequestedAuthnContext)14 MessageContext (org.opensaml.messaging.context.MessageContext)13 IdaAuthnRequestFromHub (uk.gov.ida.saml.hub.domain.IdaAuthnRequestFromHub)12 IdaAuthnRequestBuilder.anIdaAuthnRequest (uk.gov.ida.saml.hub.test.builders.IdaAuthnRequestBuilder.anIdaAuthnRequest)12 SamlRegisteredService (org.apereo.cas.support.saml.services.SamlRegisteredService)11 DateTime (org.joda.time.DateTime)11 AuthnContextClassRef (org.opensaml.saml.saml2.core.AuthnContextClassRef)11 NameIDPolicy (org.opensaml.saml.saml2.core.NameIDPolicy)11 SamlRegisteredServiceServiceProviderMetadataFacade (org.apereo.cas.support.saml.services.idp.metadata.SamlRegisteredServiceServiceProviderMetadataFacade)10 AssertionConsumerService (org.opensaml.saml.saml2.metadata.AssertionConsumerService)10 IOException (java.io.IOException)9 XMLObject (org.opensaml.core.xml.XMLObject)9 NameID (org.opensaml.saml.saml2.core.NameID)8 JEEContext (org.pac4j.core.context.JEEContext)8