-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[resolves #458] Add support for camel-xmlsecurity data format
- Loading branch information
1 parent
f3d3ba2
commit 9368e6e
Showing
10 changed files
with
200 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
158 changes: 158 additions & 0 deletions
158
...andalone/src/test/java/org/wildfly/camel/test/xmlsecurity/XmlSecurityIntegrationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
...wildfly/modules/system/layers/fuse/org/apache/camel/component/xmlsecurity/main/module.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters