Search in sources :

Example 1 with Canonicalizer20010315ExclOmitComments

use of org.apache.xml.security.c14n.implementations.Canonicalizer20010315ExclOmitComments in project santuario-java by apache.

the class TransformC14NExclusive method enginePerformTransform.

protected XMLSignatureInput enginePerformTransform(XMLSignatureInput input, OutputStream os, Transform transformObject) throws CanonicalizationException {
    try {
        String inclusiveNamespaces = null;
        if (transformObject.length(InclusiveNamespaces.ExclusiveCanonicalizationNamespace, InclusiveNamespaces._TAG_EC_INCLUSIVENAMESPACES) == 1) {
            Element inclusiveElement = XMLUtils.selectNode(transformObject.getElement().getFirstChild(), InclusiveNamespaces.ExclusiveCanonicalizationNamespace, InclusiveNamespaces._TAG_EC_INCLUSIVENAMESPACES, 0);
            inclusiveNamespaces = new InclusiveNamespaces(inclusiveElement, transformObject.getBaseURI()).getInclusiveNamespaces();
        }
        Canonicalizer20010315ExclOmitComments c14n = new Canonicalizer20010315ExclOmitComments();
        c14n.setSecureValidation(secureValidation);
        if (os != null) {
            c14n.setWriter(os);
        }
        byte[] result = c14n.engineCanonicalize(input, inclusiveNamespaces);
        XMLSignatureInput output = new XMLSignatureInput(result);
        output.setSecureValidation(secureValidation);
        if (os != null) {
            output.setOutputStream(os);
        }
        return output;
    } catch (XMLSecurityException ex) {
        throw new CanonicalizationException(ex);
    }
}
Also used : CanonicalizationException(org.apache.xml.security.c14n.CanonicalizationException) Element(org.w3c.dom.Element) InclusiveNamespaces(org.apache.xml.security.transforms.params.InclusiveNamespaces) XMLSignatureInput(org.apache.xml.security.signature.XMLSignatureInput) Canonicalizer20010315ExclOmitComments(org.apache.xml.security.c14n.implementations.Canonicalizer20010315ExclOmitComments) XMLSecurityException(org.apache.xml.security.exceptions.XMLSecurityException)

Example 2 with Canonicalizer20010315ExclOmitComments

use of org.apache.xml.security.c14n.implementations.Canonicalizer20010315ExclOmitComments in project santuario-java by apache.

the class Canonicalizer20010315ExclusiveTest method testDefaultNSInInclusiveNamespacePrefixList3.

/**
 * Test default namespace behavior if its in the InclusiveNamespace prefix list.
 *
 * @throws Exception
 */
@org.junit.Test
public void testDefaultNSInInclusiveNamespacePrefixList3() throws Exception {
    final String XML = "<env:Envelope" + " xmlns:env=\"http://schemas.xmlsoap.org/soap/envelope/\"" + " xmlns=\"\"" + " xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"" + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" + " xmlns:ns0=\"http://xmlsoap.org/Ping\"" + " xmlns:wsu=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\">" + "<env:Body wsu:Id=\"body\">" + "<ns0:Ping xsi:type=\"ns0:ping\">" + "<ns0:text xsi:type=\"xsd:string\">hello</ns0:text>" + "</ns0:Ping>" + "</env:Body>" + "</env:Envelope>";
    final String c14nXML = "<env:Body" + " xmlns:env=\"http://schemas.xmlsoap.org/soap/envelope/\"" + " xmlns:wsu=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\"" + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" + " wsu:Id=\"body\">" + "<ns0:Ping xmlns:ns0=\"http://xmlsoap.org/Ping\" xsi:type=\"ns0:ping\">" + "<ns0:text xsi:type=\"xsd:string\">hello</ns0:text>" + "</ns0:Ping>" + "</env:Body>";
    Document doc = this.db.parse(new InputSource(new StringReader(XML)));
    {
        Canonicalizer20010315ExclOmitComments c14n = new Canonicalizer20010315ExclOmitComments();
        XMLSignatureInput input = new XMLSignatureInput(doc.getDocumentElement().getFirstChild());
        byte[] bytes = c14n.engineCanonicalize(input, "#default xsi");
        assertEquals(c14nXML, new String(bytes));
    }
    {
        // exactly the same outcome is expected if #default is not set:
        Canonicalizer20010315ExclOmitComments c14n = new Canonicalizer20010315ExclOmitComments();
        XMLSignatureInput input = new XMLSignatureInput(doc.getDocumentElement().getFirstChild());
        byte[] bytes = c14n.engineCanonicalize(input, "xsi");
        assertEquals(c14nXML, new String(bytes));
    }
}
Also used : InputSource(org.xml.sax.InputSource) StringReader(java.io.StringReader) XMLSignatureInput(org.apache.xml.security.signature.XMLSignatureInput) Document(org.w3c.dom.Document) Canonicalizer20010315ExclOmitComments(org.apache.xml.security.c14n.implementations.Canonicalizer20010315ExclOmitComments)

