Search in sources :

Example 11 with Saml2Exception

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

the class Saml2Utils method samlInflate.

static String samlInflate(byte[] b) {
    try {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        InflaterOutputStream iout = new InflaterOutputStream(out, new Inflater(true));
        iout.write(b);
        iout.finish();
        return new String(out.toByteArray(), StandardCharsets.UTF_8);
    } catch (IOException ex) {
        throw new Saml2Exception("Unable to inflate string", ex);
    }
}
Also used : InflaterOutputStream(java.util.zip.InflaterOutputStream) Inflater(java.util.zip.Inflater) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) Saml2Exception(org.springframework.security.saml2.Saml2Exception)

Example 12 with Saml2Exception

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

the class OpenSamlSigningUtils method serialize.

static 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 13 with Saml2Exception

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

the class Saml2Utils method samlDeflate.

static byte[] samlDeflate(String s) {
    try {
        ByteArrayOutputStream b = new ByteArrayOutputStream();
        DeflaterOutputStream deflater = new DeflaterOutputStream(b, new Deflater(Deflater.DEFLATED, true));
        deflater.write(s.getBytes(StandardCharsets.UTF_8));
        deflater.finish();
        return b.toByteArray();
    } catch (IOException ex) {
        throw new Saml2Exception("Unable to deflate string", ex);
    }
}
Also used : Deflater(java.util.zip.Deflater) DeflaterOutputStream(java.util.zip.DeflaterOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) Saml2Exception(org.springframework.security.saml2.Saml2Exception)

Example 14 with Saml2Exception

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

the class OpenSamlLogoutRequestResolverTests method getLogoutRequest.

private LogoutRequest getLogoutRequest(String samlRequest, Saml2MessageBinding binding) {
    if (binding == 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 (LogoutRequest) XMLObjectProviderRegistrySupport.getUnmarshallerFactory().getUnmarshaller(element).unmarshall(element);
    } catch (Exception ex) {
        throw new Saml2Exception(ex);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) Element(org.w3c.dom.Element) LogoutRequest(org.opensaml.saml.saml2.core.LogoutRequest) Saml2LogoutRequest(org.springframework.security.saml2.provider.service.authentication.logout.Saml2LogoutRequest) Document(org.w3c.dom.Document) Saml2Exception(org.springframework.security.saml2.Saml2Exception) Saml2Exception(org.springframework.security.saml2.Saml2Exception)

Example 15 with Saml2Exception

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

the class OpenSamlLogoutResponseResolverTests method getLogoutResponse.

private LogoutResponse getLogoutResponse(String saml2Response, Saml2MessageBinding binding) {
    if (binding == Saml2MessageBinding.REDIRECT) {
        saml2Response = Saml2Utils.samlInflate(Saml2Utils.samlDecode(saml2Response));
    } else {
        saml2Response = new String(Saml2Utils.samlDecode(saml2Response), StandardCharsets.UTF_8);
    }
    try {
        Document document = XMLObjectProviderRegistrySupport.getParserPool().parse(new ByteArrayInputStream(saml2Response.getBytes(StandardCharsets.UTF_8)));
        Element element = document.getDocumentElement();
        return (LogoutResponse) XMLObjectProviderRegistrySupport.getUnmarshallerFactory().getUnmarshaller(element).unmarshall(element);
    } catch (Exception ex) {
        throw new Saml2Exception(ex);
    }
}
Also used : LogoutResponse(org.opensaml.saml.saml2.core.LogoutResponse) Saml2LogoutResponse(org.springframework.security.saml2.provider.service.authentication.logout.Saml2LogoutResponse) 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)

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