Search in sources :

Example 16 with XMLSignatureInput

use of org.apache.xml.security.signature.XMLSignatureInput in project santuario-java by apache.

the class Transform method performTransform.

/**
 * Transforms the input, and generates {@link XMLSignatureInput} as output.
 *
 * @param input input {@link XMLSignatureInput} which can supplied Octect
 * Stream and NodeSet as Input of Transformation
 * @param os where to output the result of the last transformation
 * @return the {@link XMLSignatureInput} class as the result of
 * transformation
 * @throws CanonicalizationException
 * @throws IOException
 * @throws InvalidCanonicalizerException
 * @throws TransformationException
 */
public XMLSignatureInput performTransform(XMLSignatureInput input, OutputStream os) throws IOException, CanonicalizationException, InvalidCanonicalizerException, TransformationException {
    XMLSignatureInput result = null;
    try {
        transformSpi.secureValidation = secureValidation;
        result = transformSpi.enginePerformTransform(input, os, this);
    } catch (ParserConfigurationException ex) {
        Object[] exArgs = { this.getURI(), "ParserConfigurationException" };
        throw new CanonicalizationException(ex, "signature.Transform.ErrorDuringTransform", exArgs);
    } catch (SAXException ex) {
        Object[] exArgs = { this.getURI(), "SAXException" };
        throw new CanonicalizationException(ex, "signature.Transform.ErrorDuringTransform", exArgs);
    }
    return result;
}
Also used : CanonicalizationException(org.apache.xml.security.c14n.CanonicalizationException) XMLSignatureInput(org.apache.xml.security.signature.XMLSignatureInput) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException)

Example 17 with XMLSignatureInput

use of org.apache.xml.security.signature.XMLSignatureInput 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 18 with XMLSignatureInput

use of org.apache.xml.security.signature.XMLSignatureInput 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 19 with XMLSignatureInput

use of org.apache.xml.security.signature.XMLSignatureInput 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)

Example 20 with XMLSignatureInput

use of org.apache.xml.security.signature.XMLSignatureInput in project santuario-java by apache.

the class Canonicalizer20010315ExclusiveTest method testNodeSet.

/**
 * Tests node-set as input. See bug 37708.
 * Provided by Pete Hendry.
 */
@org.junit.Test
public void testNodeSet() 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:ns0=\"http://xmlsoap.org/Ping\"" + " 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 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();
    Set<Node> nodeSet = new HashSet<>();
    XMLUtils.getSet(doc.getDocumentElement().getFirstChild(), nodeSet, null, false);
    XMLSignatureInput input = new XMLSignatureInput(nodeSet);
    byte[] bytes = c14n.engineCanonicalize(input, "env ns0 xsi wsu");
    assertEquals(c14nXML, new String(bytes));
}
Also used : InputSource(org.xml.sax.InputSource) Node(org.w3c.dom.Node) StringReader(java.io.StringReader) XMLSignatureInput(org.apache.xml.security.signature.XMLSignatureInput) Document(org.w3c.dom.Document) Canonicalizer20010315ExclOmitComments(org.apache.xml.security.c14n.implementations.Canonicalizer20010315ExclOmitComments) HashSet(java.util.HashSet)

Aggregations

XMLSignatureInput (org.apache.xml.security.signature.XMLSignatureInput)42 Document (org.w3c.dom.Document)12 Element (org.w3c.dom.Element)12 InputStream (java.io.InputStream)11 ByteArrayInputStream (java.io.ByteArrayInputStream)9 Node (org.w3c.dom.Node)9 ResourceResolverException (org.apache.xml.security.utils.resolver.ResourceResolverException)8 IOException (java.io.IOException)7 Canonicalizer20010315ExclOmitComments (org.apache.xml.security.c14n.implementations.Canonicalizer20010315ExclOmitComments)6 XMLSecurityException (org.apache.xml.security.exceptions.XMLSecurityException)6 StringReader (java.io.StringReader)5 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)5 CanonicalizationException (org.apache.xml.security.c14n.CanonicalizationException)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 Transforms (org.apache.xml.security.transforms.Transforms)4 InputSource (org.xml.sax.InputSource)4 SAXException (org.xml.sax.SAXException)4 URISyntaxException (java.net.URISyntaxException)3 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)3 Set (java.util.Set)3