Example 3 with Canonicalizer20010315ExclOmitComments

use of org.apache.xml.security.c14n.implementations.Canonicalizer20010315ExclOmitComments in project santuario-java by apache.

the class Canonicalizer20010315ExclusiveTest method testDefaultNSInInclusiveNamespacePrefixList4.

/**
 * Test default namespace behavior if its in the InclusiveNamespace prefix list.
 *
 * @throws Exception
 */
@org.junit.Test
public void testDefaultNSInInclusiveNamespacePrefixList4() throws Exception {
    final String XML = "<env:Envelope" + " xmlns:env=\"http://schemas.xmlsoap.org/soap/envelope/\"" + " xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"" + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" + " xmlns:ns0=\"http://xmlsoap.org/Ping\"" + " xmlns:wsu=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\">" + "<env:Body wsu:Id=\"body\">" + "<ns0:Ping xsi:type=\"ns0:ping\">" + "<ns0:text xmlns=\"\" xsi:type=\"xsd:string\">hello</ns0:text>" + "</ns0:Ping>" + "</env:Body>" + "</env:Envelope>";
    final String c14nXML = "<env:Body" + " xmlns:env=\"http://schemas.xmlsoap.org/soap/envelope/\"" + " xmlns:wsu=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\"" + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" + " wsu:Id=\"body\">" + "<ns0:Ping xmlns:ns0=\"http://xmlsoap.org/Ping\" xsi:type=\"ns0:ping\">" + "<ns0:text xsi:type=\"xsd:string\">hello</ns0:text>" + "</ns0:Ping>" + "</env:Body>";
    Document doc = this.db.parse(new InputSource(new StringReader(XML)));
    {
        Canonicalizer20010315ExclOmitComments c14n = new Canonicalizer20010315ExclOmitComments();
        XMLSignatureInput input = new XMLSignatureInput(doc.getDocumentElement().getFirstChild());
        byte[] bytes = c14n.engineCanonicalize(input, "#default xsi");
        assertEquals(c14nXML, new String(bytes));
    }
    {
        // exactly the same outcome is expected if #default is not set:
        Canonicalizer20010315ExclOmitComments c14n = new Canonicalizer20010315ExclOmitComments();
        XMLSignatureInput input = new XMLSignatureInput(doc.getDocumentElement().getFirstChild());
        byte[] bytes = c14n.engineCanonicalize(input, "xsi");
        assertEquals(c14nXML, new String(bytes));
    }
}
Also used : InputSource(org.xml.sax.InputSource) StringReader(java.io.StringReader) XMLSignatureInput(org.apache.xml.security.signature.XMLSignatureInput) Document(org.w3c.dom.Document) Canonicalizer20010315ExclOmitComments(org.apache.xml.security.c14n.implementations.Canonicalizer20010315ExclOmitComments)

Example 4 with Canonicalizer20010315ExclOmitComments

use of org.apache.xml.security.c14n.implementations.Canonicalizer20010315ExclOmitComments in project santuario-java by apache.

the class Canonicalizer20010315ExclusiveTest method testPropagateDefaultNs5.

@org.junit.Test
public void testPropagateDefaultNs5() throws Exception {
    final String XML = "<env:Envelope" + " xmlns=\"http://example.com\"" + " xmlns:env=\"http://schemas.xmlsoap.org/soap/envelope/\"" + " xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"" + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" + " xmlns:ns0=\"http://xmlsoap.org/Ping\"" + " xmlns:wsu=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\">" + "<env:Body xmlns=\"\" wsu:Id=\"body\">" + "<ns0:Ping xsi:type=\"ns0:ping\">" + "<ns0:text xsi:type=\"xsd:string\">hello</ns0:text>" + "</ns0:Ping>" + "</env:Body>" + "</env:Envelope>";
    final String c14nXML = "<ns0:Ping xmlns=\"\" xmlns:ns0=\"http://xmlsoap.org/Ping\" " + "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"ns0:ping\">" + "<ns0:text xsi:type=\"xsd:string\">hello</ns0:text>" + "</ns0:Ping>";
    Document doc = this.db.parse(new InputSource(new StringReader(XML)));
    Canonicalizer20010315ExclOmitComments c14n = new Canonicalizer20010315ExclOmitComments();
    byte[] bytes = c14n.engineCanonicalizeSubTree(doc.getDocumentElement().getFirstChild().getFirstChild(), "#default", true);
    assertEquals(c14nXML, new String(bytes));
}
Also used : InputSource(org.xml.sax.InputSource) StringReader(java.io.StringReader) Document(org.w3c.dom.Document) Canonicalizer20010315ExclOmitComments(org.apache.xml.security.c14n.implementations.Canonicalizer20010315ExclOmitComments)

