use of javax.xml.crypto.dsig.spec.XPathFilterParameterSpec in project camel by apache.
the class XmlSignatureTest method testDetached2Xpaths.
void testDetached2Xpaths(String xpath1exp, String xpath2exp) throws InterruptedException, XPathExpressionException, SAXException, IOException, ParserConfigurationException {
String detachedPayload = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + (includeNewLine ? "\n" : "") + "<ns:root xmlns:ns=\"http://test\"><test ID=\"myID\"><b>bValue</b><ts:B xmlns:ts=\"http://testB\"><C ID=\"cID\"><D>dvalue</D></C></ts:B></test></ns:root>";
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedMessageCount(1);
MockEndpoint mockVerified = getMockEndpoint("mock:verified");
mockVerified.expectedBodiesReceived(detachedPayload);
Map<String, Object> headers = new TreeMap<String, Object>();
headers.put(XmlSignatureConstants.HEADER_SCHEMA_RESOURCE_URI, "org/apache/camel/component/xmlsecurity/TestComplex.xsd");
Map<String, String> namespaceMap = new TreeMap<String, String>();
namespaceMap.put("ns", "http://test");
namespaceMap.put("ns1", "http://testB");
XPathFilterParameterSpec xpath1 = XmlSignatureHelper.getXpathFilter(xpath1exp, namespaceMap);
XPathFilterParameterSpec xpath2 = XmlSignatureHelper.getXpathFilter(xpath2exp, namespaceMap);
List<XPathFilterParameterSpec> xpaths = new ArrayList<XPathFilterParameterSpec>();
xpaths.add(xpath1);
xpaths.add(xpath2);
headers.put(XmlSignatureConstants.HEADER_XPATHS_TO_ID_ATTRIBUTES, xpaths);
sendBody("direct:detached", detachedPayload, headers);
assertMockEndpointsSatisfied();
Map<String, String> namespaceMap2 = new TreeMap<String, String>();
namespaceMap2.put("ns", "http://test");
namespaceMap2.put("ds", XMLSignature.XMLNS);
namespaceMap2.put("nsB", "http://testB");
checkXpath(mock, "ns:root/test/nsB:B/ds:Signature", namespaceMap2);
checkXpath(mock, "ns:root/ds:Signature", namespaceMap2);
}
use of javax.xml.crypto.dsig.spec.XPathFilterParameterSpec in project camel by apache.
the class XmlSignatureTest method testXpath.
private MockEndpoint testXpath(String xPath, String detachedPayload) throws InterruptedException {
MockEndpoint mock = setupExceptionMock();
mock.expectedMessageCount(1);
List<XPathFilterParameterSpec> list = Collections.singletonList(XmlSignatureHelper.getXpathFilter(xPath, null));
sendBody("direct:detached", detachedPayload, Collections.singletonMap(XmlSignatureConstants.HEADER_XPATHS_TO_ID_ATTRIBUTES, (Object) list));
assertMockEndpointsSatisfied();
return mock;
}
use of javax.xml.crypto.dsig.spec.XPathFilterParameterSpec in project camel by apache.
the class XmlSignatureTest method createRegistry.
@Override
protected JndiRegistry createRegistry() throws Exception {
JndiRegistry registry = super.createRegistry();
registry.bind("accessor", getKeyAccessor(keyPair.getPrivate()));
registry.bind("canonicalizationMethod1", getCanonicalizationMethod());
registry.bind("selector", KeySelector.singletonKeySelector(keyPair.getPublic()));
registry.bind("selectorKeyValue", getKeyValueKeySelector());
registry.bind("transformsXPath2", getTransformsXPath2());
registry.bind("transformsXsltXPath", getTransformsXsltXpath());
registry.bind("uriDereferencer", getSameDocumentUriDereferencer());
registry.bind("baseUri", getBaseUri());
registry.bind("cryptoContextProperties", getCrytoContextProperties());
registry.bind("keyAccessorDefault", getDefaultKeyAccessor());
registry.bind("keySelectorDefault", getDefaultKeySelector());
registry.bind("envelopingSignatureChecker", getEnvelopingXmlSignatureChecker());
registry.bind("xmlSignature2MessageWithTimestampProperty", getXmlSignature2MessageWithTimestampdProperty());
registry.bind("validationFailedHandlerIgnoreManifestFailures", getValidationFailedHandlerIgnoreManifestFailures());
registry.bind("signatureProperties", getSignatureProperties());
registry.bind("nodesearchxpath", getNodeSerachXPath());
Map<String, String> namespaceMap = Collections.singletonMap("ns", "http://test");
List<XPathFilterParameterSpec> xpaths = Collections.singletonList(XmlSignatureHelper.getXpathFilter("/ns:root/a/@ID", namespaceMap));
registry.bind("xpathsToIdAttributes", xpaths);
registry.bind("parentXpathBean", getParentXPathBean());
return registry;
}
use of javax.xml.crypto.dsig.spec.XPathFilterParameterSpec in project camel by apache.
the class XAdESSignaturePropertiesTest method createRegistry.
@Override
protected JndiRegistry createRegistry() throws Exception {
JndiRegistry registry = super.createRegistry();
registry.bind("keyAccessorDefault", TestKeystore.getKeyAccessor("bob"));
registry.bind("xmlSignatureProperties", getXmlSignatureProperties("bob"));
Map<String, String> namespaceMap = Collections.singletonMap("ns", "http://test");
List<XPathFilterParameterSpec> xpaths = Collections.singletonList(XmlSignatureHelper.getXpathFilter("/ns:root/a/@ID", namespaceMap));
registry.bind("xpathsToIdAttributes", xpaths);
return registry;
}
use of javax.xml.crypto.dsig.spec.XPathFilterParameterSpec in project camel by apache.
the class XmlSignatureTest method testExceptionXpathsToIdAttributesNameAndXPathSet.
@Test
public void testExceptionXpathsToIdAttributesNameAndXPathSet() throws Exception {
XmlSignerEndpoint endpoint = getSignatureEncpointForSignException();
MockEndpoint mock = setupExceptionMock();
try {
endpoint.setParentXpath(getNodeSerachXPath());
List<XPathFilterParameterSpec> xpaths = Collections.singletonList(XmlSignatureHelper.getXpathFilter("/ns:root/a/@ID", null));
endpoint.setXpathsToIdAttributes(xpaths);
sendBody("direct:signexceptions", payload);
assertMockEndpointsSatisfied();
checkThrownException(mock, XmlSignatureException.class, //
"The configuration of the XML signer component is wrong. " + "The parent XPath //pre:root for an enveloped signature and the XPATHs to ID attributes for a detached signature are specified. You must not specify both parameters.", null);
} finally {
endpoint.setParentXpath(null);
endpoint.setXpathsToIdAttributes(null);
}
}
Aggregations