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"));
}
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"));
}
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));
}
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");
}
}
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());
}
}
Aggregations