Example 5 with Canonicalizer20010315ExclOmitComments

use of org.apache.xml.security.c14n.implementations.Canonicalizer20010315ExclOmitComments in project santuario-java by apache.

the class Canonicalizer20010315ExclusiveTest method testDefaultNSInInclusiveNamespacePrefixList1.

/**
 * Test default namespace behavior if its in the InclusiveNamespace prefix list.
 *
 * @throws Exception
 */
@org.junit.Test
public void testDefaultNSInInclusiveNamespacePrefixList1() throws Exception {
    final String XML = "<env:Envelope" + " xmlns:env=\"http://schemas.xmlsoap.org/soap/envelope/\"" + " xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"" + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" + " xmlns:ns0=\"http://xmlsoap.org/Ping\"" + " xmlns:wsu=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\">" + "<env:Body wsu:Id=\"body\">" + "<ns0:Ping xsi:type=\"ns0:ping\">" + "<ns0:text xsi:type=\"xsd:string\">hello</ns0:text>" + "</ns0:Ping>" + "</env:Body>" + "</env:Envelope>";
    final String c14nXML = "<env:Body" + " xmlns:env=\"http://schemas.xmlsoap.org/soap/envelope/\"" + " xmlns:wsu=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\"" + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" + " wsu:Id=\"body\">" + "<ns0:Ping xmlns:ns0=\"http://xmlsoap.org/Ping\" xsi:type=\"ns0:ping\">" + "<ns0:text xsi:type=\"xsd:string\">hello</ns0:text>" + "</ns0:Ping>" + "</env:Body>";
    Document doc = this.db.parse(new InputSource(new StringReader(XML)));
    {
        Canonicalizer20010315ExclOmitComments c14n = new Canonicalizer20010315ExclOmitComments();
        XMLSignatureInput input = new XMLSignatureInput(doc.getDocumentElement().getFirstChild());
        byte[] bytes = c14n.engineCanonicalize(input, "#default xsi");
        assertEquals(c14nXML, new String(bytes));
    }
    {
        // exactly the same outcome is expected if #default is not set:
        Canonicalizer20010315ExclOmitComments c14n = new Canonicalizer20010315ExclOmitComments();
        XMLSignatureInput input = new XMLSignatureInput(doc.getDocumentElement().getFirstChild());
        byte[] bytes = c14n.engineCanonicalize(input, "xsi");
        assertEquals(c14nXML, new String(bytes));
    }
}
Also used : InputSource(org.xml.sax.InputSource) StringReader(java.io.StringReader) XMLSignatureInput(org.apache.xml.security.signature.XMLSignatureInput) Document(org.w3c.dom.Document) Canonicalizer20010315ExclOmitComments(org.apache.xml.security.c14n.implementations.Canonicalizer20010315ExclOmitComments)

Aggregations

Canonicalizer20010315ExclOmitComments (org.apache.xml.security.c14n.implementations.Canonicalizer20010315ExclOmitComments)12 Document (org.w3c.dom.Document)11 StringReader (java.io.StringReader)10 InputSource (org.xml.sax.InputSource)10 XMLSignatureInput (org.apache.xml.security.signature.XMLSignatureInput)6 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 HashSet (java.util.HashSet)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1 CanonicalizationException (org.apache.xml.security.c14n.CanonicalizationException)1 Canonicalizer20010315Excl (org.apache.xml.security.c14n.implementations.Canonicalizer20010315Excl)1 XMLSecurityException (org.apache.xml.security.exceptions.XMLSecurityException)1 InclusiveNamespaces (org.apache.xml.security.transforms.params.InclusiveNamespaces)1 Element (org.w3c.dom.Element)1 Node (org.w3c.dom.Node)1