Search in sources :

Example 1 with XPathFilterParameterSpec

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;
}
Also used : JndiRegistry(org.apache.camel.impl.JndiRegistry) XPathFilterParameterSpec(javax.xml.crypto.dsig.spec.XPathFilterParameterSpec)

Example 2 with XPathFilterParameterSpec

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);
    }
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) XPathFilterParameterSpec(javax.xml.crypto.dsig.spec.XPathFilterParameterSpec) Test(org.junit.Test)

Example 3 with XPathFilterParameterSpec

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);
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) XPathFilterParameterSpec(javax.xml.crypto.dsig.spec.XPathFilterParameterSpec) ArrayList(java.util.ArrayList) TreeMap(java.util.TreeMap)

Example 4 with XPathFilterParameterSpec

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;
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) XPathFilterParameterSpec(javax.xml.crypto.dsig.spec.XPathFilterParameterSpec)

Example 5 with XPathFilterParameterSpec

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;
}
Also used : JndiRegistry(org.apache.camel.impl.JndiRegistry) XPathFilterParameterSpec(javax.xml.crypto.dsig.spec.XPathFilterParameterSpec)

Aggregations

XPathFilterParameterSpec (javax.xml.crypto.dsig.spec.XPathFilterParameterSpec)14 JndiRegistry (org.apache.camel.impl.JndiRegistry)4 XPathExpression (javax.xml.xpath.XPathExpression)3 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)3 Element (org.w3c.dom.Element)3 Node (org.w3c.dom.Node)3 NodeList (org.w3c.dom.NodeList)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 XPathExpressionException (javax.xml.xpath.XPathExpressionException)2 XmlSignatureException (org.apache.camel.component.xmlsecurity.api.XmlSignatureException)2 Attr (org.w3c.dom.Attr)2 NamedNodeMap (org.w3c.dom.NamedNodeMap)2 Key (java.security.Key)1 PrivateKey (java.security.PrivateKey)1 PublicKey (java.security.PublicKey)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 SecretKey (javax.crypto.SecretKey)1 XmlSignatureFormatException (org.apache.camel.component.xmlsecurity.api.XmlSignatureFormatException)1