From 9368e6e779c2ae02608e2a12965f38e89e4ef05d Mon Sep 17 00:00:00 2001 From: James Netherton Date: Tue, 24 Mar 2015 13:51:52 +0000 Subject: [PATCH] [resolves #458] Add support for camel-xmlsecurity data format --- itests/standalone/pom.xml | 4 + .../XmlSecurityIntegrationTest.java | 158 ++++++++++++++++++ modules/etc/baseline/exported-paths.txt | 4 + modules/etc/baseline/module-list.txt | 1 + .../component/xmlsecurity/main/module.xml | 15 ++ .../apache/santuario/xmlsec/2.0/module.xml | 1 + .../apache/camel/component/main/module.xml | 1 + modules/etc/smartics/camel-modules.xml | 8 + modules/etc/smartics/cxf-modules.xml | 3 + modules/pom.xml | 5 + 10 files changed, 200 insertions(+) create mode 100644 itests/standalone/src/test/java/org/wildfly/camel/test/xmlsecurity/XmlSecurityIntegrationTest.java create mode 100644 modules/etc/generated/wildfly/modules/system/layers/fuse/org/apache/camel/component/xmlsecurity/main/module.xml diff --git a/itests/standalone/pom.xml b/itests/standalone/pom.xml index b7f6327025..28b9d3a2c0 100644 --- a/itests/standalone/pom.xml +++ b/itests/standalone/pom.xml @@ -150,6 +150,10 @@ org.apache.camel camel-rss + + org.apache.camel + camel-xmlsecurity + org.apache.camel camel-xstream diff --git a/itests/standalone/src/test/java/org/wildfly/camel/test/xmlsecurity/XmlSecurityIntegrationTest.java b/itests/standalone/src/test/java/org/wildfly/camel/test/xmlsecurity/XmlSecurityIntegrationTest.java new file mode 100644 index 0000000000..9e53036d64 --- /dev/null +++ b/itests/standalone/src/test/java/org/wildfly/camel/test/xmlsecurity/XmlSecurityIntegrationTest.java @@ -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 = "\n" + + "Hello Kermit"; + + 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; + } +} diff --git a/modules/etc/baseline/exported-paths.txt b/modules/etc/baseline/exported-paths.txt index 0f0d70fab0..566902b2a2 100644 --- a/modules/etc/baseline/exported-paths.txt +++ b/modules/etc/baseline/exported-paths.txt @@ -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 @@ -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 diff --git a/modules/etc/baseline/module-list.txt b/modules/etc/baseline/module-list.txt index 0f2ab9c037..f15987cba1 100644 --- a/modules/etc/baseline/module-list.txt +++ b/modules/etc/baseline/module-list.txt @@ -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 diff --git a/modules/etc/generated/wildfly/modules/system/layers/fuse/org/apache/camel/component/xmlsecurity/main/module.xml b/modules/etc/generated/wildfly/modules/system/layers/fuse/org/apache/camel/component/xmlsecurity/main/module.xml new file mode 100644 index 0000000000..08d07cebc4 --- /dev/null +++ b/modules/etc/generated/wildfly/modules/system/layers/fuse/org/apache/camel/component/xmlsecurity/main/module.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/modules/etc/generated/wildfly/modules/system/layers/fuse/org/apache/santuario/xmlsec/2.0/module.xml b/modules/etc/generated/wildfly/modules/system/layers/fuse/org/apache/santuario/xmlsec/2.0/module.xml index 408e119967..276f577f97 100644 --- a/modules/etc/generated/wildfly/modules/system/layers/fuse/org/apache/santuario/xmlsec/2.0/module.xml +++ b/modules/etc/generated/wildfly/modules/system/layers/fuse/org/apache/santuario/xmlsec/2.0/module.xml @@ -4,6 +4,7 @@ + diff --git a/modules/etc/managed/wildfly/modules/system/layers/fuse/org/apache/camel/component/main/module.xml b/modules/etc/managed/wildfly/modules/system/layers/fuse/org/apache/camel/component/main/module.xml index c60c7427ac..6fc9cdf7e6 100644 --- a/modules/etc/managed/wildfly/modules/system/layers/fuse/org/apache/camel/component/main/module.xml +++ b/modules/etc/managed/wildfly/modules/system/layers/fuse/org/apache/camel/component/main/module.xml @@ -68,6 +68,7 @@ + diff --git a/modules/etc/smartics/camel-modules.xml b/modules/etc/smartics/camel-modules.xml index c987e3fcaa..24e36600c6 100644 --- a/modules/etc/smartics/camel-modules.xml +++ b/modules/etc/smartics/camel-modules.xml @@ -476,6 +476,14 @@ + + + + + + + + diff --git a/modules/etc/smartics/cxf-modules.xml b/modules/etc/smartics/cxf-modules.xml index 30911b0afc..d631e5eb7a 100644 --- a/modules/etc/smartics/cxf-modules.xml +++ b/modules/etc/smartics/cxf-modules.xml @@ -52,5 +52,8 @@ + + + diff --git a/modules/pom.xml b/modules/pom.xml index 346bc7d171..77705d29a1 100644 --- a/modules/pom.xml +++ b/modules/pom.xml @@ -266,6 +266,11 @@ camel-weather provided + + org.apache.camel + camel-xmlsecurity + provided + org.apache.camel camel-xstream