Skip to content

Commit

Permalink
[resolves #458] Add support for camel-xmlsecurity data format
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesnetherton committed Mar 24, 2015
1 parent f3d3ba2 commit 9368e6e
Show file tree
Hide file tree
Showing 10 changed files with 200 additions and 0 deletions.
4 changes: 4 additions & 0 deletions itests/standalone/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@
<groupId>org.apache.camel</groupId>
<artifactId>camel-rss</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-xmlsecurity</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-xstream</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
/*
* #%L
* Wildfly Camel :: Testsuite
* %%
* Copyright (C) 2013 - 2014 RedHat
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/

package org.wildfly.camel.test.xmlsecurity;

import org.apache.camel.CamelContext;
import org.apache.camel.Message;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.xmlsecurity.api.KeyAccessor;
import org.apache.camel.impl.DefaultCamelContext;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.w3c.dom.Node;

import javax.naming.InitialContext;
import javax.xml.crypto.KeySelector;
import javax.xml.crypto.dsig.keyinfo.KeyInfo;
import javax.xml.crypto.dsig.keyinfo.KeyInfoFactory;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import java.security.SecureRandom;

@RunWith(Arquillian.class)
public class XmlSecurityIntegrationTest {

private static String XML_PAYLOAD = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+ "<root xmlns=\"http://test/test\"><test>Hello Kermit</test></root>";

private KeyPair keyPair;

@ArquillianResource
private InitialContext initialContext;

@Deployment
public static WebArchive createDeployment() {
final WebArchive archive = ShrinkWrap.create(WebArchive.class, "camel-test.war");
return archive;
}

@Before
public void setUp() throws Exception {
keyPair = setUpKeys();
initialContext.bind("accessor", getKeyAccessor(keyPair.getPrivate()));
initialContext.bind("selector", KeySelector.singletonKeySelector(keyPair.getPublic()));
}

@After
public void tearDown() throws Exception {
initialContext.unbind("accessor");
initialContext.unbind("selector");
}

@Test
public void testXmlSigning() throws Exception {
CamelContext camelctx = new DefaultCamelContext();

camelctx.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:start")
.to("xmlsecurity:sign://enveloping?keyAccessor=#accessor&schemaResourceUri=");
}
});

try {
camelctx.start();

ProducerTemplate producer = camelctx.createProducerTemplate();
String signedXml = producer.requestBody("direct:start", XML_PAYLOAD, String.class);

// Make sure the XML was signed
Assert.assertTrue(signedXml.contains("ds:SignatureValue"));
} finally {
camelctx.stop();
}
}

@Test
public void testXmlVerifySigning() throws Exception {
CamelContext camelctx = new DefaultCamelContext();

camelctx.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:start")
.to("xmlsecurity:sign://enveloping?keyAccessor=#accessor&schemaResourceUri=")
.to("xmlsecurity:verify://enveloping?keySelector=#selector");
}
});

try {
camelctx.start();

ProducerTemplate producer = camelctx.createProducerTemplate();
String verifiedXml = producer.requestBody("direct:start", XML_PAYLOAD, String.class);

// Make sure the XML was unsigned
Assert.assertEquals(XML_PAYLOAD, verifiedXml);
} finally {
camelctx.stop();
}
}

private KeyPair setUpKeys() {
KeyPairGenerator keyGen;
try {
keyGen = KeyPairGenerator.getInstance("RSA");
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
}
keyGen.initialize(1024, new SecureRandom());
return keyGen.generateKeyPair();
}

private static KeyAccessor getKeyAccessor(final PrivateKey privateKey) {
KeyAccessor accessor = new KeyAccessor() {

@Override
public KeySelector getKeySelector(Message message) throws Exception {
return KeySelector.singletonKeySelector(privateKey);
}

@Override
public KeyInfo getKeyInfo(Message mess, Node messageBody, KeyInfoFactory keyInfoFactory) throws Exception {
return null;
}
};
return accessor;
}
}
4 changes: 4 additions & 0 deletions modules/etc/baseline/exported-paths.txt
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,9 @@ org/apache/camel/component/servlet
org/apache/camel/component/servlet/osgi
org/apache/camel/component/sql
org/apache/camel/component/weather
org/apache/camel/component/xmlsecurity
org/apache/camel/component/xmlsecurity/api
org/apache/camel/component/xmlsecurity/processor
org/apache/camel/component/xquery
org/apache/camel/converter
org/apache/camel/converter/crypto
Expand All @@ -328,6 +331,7 @@ org/apache/camel/dataformat/csv
org/apache/camel/dataformat/flatpack
org/apache/camel/dataformat/protobuf
org/apache/camel/dataformat/rss
org/apache/camel/dataformat/xmlsecurity
org/apache/camel/dataformat/xstream
org/apache/camel/dataformat/zipfile
org/apache/camel/language
Expand Down
1 change: 1 addition & 0 deletions modules/etc/baseline/module-list.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
/org/apache/camel/component/soap/main/camel-soap-2.15.0.jar
/org/apache/camel/component/sql/main/camel-sql-2.15.0.jar
/org/apache/camel/component/weather/main/camel-weather-2.15.0.jar
/org/apache/camel/component/xmlsecurity/main/camel-xmlsecurity-2.15.0.jar
/org/apache/camel/component/xstream/main/camel-xstream-2.15.0.jar
/org/apache/camel/component/xstream/main/xmlpull-1.1.3.1.jar
/org/apache/camel/component/xstream/main/xpp3_min-1.1.4c.jar
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.1" name="org.apache.camel.component.xmlsecurity">
<resources>
<resource-root path="camel-xmlsecurity-2.15.0.jar" />
</resources>
<dependencies>
<module name="javax.api" />
<module name="org.slf4j" />
<module name="javax.xml.bind.api" />
<module name="org.apache.camel.core" />
<module name="org.apache.commons.codec" />
<module name="org.apache.santuario.xmlsec" slot="2.0" />
<module name="org.apache.xalan" />
</dependencies>
</module>
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<resource-root path="xmlsec-2.0.3.jar" />
</resources>
<dependencies>
<module name="javax.api" />
<module name="org.apache.commons.codec" />
<module name="org.codehaus.woodstox" />
<module name="org.slf4j" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
<module name="org.apache.camel.component.servlet" export="true" services="export" />
<module name="org.apache.camel.component.sql" export="true" services="export" />
<module name="org.apache.camel.component.weather" export="true" services="export" />
<module name="org.apache.camel.component.xmlsecurity" export="true" services="export" />
<module name="org.apache.camel.component.xstream" export="true" services="export" />
<module name="org.apache.camel.component.zipfile" export="true" services="export" />
</dependencies>
Expand Down
8 changes: 8 additions & 0 deletions modules/etc/smartics/camel-modules.xml
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,14 @@
</dependencies>
</module>

<module name="org.apache.camel.component.xmlsecurity">
<include artifact="org.apache.camel:camel-xmlsecurity" />
<dependencies>
<module name="javax.api"/>
<module name="org.slf4j"/>
</dependencies>
</module>

<module name="org.apache.camel.component.xstream">
<include artifact="org.apache.camel:camel-xstream" />
<include artifact="com.thoughtworks.xstream:xstream" />
Expand Down
3 changes: 3 additions & 0 deletions modules/etc/smartics/cxf-modules.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,8 @@

<module name="org.apache.santuario.xmlsec" slot="2.0" inherit-slot="false">
<include artifact="org.apache.santuario:xmlsec" />
<dependencies>
<module name="javax.api" />
</dependencies>
</module>
</modules>
5 changes: 5 additions & 0 deletions modules/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,11 @@
<artifactId>camel-weather</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-xmlsecurity</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-xstream</artifactId>
Expand Down

0 comments on commit 9368e6e

Please sign in to comment.