Search in sources :

Example 6 with Saml2Exception

use of org.springframework.security.saml2.Saml2Exception in project spring-security by spring-projects.

the class OpenSamlAuthenticationProvider method parse.

private Response parse(String response) throws Saml2Exception, Saml2AuthenticationException {
    try {
        Document document = this.parserPool.parse(new ByteArrayInputStream(response.getBytes(StandardCharsets.UTF_8)));
        Element element = document.getDocumentElement();
        return (Response) this.responseUnmarshaller.unmarshall(element);
    } catch (Exception ex) {
        throw createAuthenticationException(Saml2ErrorCodes.MALFORMED_RESPONSE_DATA, ex.getMessage(), ex);
    }
}
Also used : Response(org.opensaml.saml.saml2.core.Response) ByteArrayInputStream(java.io.ByteArrayInputStream) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) AuthenticationException(org.springframework.security.core.AuthenticationException) AssertionValidationException(org.opensaml.saml.common.assertion.AssertionValidationException) Saml2Exception(org.springframework.security.saml2.Saml2Exception)

Example 7 with Saml2Exception

use of org.springframework.security.saml2.Saml2Exception in project spring-security by spring-projects.

the class OpenSaml4AuthenticationProviderTests method serialize.

private String serialize(XMLObject object) {
    try {
        Marshaller marshaller = XMLObjectProviderRegistrySupport.getMarshallerFactory().getMarshaller(object);
        Element element = marshaller.marshall(object);
        return SerializeSupport.nodeToString(element);
    } catch (MarshallingException ex) {
        throw new Saml2Exception(ex);
    }
}
Also used : Marshaller(org.opensaml.core.xml.io.Marshaller) MarshallingException(org.opensaml.core.xml.io.MarshallingException) Element(org.w3c.dom.Element) Saml2Exception(org.springframework.security.saml2.Saml2Exception)

Example 8 with Saml2Exception

use of org.springframework.security.saml2.Saml2Exception in project spring-security by spring-projects.

the class OpenSamlAuthenticationRequestFactoryTests method getAuthNRequest.

private AuthnRequest getAuthNRequest(Saml2MessageBinding binding) {
    AbstractSaml2AuthenticationRequest result = (binding == Saml2MessageBinding.REDIRECT) ? this.factory.createRedirectAuthenticationRequest(this.context) : this.factory.createPostAuthenticationRequest(this.context);
    String samlRequest = result.getSamlRequest();
    assertThat(samlRequest).isNotEmpty();
    if (result.getBinding() == Saml2MessageBinding.REDIRECT) {
        samlRequest = Saml2Utils.samlInflate(Saml2Utils.samlDecode(samlRequest));
    } else {
        samlRequest = new String(Saml2Utils.samlDecode(samlRequest), StandardCharsets.UTF_8);
    }
    try {
        Document document = XMLObjectProviderRegistrySupport.getParserPool().parse(new ByteArrayInputStream(samlRequest.getBytes(StandardCharsets.UTF_8)));
        Element element = document.getDocumentElement();
        return (AuthnRequest) this.unmarshaller.unmarshall(element);
    } catch (Exception ex) {
        throw new Saml2Exception(ex);
    }
}
Also used : AuthnRequest(org.opensaml.saml.saml2.core.AuthnRequest) ByteArrayInputStream(java.io.ByteArrayInputStream) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) Saml2Exception(org.springframework.security.saml2.Saml2Exception) Saml2Exception(org.springframework.security.saml2.Saml2Exception) Assertions.assertThatIllegalArgumentException(org.assertj.core.api.Assertions.assertThatIllegalArgumentException)

Example 9 with Saml2Exception

use of org.springframework.security.saml2.Saml2Exception in project spring-security by spring-projects.

the class OpenSamlMetadataAssertingPartyDetailsConverter method convert.

Collection<RelyingPartyRegistration.AssertingPartyDetails.Builder> convert(InputStream inputStream) {
    List<RelyingPartyRegistration.AssertingPartyDetails.Builder> builders = new ArrayList<>();
    XMLObject xmlObject = xmlObject(inputStream);
    if (xmlObject instanceof EntitiesDescriptor) {
        EntitiesDescriptor descriptors = (EntitiesDescriptor) xmlObject;
        for (EntityDescriptor descriptor : descriptors.getEntityDescriptors()) {
            builders.add(convert(descriptor));
        }
        return builders;
    }
    if (xmlObject instanceof EntityDescriptor) {
        EntityDescriptor descriptor = (EntityDescriptor) xmlObject;
        return Arrays.asList(convert(descriptor));
    }
    throw new Saml2Exception("Unsupported element of type " + xmlObject.getClass());
}
Also used : EntityDescriptor(org.opensaml.saml.saml2.metadata.EntityDescriptor) ArrayList(java.util.ArrayList) XMLObject(org.opensaml.core.xml.XMLObject) EntitiesDescriptor(org.opensaml.saml.saml2.metadata.EntitiesDescriptor) Saml2Exception(org.springframework.security.saml2.Saml2Exception)

Example 10 with Saml2Exception

use of org.springframework.security.saml2.Saml2Exception in project spring-security by spring-projects.

the class OpenSamlLogoutResponseResolver method parse.

private LogoutRequest parse(String request) throws Saml2Exception {
    try {
        Document document = this.parserPool.parse(new ByteArrayInputStream(request.getBytes(StandardCharsets.UTF_8)));
        Element element = document.getDocumentElement();
        return (LogoutRequest) this.unmarshaller.unmarshall(element);
    } catch (Exception ex) {
        throw new Saml2Exception("Failed to deserialize LogoutRequest", ex);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) Element(org.w3c.dom.Element) LogoutRequest(org.opensaml.saml.saml2.core.LogoutRequest) Document(org.w3c.dom.Document) Saml2Exception(org.springframework.security.saml2.Saml2Exception) MarshallingException(org.opensaml.core.xml.io.MarshallingException) Saml2Exception(org.springframework.security.saml2.Saml2Exception)

Aggregations

Saml2Exception (org.springframework.security.saml2.Saml2Exception)46 Element (org.w3c.dom.Element)19 Document (org.w3c.dom.Document)13 MarshallingException (org.opensaml.core.xml.io.MarshallingException)12 ByteArrayOutputStream (java.io.ByteArrayOutputStream)10 IOException (java.io.IOException)10 ByteArrayInputStream (java.io.ByteArrayInputStream)9 Saml2X509Credential (org.springframework.security.saml2.core.Saml2X509Credential)9 X509Certificate (java.security.cert.X509Certificate)7 CertificateException (java.security.cert.CertificateException)6 Marshaller (org.opensaml.core.xml.io.Marshaller)6 Deflater (java.util.zip.Deflater)5 DeflaterOutputStream (java.util.zip.DeflaterOutputStream)5 Inflater (java.util.zip.Inflater)5 InflaterOutputStream (java.util.zip.InflaterOutputStream)5 CriteriaSet (net.shibboleth.utilities.java.support.resolver.CriteriaSet)4 XMLObject (org.opensaml.core.xml.XMLObject)4 Unmarshaller (org.opensaml.core.xml.io.Unmarshaller)4 SAMLMetadataSignatureSigningParametersResolver (org.opensaml.saml.security.impl.SAMLMetadataSignatureSigningParametersResolver)4 SecurityException (org.opensaml.security.SecurityException)4