Search in sources :

Example 21 with XMLSignatureInput

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

the class TransformBase64DecodeTest method test2.

@org.junit.Test
public void test2() throws Exception {
    // base64 encoded twice
    String s2 = "VkdobElGVlNTU0J2WmlCMGFHVWdkSEpoYm5ObWIzSnRJR2x6SUdoMGRIQTZMeTkzZDNjdWR6TXVi\n" + "M0puTHpJd01EQXZNRGt2ZUcxcwpaSE5wWnlOaVlYTmxOalE9";
    Document doc = TransformBase64DecodeTest.createDocument();
    Transforms t = new Transforms(doc);
    doc.appendChild(t.getElement());
    t.addTransform(TransformBase64Decode.implementedTransformURI);
    XMLSignatureInput in = null;
    try (InputStream is = new ByteArrayInputStream(s2.getBytes())) {
        in = new XMLSignatureInput(is);
    }
    XMLSignatureInput out = t.performTransforms(t.performTransforms(in));
    String result = new String(out.getBytes());
    assertTrue(result.equals("The URI of the transform is http://www.w3.org/2000/09/xmldsig#base64"));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Transforms(org.apache.xml.security.transforms.Transforms) XMLSignatureInput(org.apache.xml.security.signature.XMLSignatureInput) Document(org.w3c.dom.Document)

Example 22 with XMLSignatureInput

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

the class TransformBase64DecodeTest method test1.

@org.junit.Test
public void test1() throws Exception {
    // base64 encoded
    String s1 = "VGhlIFVSSSBvZiB0aGUgdHJhbnNmb3JtIGlzIGh0dHA6Ly93d3cudzMub3JnLzIwMDAvMDkveG1s\n" + "ZHNpZyNiYXNlNjQ=";
    Document doc = TransformBase64DecodeTest.createDocument();
    Transforms t = new Transforms(doc);
    doc.appendChild(t.getElement());
    t.addTransform(TransformBase64Decode.implementedTransformURI);
    XMLSignatureInput in = null;
    try (InputStream is = new ByteArrayInputStream(s1.getBytes())) {
        in = new XMLSignatureInput(is);
    }
    XMLSignatureInput out = t.performTransforms(in);
    String result = new String(out.getBytes());
    assertTrue(result.equals("The URI of the transform is http://www.w3.org/2000/09/xmldsig#base64"));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Transforms(org.apache.xml.security.transforms.Transforms) XMLSignatureInput(org.apache.xml.security.signature.XMLSignatureInput) Document(org.w3c.dom.Document)

Example 23 with XMLSignatureInput

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

the class TransformXSLTTest method test1.

/**
 * Make sure Transform.performTransform does not throw NullPointerException.
 * See bug 41927 for more info.
 */
@org.junit.Test
public void test1() throws Exception {
    File file1 = null;
    File file2 = null;
    if (BASEDIR != null && !"".equals(BASEDIR)) {
        file1 = new File(BASEDIR + SEP + SOURCE_PATH, SIGNATURE_FILE);
        file2 = new File(BASEDIR + SEP + SOURCE_PATH, STYLESHEET_FILE);
    } else {
        file1 = new File(SOURCE_PATH, SIGNATURE_FILE);
        file1 = new File(SOURCE_PATH, STYLESHEET_FILE);
    }
    Document doc1 = getDocument(file1);
    Document doc2 = getDocument(file2);
    XPathFactory xpf = XPathFactory.newInstance();
    XPath xpath = xpf.newXPath();
    xpath.setNamespaceContext(new DSNamespaceContext());
    String expression = "//ds:Transform[1]";
    Element transformEl = (Element) xpath.evaluate(expression, doc1, XPathConstants.NODE);
    Transform transform = new Transform(doc1, Transforms.TRANSFORM_XSLT, transformEl.getChildNodes());
    transform.performTransform(new XMLSignatureInput(doc2));
}
Also used : XPath(javax.xml.xpath.XPath) XPathFactory(javax.xml.xpath.XPathFactory) DSNamespaceContext(org.apache.xml.security.test.dom.DSNamespaceContext) Element(org.w3c.dom.Element) XMLSignatureInput(org.apache.xml.security.signature.XMLSignatureInput) Document(org.w3c.dom.Document) Transform(org.apache.xml.security.transforms.Transform) File(java.io.File)

Example 24 with XMLSignatureInput

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

the class OfflineResolver method engineResolveURI.

/**
 * Method engineResolve
 *
 * @param context
 *
 * @throws ResourceResolverException
 */
@Override
public XMLSignatureInput engineResolveURI(ResourceResolverContext context) throws ResourceResolverException {
    try {
        String URI = context.uriToResolve;
        if (OfflineResolver._uriMap.containsKey(URI)) {
            String newURI = OfflineResolver._uriMap.get(URI);
            LOG.debug("Mapped " + URI + " to " + newURI);
            InputStream is = new FileInputStream(newURI);
            LOG.debug("Available bytes = " + is.available());
            XMLSignatureInput result = new XMLSignatureInput(is);
            result.setSourceURI(URI);
            result.setMIMEType(OfflineResolver._mimeMap.get(URI));
            return result;
        } else {
            Object[] exArgs = { "The URI " + URI + " is not configured for offline work" };
            throw new ResourceResolverException("generic.EmptyMessage", exArgs, context.uriToResolve, context.baseUri);
        }
    } catch (IOException ex) {
        throw new ResourceResolverException(ex, context.uriToResolve, context.baseUri, "generic.EmptyMessage");
    }
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) XMLSignatureInput(org.apache.xml.security.signature.XMLSignatureInput) ResourceResolverException(org.apache.xml.security.utils.resolver.ResourceResolverException) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream)

Example 25 with XMLSignatureInput

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

the class XMLSignatureInputTest method testOctetStreamIsNotNodeSet.

@org.junit.Test
public void testOctetStreamIsNotNodeSet() throws IOException {
    try (InputStream inputStream = new ByteArrayInputStream(_octetStreamTextInput.getBytes())) {
        XMLSignatureInput input = new XMLSignatureInput(inputStream);
        assertTrue("Input is not node set", !input.isNodeSet());
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) XMLSignatureInput(org.apache.xml.security.signature.XMLSignatureInput)

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