You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2014/07/24 09:31:29 UTC
git commit: CAMEL-7631. Enhancement for xmlsecurity component (XML
Signature): Configurable Signature Id. Thanks to Franz Forsthofer for the
patch.
Repository: camel
Updated Branches:
refs/heads/master 3c0e75bb0 -> 9afc1bd9b
CAMEL-7631. Enhancement for xmlsecurity component (XML Signature): Configurable Signature Id. Thanks to Franz Forsthofer for the patch.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/9afc1bd9
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/9afc1bd9
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/9afc1bd9
Branch: refs/heads/master
Commit: 9afc1bd9bae063a60faf0e0133a736cbf6aa8f94
Parents: 3c0e75b
Author: Claus Ibsen <da...@apache.org>
Authored: Thu Jul 24 09:31:17 2014 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Thu Jul 24 09:31:17 2014 +0200
----------------------------------------------------------------------
.../xmlsecurity/XmlSignerEndpoint.java | 12 ++-
.../xmlsecurity/api/XmlSignatureHelper.java | 4 +
.../xmlsecurity/api/XmlSignatureProperties.java | 7 +-
.../processor/XmlSignatureProcessor.java | 4 +-
.../processor/XmlSignerConfiguration.java | 21 +++-
.../processor/XmlSignerProcessor.java | 14 ++-
.../xmlsecurity/SpringXmlSignatureTest.java | 2 +-
.../component/xmlsecurity/XmlSignatureTest.java | 104 +++++++++++++------
.../xmlsecurity/SpringXmlSignatureTests.xml | 2 +-
9 files changed, 124 insertions(+), 46 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/9afc1bd9/components/camel-xmlsecurity/src/main/java/org/apache/camel/component/xmlsecurity/XmlSignerEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-xmlsecurity/src/main/java/org/apache/camel/component/xmlsecurity/XmlSignerEndpoint.java b/components/camel-xmlsecurity/src/main/java/org/apache/camel/component/xmlsecurity/XmlSignerEndpoint.java
index 993a979..26fd77a 100644
--- a/components/camel-xmlsecurity/src/main/java/org/apache/camel/component/xmlsecurity/XmlSignerEndpoint.java
+++ b/components/camel-xmlsecurity/src/main/java/org/apache/camel/component/xmlsecurity/XmlSignerEndpoint.java
@@ -169,12 +169,20 @@ public class XmlSignerEndpoint extends XmlSignatureEndpoint {
getConfiguration().setContentObjectId(contentObjectId);
}
- public List<XPathFilterParameterSpec> getXpathToIdAttributes() {
- return getConfiguration().getXpathToIdAttributes();
+ public List<XPathFilterParameterSpec> getXpathsToIdAttributes() {
+ return getConfiguration().getXpathsToIdAttributes();
}
public void setXpathsToIdAttributes(List<XPathFilterParameterSpec> xpathsToIdAttributes) {
getConfiguration().setXpathsToIdAttributes(xpathsToIdAttributes);
}
+ public String getSignatureId() {
+ return getConfiguration().getSignatureId();
+ }
+
+ public void setSignatureId(String signatureId) {
+ getConfiguration().setSignatureId(signatureId);
+ }
+
}
http://git-wip-us.apache.org/repos/asf/camel/blob/9afc1bd9/components/camel-xmlsecurity/src/main/java/org/apache/camel/component/xmlsecurity/api/XmlSignatureHelper.java
----------------------------------------------------------------------
diff --git a/components/camel-xmlsecurity/src/main/java/org/apache/camel/component/xmlsecurity/api/XmlSignatureHelper.java b/components/camel-xmlsecurity/src/main/java/org/apache/camel/component/xmlsecurity/api/XmlSignatureHelper.java
index 68f9f0f..2593e3b 100644
--- a/components/camel-xmlsecurity/src/main/java/org/apache/camel/component/xmlsecurity/api/XmlSignatureHelper.java
+++ b/components/camel-xmlsecurity/src/main/java/org/apache/camel/component/xmlsecurity/api/XmlSignatureHelper.java
@@ -162,6 +162,10 @@ public final class XmlSignatureHelper {
namespaceMap);
return params;
}
+
+ public static XPathFilterParameterSpec getXpathFilter(String xpath) {
+ return getXpathFilter(xpath, null);
+ }
@SuppressWarnings("unchecked")
public static XPathExpression getXPathExpression(XPathFilterParameterSpec xpathFilter) throws XPathExpressionException {
http://git-wip-us.apache.org/repos/asf/camel/blob/9afc1bd9/components/camel-xmlsecurity/src/main/java/org/apache/camel/component/xmlsecurity/api/XmlSignatureProperties.java
----------------------------------------------------------------------
diff --git a/components/camel-xmlsecurity/src/main/java/org/apache/camel/component/xmlsecurity/api/XmlSignatureProperties.java b/components/camel-xmlsecurity/src/main/java/org/apache/camel/component/xmlsecurity/api/XmlSignatureProperties.java
index 871793f..9fe72c8 100644
--- a/components/camel-xmlsecurity/src/main/java/org/apache/camel/component/xmlsecurity/api/XmlSignatureProperties.java
+++ b/components/camel-xmlsecurity/src/main/java/org/apache/camel/component/xmlsecurity/api/XmlSignatureProperties.java
@@ -42,7 +42,7 @@ public interface XmlSignatureProperties {
* @throws Exception
* if an error occurs during creating the output
*/
- Output get(Input input) throws Exception;
+ Output get(Input input) throws Exception; //NOPMD
public interface Input {
@@ -88,7 +88,10 @@ public interface XmlSignatureProperties {
*/
String getContentDigestAlgorithm();
- /** Signature Id. Can be <code>null</code>. */
+ /**
+ * Signature Id. Can be <code>null</code>, then no signature Id
+ * attribute is generated.
+ */
String getSignatureId();
/**
http://git-wip-us.apache.org/repos/asf/camel/blob/9afc1bd9/components/camel-xmlsecurity/src/main/java/org/apache/camel/component/xmlsecurity/processor/XmlSignatureProcessor.java
----------------------------------------------------------------------
diff --git a/components/camel-xmlsecurity/src/main/java/org/apache/camel/component/xmlsecurity/processor/XmlSignatureProcessor.java b/components/camel-xmlsecurity/src/main/java/org/apache/camel/component/xmlsecurity/processor/XmlSignatureProcessor.java
index d474084..9a425ba 100644
--- a/components/camel-xmlsecurity/src/main/java/org/apache/camel/component/xmlsecurity/processor/XmlSignatureProcessor.java
+++ b/components/camel-xmlsecurity/src/main/java/org/apache/camel/component/xmlsecurity/processor/XmlSignatureProcessor.java
@@ -50,7 +50,7 @@ public abstract class XmlSignatureProcessor implements Processor {
try {
SantuarioUtil.initializeSantuario();
SantuarioUtil.addSantuarioJSR105Provider();
- } catch (Throwable t) {
+ } catch (Throwable t) { //NOPMD
// provider not in classpath, ignore and fall back to jre default
LOG.info("Cannot add the SantuarioJSR105Provider due to {0}, fall back to JRE default.", t);
}
@@ -101,7 +101,7 @@ public abstract class XmlSignatureProcessor implements Processor {
protected Schema getSchema(Message message) throws SAXException, XmlSignatureException, IOException {
String schemaResourceUri = getSchemaResourceUri(message);
- if (schemaResourceUri == null) {
+ if (schemaResourceUri == null || schemaResourceUri.isEmpty()) {
return null;
}
InputStream is = ResourceHelper.resolveResourceAsInputStream(getConfiguration().getCamelContext().getClassResolver(),
http://git-wip-us.apache.org/repos/asf/camel/blob/9afc1bd9/components/camel-xmlsecurity/src/main/java/org/apache/camel/component/xmlsecurity/processor/XmlSignerConfiguration.java
----------------------------------------------------------------------
diff --git a/components/camel-xmlsecurity/src/main/java/org/apache/camel/component/xmlsecurity/processor/XmlSignerConfiguration.java b/components/camel-xmlsecurity/src/main/java/org/apache/camel/component/xmlsecurity/processor/XmlSignerConfiguration.java
index 6b2d4fe..e2a25e6 100644
--- a/components/camel-xmlsecurity/src/main/java/org/apache/camel/component/xmlsecurity/processor/XmlSignerConfiguration.java
+++ b/components/camel-xmlsecurity/src/main/java/org/apache/camel/component/xmlsecurity/processor/XmlSignerConfiguration.java
@@ -67,6 +67,9 @@ public class XmlSignerConfiguration extends XmlSignatureConfiguration {
private String contentObjectId;
+ // default value is null so that a unique ID is generated.
+ private String signatureId;
+
/**
* The URI of the content reference. This value can be overwritten by the
* header {@link XmlSignatureConstants#HEADER_CONTENT_REFERENCE_URI}. Can
@@ -322,6 +325,22 @@ public class XmlSignerConfiguration extends XmlSignatureConfiguration {
this.contentObjectId = contentObjectId;
}
+ public String getSignatureId() {
+ return signatureId;
+ }
+
+ /**
+ * Sets the signature Id. If this parameter is not set (null value) then a
+ * unique ID is generated for the signature ID (default). If this parameter
+ * is set to "" (empty string) then no Id attribute is created in the
+ * signature element.
+ *
+ * @param signatureId
+ */
+ public void setSignatureId(String signatureId) {
+ this.signatureId = signatureId;
+ }
+
public String getContentReferenceUri() {
return contentReferenceUri;
}
@@ -421,7 +440,7 @@ public class XmlSignerConfiguration extends XmlSignatureConfiguration {
this.propertiesName = propertiesName;
}
- public List<XPathFilterParameterSpec> getXpathToIdAttributes() {
+ public List<XPathFilterParameterSpec> getXpathsToIdAttributes() {
return xpathsToIdAttributes;
}
http://git-wip-us.apache.org/repos/asf/camel/blob/9afc1bd9/components/camel-xmlsecurity/src/main/java/org/apache/camel/component/xmlsecurity/processor/XmlSignerProcessor.java
----------------------------------------------------------------------
diff --git a/components/camel-xmlsecurity/src/main/java/org/apache/camel/component/xmlsecurity/processor/XmlSignerProcessor.java b/components/camel-xmlsecurity/src/main/java/org/apache/camel/component/xmlsecurity/processor/XmlSignerProcessor.java
index 1b8180e..4607aff 100644
--- a/components/camel-xmlsecurity/src/main/java/org/apache/camel/component/xmlsecurity/processor/XmlSignerProcessor.java
+++ b/components/camel-xmlsecurity/src/main/java/org/apache/camel/component/xmlsecurity/processor/XmlSignerProcessor.java
@@ -262,7 +262,13 @@ public class XmlSignerProcessor extends XmlSignatureProcessor {
// and this method must be called within the loop over the content reference URIs, because for each signature the key info ID must be different
final KeyInfo keyInfo = getConfiguration().getKeyAccessor().getKeyInfo(out, node, fac.getKeyInfoFactory());
- String signatureId = "_" + UUID.randomUUID().toString();
+ String signatureId = getConfiguration().getSignatureId();
+ if (signatureId == null) {
+ signatureId = "_" + UUID.randomUUID().toString();
+ } else if (signatureId.isEmpty()) {
+ // indicator that no signature Id attribute shall be generated
+ signatureId = null;
+ }
// parent only relevant for enveloping or detached signature
Node parent = getParentOfSignature(out, node, contentReferenceUri, signatureType);
@@ -344,7 +350,7 @@ public class XmlSignerProcessor extends XmlSignatureProcessor {
List<XPathFilterParameterSpec> result = (List<XPathFilterParameterSpec>) message
.getHeader(XmlSignatureConstants.HEADER_XPATHS_TO_ID_ATTRIBUTES);
if (result == null) {
- result = getConfiguration().getXpathToIdAttributes();
+ result = getConfiguration().getXpathsToIdAttributes();
}
return result;
}
@@ -635,7 +641,7 @@ public class XmlSignerProcessor extends XmlSignatureProcessor {
}
private List<String> getContentReferenceUrisForDetachedCase(Message message, Node messageBodyNode) throws XmlSignatureException,
- XPathExpressionException {
+ XPathExpressionException {
List<XPathFilterParameterSpec> xpathsToIdAttributes = getXpathToIdAttributes(message);
if (xpathsToIdAttributes.isEmpty()) {
// should not happen, has already been checked earlier
@@ -707,7 +713,7 @@ public class XmlSignerProcessor extends XmlSignatureProcessor {
}
private List<Transform> getTransforms(XMLSignatureFactory fac, SignatureType sigType) throws NoSuchAlgorithmException,
- InvalidAlgorithmParameterException {
+ InvalidAlgorithmParameterException {
List<AlgorithmMethod> configuredTrafos = getConfiguration().getTransformMethods();
if (SignatureType.enveloped == sigType) {
// add enveloped transform if necessary
http://git-wip-us.apache.org/repos/asf/camel/blob/9afc1bd9/components/camel-xmlsecurity/src/test/java/org/apache/camel/component/xmlsecurity/SpringXmlSignatureTest.java
----------------------------------------------------------------------
diff --git a/components/camel-xmlsecurity/src/test/java/org/apache/camel/component/xmlsecurity/SpringXmlSignatureTest.java b/components/camel-xmlsecurity/src/test/java/org/apache/camel/component/xmlsecurity/SpringXmlSignatureTest.java
index 628a532..3f7f089 100644
--- a/components/camel-xmlsecurity/src/test/java/org/apache/camel/component/xmlsecurity/SpringXmlSignatureTest.java
+++ b/components/camel-xmlsecurity/src/test/java/org/apache/camel/component/xmlsecurity/SpringXmlSignatureTest.java
@@ -66,7 +66,7 @@ public class SpringXmlSignatureTest extends XmlSignatureTest {
XmlSignerEndpoint endpoint = (XmlSignerEndpoint) context()
.getEndpoint(
"xmlsecurity:sign://detached?keyAccessor=#accessorRsa&xpathsToIdAttributes=#xpathsToIdAttributes&"//
- + "schemaResourceUri=org/apache/camel/component/xmlsecurity/Test.xsd&clearHeaders=false");
+ + "schemaResourceUri=org/apache/camel/component/xmlsecurity/Test.xsd&signatureId=&clearHeaders=false");
return endpoint;
}
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/9afc1bd9/components/camel-xmlsecurity/src/test/java/org/apache/camel/component/xmlsecurity/XmlSignatureTest.java
----------------------------------------------------------------------
diff --git a/components/camel-xmlsecurity/src/test/java/org/apache/camel/component/xmlsecurity/XmlSignatureTest.java b/components/camel-xmlsecurity/src/test/java/org/apache/camel/component/xmlsecurity/XmlSignatureTest.java
index 2562763..0965d3c 100644
--- a/components/camel-xmlsecurity/src/test/java/org/apache/camel/component/xmlsecurity/XmlSignatureTest.java
+++ b/components/camel-xmlsecurity/src/test/java/org/apache/camel/component/xmlsecurity/XmlSignatureTest.java
@@ -62,6 +62,8 @@ import javax.xml.xpath.XPathExpression;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;
+import org.w3c.dom.Attr;
+import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.xml.sax.SAXException;
@@ -140,7 +142,7 @@ public class XmlSignatureTest extends CamelTestSupport {
public void configure() throws Exception {
// START SNIPPET: enveloping XML signature
onException(XmlSignatureException.class).handled(true).to("mock:exception");
- from("direct:enveloping").to("xmlsecurity:sign://enveloping?keyAccessor=#accessor")
+ from("direct:enveloping").to("xmlsecurity:sign://enveloping?keyAccessor=#accessor&schemaResourceUri=")
.to("xmlsecurity:verify://enveloping?keySelector=#selector").to("mock:result");
// END SNIPPET: enveloping XML signature
}
@@ -349,7 +351,7 @@ public class XmlSignatureTest extends CamelTestSupport {
onException(Exception.class).handled(false).to("mock:exception");
from("direct:detached")
.to("xmlsecurity:sign://detached?keyAccessor=#keyAccessorDefault&xpathsToIdAttributes=#xpathsToIdAttributes&"//
- + "schemaResourceUri=org/apache/camel/component/xmlsecurity/Test.xsd&clearHeaders=false")
+ + "schemaResourceUri=org/apache/camel/component/xmlsecurity/Test.xsd&signatureId=&clearHeaders=false")
.to("mock:result")
.to("xmlsecurity:verify://detached?keySelector=#keySelectorDefault&schemaResourceUri=org/apache/camel/component/xmlsecurity/Test.xsd")
.to("mock:verified");
@@ -441,7 +443,7 @@ public class XmlSignatureTest extends CamelTestSupport {
Map<String, Object> headers = new TreeMap<String, Object>();
headers.put(XmlSignatureConstants.HEADER_OMIT_XML_DECLARATION, Boolean.TRUE);
InputStream payload = XmlSignatureTest.class
- .getResourceAsStream("/org/apache/camel/component/xmlsecurity/ExampleEnvelopedXmlSig.xml");
+ .getResourceAsStream("/org/apache/camel/component/xmlsecurity/ExampleEnvelopedXmlSig.xml");
assertNotNull("Cannot load payload", payload);
sendBody("direct:outputnodesearchelementname", payload, headers);
assertMockEndpointsSatisfied();
@@ -473,24 +475,23 @@ public class XmlSignatureTest extends CamelTestSupport {
public void testSetTransformMethodXpath2InRouteDefinition() throws Exception {
// example from http://www.w3.org/TR/2002/REC-xmldsig-filter2-20021108/
String payload = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
- + "<Document xmlns=\"http://test/test\"> "
- + "<ToBeSigned> "
- + " <!-- comment --> "
- + " <Data>1</Data> "
- + " <NotToBeSigned> "
- + " <ReallyToBeSigned> "
- + " <!-- comment --> "
- + " <Data>2</Data> "
- + " </ReallyToBeSigned> "
- + " </NotToBeSigned> "
- + " </ToBeSigned> "
- + " <ToBeSigned> "
- + " <Data>3</Data> "
- + " <NotToBeSigned> "
- + " <Data>4</Data> "
- + " </NotToBeSigned> "
- + " </ToBeSigned> "
- + "</Document>";
+ + "<Document xmlns=\"http://test/test\"> "
+ + "<ToBeSigned> "
+ + " <!-- comment --> "
+ + " <Data>1</Data> "
+ + " <NotToBeSigned> "
+ + " <ReallyToBeSigned> "
+ + " <!-- comment --> "
+ + " <Data>2</Data> "
+ + " </ReallyToBeSigned> "
+ + " </NotToBeSigned> "
+ + " </ToBeSigned> "
+ + " <ToBeSigned> "
+ + " <Data>3</Data> "
+ + " <NotToBeSigned> "
+ + " <Data>4</Data> "
+ + " </NotToBeSigned> "
+ + " </ToBeSigned> " + "</Document>";
setupMock(payload);
sendBody("direct:transformsXPath2", payload);
@@ -528,7 +529,7 @@ public class XmlSignatureTest extends CamelTestSupport {
public void testVerifyOutputNodeSearchElementName() throws Exception {
setupMock();
InputStream payload = XmlSignatureTest.class
- .getResourceAsStream("/org/apache/camel/component/xmlsecurity/ExampleEnvelopedXmlSig.xml");
+ .getResourceAsStream("/org/apache/camel/component/xmlsecurity/ExampleEnvelopedXmlSig.xml");
assertNotNull("Cannot load payload", payload);
sendBody("direct:outputnodesearchelementname", payload);
assertMockEndpointsSatisfied();
@@ -542,7 +543,7 @@ public class XmlSignatureTest extends CamelTestSupport {
endpoint.setOutputNodeSearch("{wrongformat"); // closing '}' missing
MockEndpoint mock = setupExceptionMock();
InputStream payload = XmlSignatureTest.class
- .getResourceAsStream("/org/apache/camel/component/xmlsecurity/ExampleEnvelopedXmlSig.xml");
+ .getResourceAsStream("/org/apache/camel/component/xmlsecurity/ExampleEnvelopedXmlSig.xml");
assertNotNull("Cannot load payload", payload);
sendBody("direct:outputnodesearchelementname", payload);
assertMockEndpointsSatisfied();
@@ -558,7 +559,7 @@ public class XmlSignatureTest extends CamelTestSupport {
// local name missing
MockEndpoint mock = setupExceptionMock();
InputStream payload = XmlSignatureTest.class
- .getResourceAsStream("/org/apache/camel/component/xmlsecurity/ExampleEnvelopedXmlSig.xml");
+ .getResourceAsStream("/org/apache/camel/component/xmlsecurity/ExampleEnvelopedXmlSig.xml");
assertNotNull("Cannot load payload", payload);
sendBody("direct:outputnodesearchelementname", payload);
assertMockEndpointsSatisfied();
@@ -569,7 +570,7 @@ public class XmlSignatureTest extends CamelTestSupport {
public void testExceptionVerifyOutputNodeSearchWrongElementName() throws Exception {
MockEndpoint mock = setupExceptionMock();
InputStream payload = XmlSignatureTest.class
- .getResourceAsStream("/org/apache/camel/component/xmlsecurity/ExampleEnvelopingDigSig.xml");
+ .getResourceAsStream("/org/apache/camel/component/xmlsecurity/ExampleEnvelopingDigSig.xml");
assertNotNull("Cannot load payload", payload);
sendBody("direct:outputnodesearchelementname", payload);
assertMockEndpointsSatisfied();
@@ -580,7 +581,7 @@ public class XmlSignatureTest extends CamelTestSupport {
public void testExceptionVerifyOutputNodeSearchElementNameMoreThanOneOutputElement() throws Exception {
MockEndpoint mock = setupExceptionMock();
InputStream payload = XmlSignatureTest.class
- .getResourceAsStream("/org/apache/camel/component/xmlsecurity/ExampleEnvelopingDigSigWithSeveralElementsWithNameRoot.xml");
+ .getResourceAsStream("/org/apache/camel/component/xmlsecurity/ExampleEnvelopingDigSigWithSeveralElementsWithNameRoot.xml");
assertNotNull("Cannot load payload", payload);
sendBody("direct:outputnodesearchelementname", payload);
assertMockEndpointsSatisfied();
@@ -591,7 +592,7 @@ public class XmlSignatureTest extends CamelTestSupport {
public void testVerifyOutputNodeSearchXPath() throws Exception {
setupMock();
InputStream payload = XmlSignatureTest.class
- .getResourceAsStream("/org/apache/camel/component/xmlsecurity/ExampleEnvelopedXmlSig.xml");
+ .getResourceAsStream("/org/apache/camel/component/xmlsecurity/ExampleEnvelopedXmlSig.xml");
assertNotNull("Cannot load payload", payload);
sendBody("direct:outputnodesearchxpath", payload);
assertMockEndpointsSatisfied();
@@ -785,6 +786,41 @@ public class XmlSignatureTest extends CamelTestSupport {
@Test
public void testDetachedSignature() throws Exception {
+ testDetachedSignatureInternal();
+ }
+
+ @Test
+ public void testSignatureIdAtributeNull() throws Exception {
+ // the signature Id parameter must be empty, this is set in the URI already
+ Element sigEle = testDetachedSignatureInternal();
+ Attr attr = sigEle.getAttributeNode("Id");
+ assertNull("Signature element contains Id attribute", attr);
+ }
+
+ @Test
+ public void testSignatureIdAttribute() throws Exception {
+ String signatureId = "sigId";
+ XmlSignerEndpoint endpoint = getDetachedSignerEndpoint();
+ endpoint.setSignatureId(signatureId);
+ Element sigEle = testDetachedSignatureInternal();
+ String value = sigEle.getAttribute("Id");
+ assertNotNull("Signature Id is null", value);
+ assertEquals(signatureId, value);
+ }
+
+ @Test
+ public void testSignatureIdAttributeGenerated() throws Exception {
+ String signatureId = null;
+ XmlSignerEndpoint endpoint = getDetachedSignerEndpoint();
+ endpoint.setSignatureId(signatureId);
+ Element sigEle = testDetachedSignatureInternal();
+ String value = sigEle.getAttribute("Id");
+ assertNotNull("Signature Id is null", value);
+ assertTrue("Signature Id value does not start with '_'", value.startsWith("_"));
+ }
+
+ private Element testDetachedSignatureInternal() throws InterruptedException, XPathExpressionException, SAXException, IOException,
+ ParserConfigurationException {
String detachedPayload = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + //
"<ns:root xmlns:ns=\"http://test\"><a ID=\"myID\"><b>bValue</b></a></ns:root>";
MockEndpoint mock = getMockEndpoint("mock:result");
@@ -796,7 +832,9 @@ public class XmlSignatureTest extends CamelTestSupport {
Map<String, String> namespaceMap = new TreeMap<String, String>();
namespaceMap.put("ns", "http://test");
namespaceMap.put("ds", XMLSignature.XMLNS);
- checkXpath(mock, "ns:root/ds:Signature", namespaceMap);
+ Object obj = checkXpath(mock, "ns:root/ds:Signature", namespaceMap);
+ Element sigEle = (Element) obj;
+ return sigEle;
}
@Test
@@ -970,10 +1008,9 @@ public class XmlSignatureTest extends CamelTestSupport {
}
XmlSignerEndpoint getDetachedSignerEndpoint() {
- XmlSignerEndpoint endpoint = (XmlSignerEndpoint) context()
- .getEndpoint(
- "xmlsecurity:sign://detached?keyAccessor=#keyAccessorDefault&xpathsToIdAttributes=#xpathsToIdAttributes&"//
- + "schemaResourceUri=org/apache/camel/component/xmlsecurity/Test.xsd&clearHeaders=false");
+ XmlSignerEndpoint endpoint = (XmlSignerEndpoint) context().getEndpoint(
+ "xmlsecurity:sign://detached?keyAccessor=#keyAccessorDefault&xpathsToIdAttributes=#xpathsToIdAttributes&"//
+ + "schemaResourceUri=org/apache/camel/component/xmlsecurity/Test.xsd&signatureId=&clearHeaders=false");
return endpoint;
}
@@ -985,7 +1022,7 @@ public class XmlSignatureTest extends CamelTestSupport {
body.contains(expectedPartContent));
}
- private void checkXpath(MockEndpoint mock, String xpathString, final Map<String, String> prefix2Namespace)
+ private Object checkXpath(MockEndpoint mock, String xpathString, final Map<String, String> prefix2Namespace)
throws XPathExpressionException, SAXException, IOException, ParserConfigurationException {
Message mess = getMessage(mock);
InputStream body = mess.getBody(InputStream.class);
@@ -1014,6 +1051,7 @@ public class XmlSignatureTest extends CamelTestSupport {
XPathExpression expr = xpath.compile(xpathString);
Object result = expr.evaluate(XmlSignatureHelper.newDocumentBuilder(true).parse(body), XPathConstants.NODE);
assertNotNull("The xpath " + xpathString + " returned a null value", result);
+ return result;
}
private Message getMessage(MockEndpoint mock) {
http://git-wip-us.apache.org/repos/asf/camel/blob/9afc1bd9/components/camel-xmlsecurity/src/test/resources/org/apache/camel/component/xmlsecurity/SpringXmlSignatureTests.xml
----------------------------------------------------------------------
diff --git a/components/camel-xmlsecurity/src/test/resources/org/apache/camel/component/xmlsecurity/SpringXmlSignatureTests.xml b/components/camel-xmlsecurity/src/test/resources/org/apache/camel/component/xmlsecurity/SpringXmlSignatureTests.xml
index 8ce4688..96ccd0c 100644
--- a/components/camel-xmlsecurity/src/test/resources/org/apache/camel/component/xmlsecurity/SpringXmlSignatureTests.xml
+++ b/components/camel-xmlsecurity/src/test/resources/org/apache/camel/component/xmlsecurity/SpringXmlSignatureTests.xml
@@ -262,7 +262,7 @@
<route>
<from uri="direct:detached" />
<to
- uri="xmlsecurity:sign://detached?keyAccessor=#accessorRsa&xpathsToIdAttributes=#xpathsToIdAttributes&schemaResourceUri=org/apache/camel/component/xmlsecurity/Test.xsd&clearHeaders=false" />
+ uri="xmlsecurity:sign://detached?keyAccessor=#accessorRsa&xpathsToIdAttributes=#xpathsToIdAttributes&schemaResourceUri=org/apache/camel/component/xmlsecurity/Test.xsd&signatureId=&clearHeaders=false" />
<to uri="mock:result" />
<to
uri="xmlsecurity:verify://detached?keySelector=#selectorRsa&schemaResourceUri=org/apache/camel/component/xmlsecurity/Test.xsd" />