Updated Branches: refs/heads/master 070c795ca -> 0db69352e
Added an unit test of WSSecurity with CXF_MESSAGE dataformat Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/0db69352 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/0db69352 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/0db69352 Branch: refs/heads/master Commit: 0db69352e38a9d11393e8c1aba293296507dd597 Parents: da8095f Author: Willem Jiang <ningji...@apache.org> Authored: Mon Jun 17 23:16:07 2013 +0800 Committer: Willem Jiang <ningji...@apache.org> Committed: Mon Jun 17 23:16:59 2013 +0800 ---------------------------------------------------------------------- components/camel-cxf/pom.xml | 10 ++ .../cxf/wssecurity/camel/MyProcessor.java | 22 +++ .../wssecurity/camel/WSSecurityRouteTest.java | 62 +++++++++ .../component/cxf/wssecurity/client/Client.java | 104 ++++++++++++++ .../wssecurity/client/UTPasswordCallback.java | 68 ++++++++++ .../cxf/wssecurity/server/CxfServer.java | 105 +++++++++++++++ .../cxf/wssecurity/server/GreeterImpl.java | 60 +++++++++ .../wssecurity/server/UTPasswordCallback.java | 68 ++++++++++ .../src/test/resources/hello_world_wssec.wsdl | 135 +++++++++++++++++++ .../cxf/wssecurity/camel/camel-context.xml | 93 +++++++++++++ .../component/cxf/wssecurity/client/wssec.xml | 45 +++++++ .../component/cxf/wssecurity/server/wssec.xml | 45 +++++++ .../wssecurity/etc/Client_Encrypt.properties | 5 + .../wssecurity/etc/Client_Sign.properties | 6 + .../wssecurity/etc/Server_Decrypt.properties | 5 + .../wssecurity/etc/Server_SignVerf.properties | 5 + .../wssecurity/keystore/client-keystore.jks | Bin 0 -> 1344 bytes .../wssecurity/keystore/client-truststore.jks | Bin 0 -> 639 bytes .../wssecurity/keystore/server-keystore.jks | Bin 0 -> 1345 bytes .../wssecurity/keystore/server-truststore.jks | Bin 0 -> 639 bytes 20 files changed, 838 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/0db69352/components/camel-cxf/pom.xml ---------------------------------------------------------------------- diff --git a/components/camel-cxf/pom.xml b/components/camel-cxf/pom.xml index b95f7ea..97b3711 100644 --- a/components/camel-cxf/pom.xml +++ b/components/camel-cxf/pom.xml @@ -236,6 +236,13 @@ <version>${cxf-version}</version> <scope>test</scope> </dependency> + + <dependency> + <groupId>org.apache.cxf</groupId> + <artifactId>cxf-rt-ws-security</artifactId> + <version>${cxf-version}</version> + <scope>test</scope> + </dependency> <dependency> <groupId>org.springframework</groupId> @@ -340,6 +347,9 @@ <wsdl>${basedir}/src/test/resources/mtom.wsdl</wsdl> </wsdlOption> <wsdlOption> + <wsdl>${basedir}/src/test/resources/hello_world_wssec.wsdl</wsdl> + </wsdlOption> + <wsdlOption> <wsdl>${basedir}/src/test/resources/MultiPartTest.wsdl</wsdl> </wsdlOption> <wsdlOption> http://git-wip-us.apache.org/repos/asf/camel/blob/0db69352/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/wssecurity/camel/MyProcessor.java ---------------------------------------------------------------------- diff --git a/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/wssecurity/camel/MyProcessor.java b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/wssecurity/camel/MyProcessor.java new file mode 100644 index 0000000..06bc461 --- /dev/null +++ b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/wssecurity/camel/MyProcessor.java @@ -0,0 +1,22 @@ +package org.apache.camel.component.cxf.wssecurity.camel; + +import java.io.InputStream; + +import javax.xml.soap.MessageFactory; +import javax.xml.soap.SOAPMessage; + +import org.apache.camel.Exchange; +import org.apache.camel.Processor; + +public class MyProcessor implements Processor { + + @Override + public void process(Exchange exchange) throws Exception { + // take out the soap message as an inputStream + InputStream is = exchange.getIn().getBody(InputStream.class); + // put it as an soap message + SOAPMessage message = MessageFactory.newInstance().createMessage(null, is); + exchange.getOut().setBody(message); + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/0db69352/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/wssecurity/camel/WSSecurityRouteTest.java ---------------------------------------------------------------------- diff --git a/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/wssecurity/camel/WSSecurityRouteTest.java b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/wssecurity/camel/WSSecurityRouteTest.java new file mode 100644 index 0000000..b7c55e7 --- /dev/null +++ b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/wssecurity/camel/WSSecurityRouteTest.java @@ -0,0 +1,62 @@ +package org.apache.camel.component.cxf.wssecurity.camel; + +import org.apache.camel.CamelContext; +import org.apache.camel.component.cxf.CXFTestSupport; +import org.apache.camel.component.cxf.wssecurity.client.Client; +import org.apache.camel.component.cxf.wssecurity.server.CxfServer; +import org.apache.camel.hello_world_soap_http.Greeter; +import org.apache.camel.spring.SpringCamelContext; +import org.apache.camel.test.junit4.CamelTestSupport; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.springframework.context.support.AbstractXmlApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +public class WSSecurityRouteTest extends CamelTestSupport { + protected CxfServer cxfServer; + protected AbstractXmlApplicationContext applicationContext; + + @Before + public void setUp() throws Exception { + //start the back end service + int port = CXFTestSupport.getPort1(); + cxfServer = new CxfServer(port); + applicationContext = createApplicationContext(); + super.setUp(); + } + + @After + public void shutdownService() { + if (cxfServer != null) { + cxfServer.stop(); + } + if (applicationContext != null) { + applicationContext.stop(); + } + } + + + @Override + protected CamelContext createCamelContext() throws Exception { + return SpringCamelContext.springCamelContext(applicationContext); + } + + + protected ClassPathXmlApplicationContext createApplicationContext() { + return new ClassPathXmlApplicationContext("org/apache/camel/component/cxf/wssecurity/camel/camel-context.xml"); + } + + protected String getRouterAddress() { + return "http://localhost:" + CXFTestSupport.getPort2() + "/WSSecurityRouteTest/GreeterPort"; + } + + @Test + public void testInvokeService() throws Exception { + Client client = new Client(getRouterAddress()); + Greeter greeter = client.getClient(); + assertEquals("Get a wrong response", "Hello Security", greeter.greetMe("Security")); + } + + +} http://git-wip-us.apache.org/repos/asf/camel/blob/0db69352/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/wssecurity/client/Client.java ---------------------------------------------------------------------- diff --git a/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/wssecurity/client/Client.java b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/wssecurity/client/Client.java new file mode 100644 index 0000000..3c18e00 --- /dev/null +++ b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/wssecurity/client/Client.java @@ -0,0 +1,104 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ + +package org.apache.camel.component.cxf.wssecurity.client; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.camel.hello_world_soap_http.Greeter; +import org.apache.cxf.jaxws.JaxWsProxyFactoryBean; +import org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor; +import org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor; + + +public final class Client { + + //private static final String WSU_NS + // = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"; + private JaxWsProxyFactoryBean bean; + + public Client(String address) throws Exception { + bean = new JaxWsProxyFactoryBean(); + bean.setAddress(address); + bean.getInInterceptors().add(getWSS4JInInterceptor()); + bean.getOutInterceptors().add(getWSS4JOutInterceptor()); + bean.setServiceClass(Greeter.class); + } + + public Greeter getClient() { + return bean.create(Greeter.class); + } + + + public static WSS4JOutInterceptor getWSS4JOutInterceptor() throws Exception { + + Map<String, Object> outProps = new HashMap<String, Object>(); + outProps.put("action", "Signature"); + // outProps.put("action", "UsernameToken Timestamp Signature Encrypt"); + + outProps.put("passwordType", "PasswordDigest"); + outProps.put("user", "clientx509v1"); + + // If you are using the patch WSS-194, then uncomment below two lines + // and comment the above "user" prop line. + // outProps.put("user", "abcd"); + // outProps.put("signatureUser", "clientx509v1"); + + outProps.put("passwordCallbackClass", + "org.apache.camel.component.cxf.wssecurity.client.UTPasswordCallback"); + + // outProps.put("encryptionUser", "serverx509v1"); + // outProps.put("encryptionPropFile", + // "wssecurity/etc/Client_Encrypt.properties"); + // outProps.put("encryptionKeyIdentifier", "IssuerSerial"); + // outProps.put("encryptionParts", + // "{Element}{" + WSU_NS + "}Timestamp;" + // + "{Content}{http://schemas.xmlsoap.org/soap/envelope/}Body"); + + outProps.put("signaturePropFile", "wssecurity/etc/Client_Sign.properties"); + outProps.put("signatureKeyIdentifier", "DirectReference"); + outProps.put("signatureParts", + // "{Element}{" + WSU_NS + "}Timestamp;" + "{Element}{http://schemas.xmlsoap.org/soap/envelope/}Body"); + + return new WSS4JOutInterceptor(outProps); + } + + public static WSS4JInInterceptor getWSS4JInInterceptor() throws Exception { + + Map<String, Object> inProps = new HashMap<String, Object>(); + + inProps.put("action", "Signature"); + // inProps.put("action", "UsernameToken Timestamp Signature Encrypt"); + // inProps.put("passwordType", "PasswordText"); + // inProps.put("passwordCallbackClass", + // "org.apache.camel.component.cxf.wssecurity.client.UTPasswordCallback"); + + // inProps.put("decryptionPropFile", + // "wssecurity/etc/Client_Sign.properties"); + // inProps.put("encryptionKeyIdentifier", "IssuerSerial"); + + inProps.put("signaturePropFile", "wssecurity/etc/Client_Encrypt.properties"); + inProps.put("signatureKeyIdentifier", "DirectReference"); + + return new WSS4JInInterceptor(inProps); + + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/0db69352/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/wssecurity/client/UTPasswordCallback.java ---------------------------------------------------------------------- diff --git a/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/wssecurity/client/UTPasswordCallback.java b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/wssecurity/client/UTPasswordCallback.java new file mode 100644 index 0000000..b4fdaf0 --- /dev/null +++ b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/wssecurity/client/UTPasswordCallback.java @@ -0,0 +1,68 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ +package org.apache.camel.component.cxf.wssecurity.client; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +import javax.security.auth.callback.Callback; +import javax.security.auth.callback.CallbackHandler; +import javax.security.auth.callback.UnsupportedCallbackException; + +import org.apache.ws.security.WSPasswordCallback; + +/** + */ + +public class UTPasswordCallback implements CallbackHandler { + + private Map<String, String> passwords = + new HashMap<String, String>(); + + public UTPasswordCallback() { + passwords.put("Alice", "ecilA"); + passwords.put("abcd", "dcba"); + passwords.put("clientx509v1", "storepassword"); + passwords.put("serverx509v1", "storepassword"); + } + + /** + * Here, we attempt to get the password from the private + * alias/passwords map. + */ + public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException { + for (int i = 0; i < callbacks.length; i++) { + WSPasswordCallback pc = (WSPasswordCallback)callbacks[i]; + + String pass = passwords.get(pc.getIdentifier()); + if (pass != null) { + pc.setPassword(pass); + return; + } + } + } + + /** + * Add an alias/password pair to the callback mechanism. + */ + public void setAliasPassword(String alias, String password) { + passwords.put(alias, password); + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/0db69352/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/wssecurity/server/CxfServer.java ---------------------------------------------------------------------- diff --git a/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/wssecurity/server/CxfServer.java b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/wssecurity/server/CxfServer.java new file mode 100644 index 0000000..ff7ddd3 --- /dev/null +++ b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/wssecurity/server/CxfServer.java @@ -0,0 +1,105 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ + +package org.apache.camel.component.cxf.wssecurity.server; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.cxf.endpoint.Server; +import org.apache.cxf.jaxws.JaxWsServerFactoryBean; +import org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor; +import org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor; + +public class CxfServer { + + //private static final String WSU_NS + // = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"; + + private String address; + + private Server server; + + public CxfServer(int port) throws Exception { + Object implementor = new GreeterImpl(); + address = "http://localhost:" + port + "/WSSecurityRouteTest/GreeterPort"; + JaxWsServerFactoryBean bean = new JaxWsServerFactoryBean(); + bean.setAddress(address); + bean.setServiceBean(implementor); + bean.getInInterceptors().add(getWSS4JInInterceptor()); + bean.getOutInterceptors().add(getWSS4JOutInterceptor()); + server = bean.create(); + } + + public void stop() { + if (server != null) { + server.start(); + } + } + + public static WSS4JOutInterceptor getWSS4JOutInterceptor() throws Exception { + + Map<String, Object> outProps = new HashMap<String, Object>(); + outProps.put("action", "Signature"); + //outProps.put("action", "UsernameToken Timestamp Signature Encrypt"); + + outProps.put("passwordType", "PasswordText"); + outProps.put("user", "serverx509v1"); + outProps.put("passwordCallbackClass", "org.apache.camel.component.cxf.wssecurity.server.UTPasswordCallback"); + + //If you are using the patch WSS-194, then uncomment below two lines and + //comment the above "user" prop line. + //outProps.put("user", "Alice"); + //outProps.put("signatureUser", "serverx509v1"); + + //outProps.put("encryptionUser", "clientx509v1"); + //outProps.put("encryptionPropFile", "wssecurity/etc/Server_SignVerf.properties"); + //outProps.put("encryptionKeyIdentifier", "IssuerSerial"); + //outProps.put("encryptionParts", "{Element}{" + WSU_NS + "}Timestamp;" + // + "{Content}{http://schemas.xmlsoap.org/soap/envelope/}Body"); + + outProps.put("signaturePropFile", "wssecurity/etc/Server_Decrypt.properties"); + outProps.put("signatureKeyIdentifier", "DirectReference"); + outProps.put("signatureParts", //"{Element}{" + WSU_NS + "}Timestamp;" + "{Element}{http://schemas.xmlsoap.org/soap/envelope/}Body"); + + return new WSS4JOutInterceptor(outProps); + } + + public static WSS4JInInterceptor getWSS4JInInterceptor() throws Exception { + + Map<String, Object> inProps = new HashMap<String, Object>(); + + //inProps.put("action", "UsernameToken Timestamp Signature Encrypt"); + inProps.put("action", "Signature"); + inProps.put("passwordType", "PasswordDigest"); + inProps.put("passwordCallbackClass", "org.apache.camel.component.cxf.wssecurity.server.UTPasswordCallback"); + + //inProps.put("decryptionPropFile", "wssecurity/etc/Server_Decrypt.properties"); + //inProps.put("encryptionKeyIdentifier", "IssuerSerial"); + + inProps.put("signaturePropFile", "wssecurity/etc/Server_SignVerf.properties"); + inProps.put("signatureKeyIdentifier", "DirectReference"); + + return new WSS4JInInterceptor(inProps); + + } + + +} http://git-wip-us.apache.org/repos/asf/camel/blob/0db69352/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/wssecurity/server/GreeterImpl.java ---------------------------------------------------------------------- diff --git a/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/wssecurity/server/GreeterImpl.java b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/wssecurity/server/GreeterImpl.java new file mode 100644 index 0000000..ae07145 --- /dev/null +++ b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/wssecurity/server/GreeterImpl.java @@ -0,0 +1,60 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ + +package org.apache.camel.component.cxf.wssecurity.server; + +import java.util.logging.Logger; +import org.apache.camel.hello_world_soap_http.Greeter; + +@javax.jws.WebService(serviceName = "GreeterService", + portName = "GreeterPort", + endpointInterface = "org.apache.camel.hello_world_soap_http.Greeter", + targetNamespace = "http://camel.apache.org/hello_world_soap_http") + +public class GreeterImpl implements Greeter { + + private static final Logger LOG = + Logger.getLogger(GreeterImpl.class.getPackage().getName()); + + /* (non-Javadoc) + * @see org.apache.cxf.hello_world_soap_http.Greeter#greetMe(java.lang.String) + */ + public String greetMe(String me) { + LOG.info("Executing operation greetMe"); + LOG.info("Message received: " + me ); + return "Hello " + me; + } + + /* (non-Javadoc) + * @see org.apache.cxf.hello_world_soap_http.Greeter#greetMeOneWay(java.lang.String) + */ + public void greetMeOneWay(String me) { + LOG.info("Executing operation greetMeOneWay"); + LOG.info("Hello there " + me); + } + + /* (non-Javadoc) + * @see org.apache.cxf.hello_world_soap_http.Greeter#sayHi() + */ + public String sayHi() { + LOG.info("Executing operation sayHi"); + System.out.println("Executing operation sayHi\n"); + return "Bonjour"; + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/0db69352/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/wssecurity/server/UTPasswordCallback.java ---------------------------------------------------------------------- diff --git a/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/wssecurity/server/UTPasswordCallback.java b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/wssecurity/server/UTPasswordCallback.java new file mode 100644 index 0000000..60bf99b --- /dev/null +++ b/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/wssecurity/server/UTPasswordCallback.java @@ -0,0 +1,68 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ +package org.apache.camel.component.cxf.wssecurity.server; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +import javax.security.auth.callback.Callback; +import javax.security.auth.callback.CallbackHandler; +import javax.security.auth.callback.UnsupportedCallbackException; + +import org.apache.ws.security.WSPasswordCallback; + +/** + */ + +public class UTPasswordCallback implements CallbackHandler { + + private Map<String, String> passwords = + new HashMap<String, String>(); + + public UTPasswordCallback() { + passwords.put("Alice", "ecilA"); + passwords.put("abcd", "dcba"); + passwords.put("clientx509v1", "storepassword"); + passwords.put("serverx509v1", "storepassword"); + } + + /** + * Here, we attempt to get the password from the private + * alias/passwords map. + */ + public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException { + for (int i = 0; i < callbacks.length; i++) { + WSPasswordCallback pc = (WSPasswordCallback)callbacks[i]; + + String pass = passwords.get(pc.getIdentifier()); + if (pass != null) { + pc.setPassword(pass); + return; + } + } + } + + /** + * Add an alias/password pair to the callback mechanism. + */ + public void setAliasPassword(String alias, String password) { + passwords.put(alias, password); + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/0db69352/components/camel-cxf/src/test/resources/hello_world_wssec.wsdl ---------------------------------------------------------------------- diff --git a/components/camel-cxf/src/test/resources/hello_world_wssec.wsdl b/components/camel-cxf/src/test/resources/hello_world_wssec.wsdl new file mode 100644 index 0000000..a19ccbe --- /dev/null +++ b/components/camel-cxf/src/test/resources/hello_world_wssec.wsdl @@ -0,0 +1,135 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you 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. +--> +<wsdl:definitions name="HelloWorld" targetNamespace="http://camel.apache.org/hello_world_soap_http" + xmlns="http://schemas.xmlsoap.org/wsdl/" + xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" + xmlns:tns="http://camel.apache.org/hello_world_soap_http" + xmlns:x1="http://camel.apache.org/hello_world_soap_http/types" + xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" + xmlns:xsd="http://www.w3.org/2001/XMLSchema"> + <wsdl:types> + <schema targetNamespace="http://camel.apache.org/hello_world_soap_http/types" + xmlns="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"> + <element name="sayHi"> + <complexType/> + </element> + <element name="sayHiResponse"> + <complexType> + <sequence> + <element name="responseType" type="xsd:string"/> + </sequence> + </complexType> + </element> + <element name="greetMe"> + <complexType> + <sequence> + <element name="requestType" type="xsd:string"/> + </sequence> + </complexType> + </element> + <element name="greetMeResponse"> + <complexType> + <sequence> + <element name="responseType" type="xsd:string"/> + </sequence> + </complexType> + </element> + <element name="greetMeOneWay"> + <complexType> + <sequence> + <element name="requestType" type="xsd:string"/> + </sequence> + </complexType> + </element> + </schema> + </wsdl:types> + + <wsdl:message name="sayHiRequest"> + <wsdl:part element="x1:sayHi" name="in"/> + </wsdl:message> + <wsdl:message name="sayHiResponse"> + <wsdl:part element="x1:sayHiResponse" name="out"/> + </wsdl:message> + <wsdl:message name="greetMeRequest"> + <wsdl:part element="x1:greetMe" name="in"/> + </wsdl:message> + <wsdl:message name="greetMeResponse"> + <wsdl:part element="x1:greetMeResponse" name="out"/> + </wsdl:message> + <wsdl:message name="greetMeOneWayRequest"> + <wsdl:part element="x1:greetMeOneWay" name="in"/> + </wsdl:message> + + <wsdl:portType name="Greeter"> + <wsdl:operation name="sayHi"> + <wsdl:input message="tns:sayHiRequest" name="sayHiRequest"/> + <wsdl:output message="tns:sayHiResponse" name="sayHiResponse"/> + </wsdl:operation> + + <wsdl:operation name="greetMe"> + <wsdl:input message="tns:greetMeRequest" name="greetMeRequest"/> + <wsdl:output message="tns:greetMeResponse" name="greetMeResponse"/> + </wsdl:operation> + + <wsdl:operation name="greetMeOneWay"> + <wsdl:input message="tns:greetMeOneWayRequest" name="greetMeOneWayRequest"/> + </wsdl:operation> + + </wsdl:portType> + + <wsdl:binding name="Greeter_SOAPBinding" type="tns:Greeter"> + <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/> + + <wsdl:operation name="sayHi"> + <soap:operation soapAction="" style="document"/> + <wsdl:input name="sayHiRequest"> + <soap:body use="literal"/> + </wsdl:input> + <wsdl:output name="sayHiResponse"> + <soap:body use="literal"/> + </wsdl:output> + </wsdl:operation> + + <wsdl:operation name="greetMe"> + <soap:operation soapAction="" style="document"/> + <wsdl:input name="greetMeRequest"> + <soap:body use="literal"/> + </wsdl:input> + <wsdl:output name="greetMeResponse"> + <soap:body use="literal"/> + </wsdl:output> + </wsdl:operation> + + <wsdl:operation name="greetMeOneWay"> + <soap:operation soapAction="" style="document"/> + <wsdl:input name="greetMeOneWayRequest"> + <soap:body use="literal"/> + </wsdl:input> + </wsdl:operation> + </wsdl:binding> + + <wsdl:service name="GreeterService"> + <wsdl:port binding="tns:Greeter_SOAPBinding" name="GreeterPort"> + <soap:address location="http://localhost:8000/SoapContext/GreeterPort"/> + <wswa:UsingAddressing xmlns:wswa="http://www.w3.org/2005/02/addressing/wsdl"/> + </wsdl:port> + </wsdl:service> +</wsdl:definitions> + http://git-wip-us.apache.org/repos/asf/camel/blob/0db69352/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/wssecurity/camel/camel-context.xml ---------------------------------------------------------------------- diff --git a/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/wssecurity/camel/camel-context.xml b/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/wssecurity/camel/camel-context.xml new file mode 100644 index 0000000..1398243 --- /dev/null +++ b/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/wssecurity/camel/camel-context.xml @@ -0,0 +1,93 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<beans xmlns="http://www.springframework.org/schema/beans" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:camel="http://camel.apache.org/schema/spring" + xmlns:cxf="http://camel.apache.org/schema/cxf" + xmlns:cxf-core="http://cxf.apache.org/core" + xmlns:wsa="http://cxf.apache.org/ws/addressing" + xsi:schemaLocation=" + http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd + http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd + http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd + http://camel.apache.org/schema/cxf http://camel.apache.org/schema/cxf/camel-cxf.xsd"> + + <cxf-core:bus> + <cxf-core:features> + <cxf-core:logging/> + <!-- wsa:addressing/--> + </cxf-core:features> + </cxf-core:bus> + + <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"/> + + <import resource="classpath:META-INF/cxf/cxf.xml"/> + + + <cxf:cxfEndpoint id="route" + address="http://localhost:${CXFTestSupport.port2}/WSSecurityRouteTest/GreeterPort" + serviceClass="org.apache.camel.hello_world_soap_http.Greeter"> + <cxf:properties> + <entry key="dataFormat" value="CXF_MESSAGE" /> + </cxf:properties> + + <cxf:inInterceptors> + <ref bean="wss4jInInterceptor" /> + </cxf:inInterceptors> + + </cxf:cxfEndpoint> + + <cxf:cxfEndpoint id="service" + address="http://localhost:${CXFTestSupport.port1}/WSSecurityRouteTest/GreeterPort" + serviceClass="org.apache.camel.hello_world_soap_http.Greeter"> + <cxf:properties> + <entry key="dataFormat" value="CXF_MESSAGE" /> + </cxf:properties> + + </cxf:cxfEndpoint> + + + <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring"> + <route errorHandlerRef="noErrorHandler"> + <from uri="cxf:bean:route" /> + <process ref="myProcessor" /> + <to uri="cxf:bean:service"/> + <process ref="myProcessor" /> + </route> + + </camelContext> + + <bean id="noErrorHandler" class="org.apache.camel.builder.NoErrorHandlerBuilder"/> + <bean id="myProcessor" class="org.apache.camel.component.cxf.wssecurity.camel.MyProcessor"/> + + <bean id="wss4jInInterceptor" class="org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor"> + <constructor-arg> + <map> + <entry key="action" value="Signature" /> + <!-- entry key="passwordCallbackClass" value="org.apache.camel.component.cxf.wssecurity.server.UTPasswordCallback" /> + <entry key="passwordType" value="PasswordDigest" /--> + <!-- entry key="decryptionPropFile" value="wssecurity/etc/Server_Decrypt.properties" /> + <entry key="encryptionKeyIdentifier" value="IssuerSerial" /--> + + <entry key="signaturePropFile" value="wssecurity/etc/Server_SignVerf.properties"/> + <entry key="signatureKeyIdentifier" value="DirectReference"/> + </map> + </constructor-arg> + </bean> + +</beans> http://git-wip-us.apache.org/repos/asf/camel/blob/0db69352/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/wssecurity/client/wssec.xml ---------------------------------------------------------------------- diff --git a/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/wssecurity/client/wssec.xml b/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/wssecurity/client/wssec.xml new file mode 100644 index 0000000..6526527 --- /dev/null +++ b/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/wssecurity/client/wssec.xml @@ -0,0 +1,45 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you 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. +--> +<beans xmlns="http://www.springframework.org/schema/beans" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:cxf="http://cxf.apache.org/core" + xmlns:wsa="http://cxf.apache.org/ws/addressing" + xmlns:http="http://cxf.apache.org/transports/http/configuration" + xmlns:wsrm-policy="http://schemas.xmlsoap.org/ws/2005/02/rm/policy" + xmlns:wsrm-mgr="http://cxf.apache.org/ws/rm/manager" + xsi:schemaLocation=" + http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd + http://cxf.apache.org/transports/http/configuration http://cxf.apache.org/schemas/configuration/http-conf.xsd + http://schemas.xmlsoap.org/ws/2005/02/rm/policy http://schemas.xmlsoap.org/ws/2005/02/rm/wsrm-policy.xsd + http://cxf.apache.org/ws/rm/manager http://cxf.apache.org/schemas/configuration/wsrm-manager.xsd + http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> + + <cxf:bus> + <cxf:features> + <cxf:logging/> + <!-- wsa:addressing/--> + </cxf:features> + </cxf:bus> + + <http:conduit name="{http://cxf.apache.org/hello_world_soap_http}GreeterPort.http-conduit"> + <http:client DecoupledEndpoint="http://localhost:9990/decoupled_endpoint"/> + </http:conduit> + +</beans> http://git-wip-us.apache.org/repos/asf/camel/blob/0db69352/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/wssecurity/server/wssec.xml ---------------------------------------------------------------------- diff --git a/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/wssecurity/server/wssec.xml b/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/wssecurity/server/wssec.xml new file mode 100644 index 0000000..6526527 --- /dev/null +++ b/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/wssecurity/server/wssec.xml @@ -0,0 +1,45 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you 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. +--> +<beans xmlns="http://www.springframework.org/schema/beans" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:cxf="http://cxf.apache.org/core" + xmlns:wsa="http://cxf.apache.org/ws/addressing" + xmlns:http="http://cxf.apache.org/transports/http/configuration" + xmlns:wsrm-policy="http://schemas.xmlsoap.org/ws/2005/02/rm/policy" + xmlns:wsrm-mgr="http://cxf.apache.org/ws/rm/manager" + xsi:schemaLocation=" + http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd + http://cxf.apache.org/transports/http/configuration http://cxf.apache.org/schemas/configuration/http-conf.xsd + http://schemas.xmlsoap.org/ws/2005/02/rm/policy http://schemas.xmlsoap.org/ws/2005/02/rm/wsrm-policy.xsd + http://cxf.apache.org/ws/rm/manager http://cxf.apache.org/schemas/configuration/wsrm-manager.xsd + http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> + + <cxf:bus> + <cxf:features> + <cxf:logging/> + <!-- wsa:addressing/--> + </cxf:features> + </cxf:bus> + + <http:conduit name="{http://cxf.apache.org/hello_world_soap_http}GreeterPort.http-conduit"> + <http:client DecoupledEndpoint="http://localhost:9990/decoupled_endpoint"/> + </http:conduit> + +</beans> http://git-wip-us.apache.org/repos/asf/camel/blob/0db69352/components/camel-cxf/src/test/resources/wssecurity/etc/Client_Encrypt.properties ---------------------------------------------------------------------- diff --git a/components/camel-cxf/src/test/resources/wssecurity/etc/Client_Encrypt.properties b/components/camel-cxf/src/test/resources/wssecurity/etc/Client_Encrypt.properties new file mode 100644 index 0000000..d7b5ba1 --- /dev/null +++ b/components/camel-cxf/src/test/resources/wssecurity/etc/Client_Encrypt.properties @@ -0,0 +1,5 @@ +org.apache.ws.security.crypto.provider=org.apache.ws.security.components.crypto.Merlin +org.apache.ws.security.crypto.merlin.keystore.type=jks +org.apache.ws.security.crypto.merlin.keystore.password=storepassword +org.apache.ws.security.crypto.merlin.keystore.alias=serverx509v1 +org.apache.ws.security.crypto.merlin.keystore.file=wssecurity/keystore/client-truststore.jks http://git-wip-us.apache.org/repos/asf/camel/blob/0db69352/components/camel-cxf/src/test/resources/wssecurity/etc/Client_Sign.properties ---------------------------------------------------------------------- diff --git a/components/camel-cxf/src/test/resources/wssecurity/etc/Client_Sign.properties b/components/camel-cxf/src/test/resources/wssecurity/etc/Client_Sign.properties new file mode 100644 index 0000000..07d5c82 --- /dev/null +++ b/components/camel-cxf/src/test/resources/wssecurity/etc/Client_Sign.properties @@ -0,0 +1,6 @@ +org.apache.ws.security.crypto.provider=org.apache.ws.security.components.crypto.Merlin +org.apache.ws.security.crypto.merlin.keystore.type=jks +org.apache.ws.security.crypto.merlin.keystore.password=storepassword +org.apache.ws.security.crypto.merlin.keystore.alias=clientx509v1 +org.apache.ws.security.crypto.merlin.keystore.file=wssecurity/keystore/client-keystore.jks + http://git-wip-us.apache.org/repos/asf/camel/blob/0db69352/components/camel-cxf/src/test/resources/wssecurity/etc/Server_Decrypt.properties ---------------------------------------------------------------------- diff --git a/components/camel-cxf/src/test/resources/wssecurity/etc/Server_Decrypt.properties b/components/camel-cxf/src/test/resources/wssecurity/etc/Server_Decrypt.properties new file mode 100644 index 0000000..1feacc1 --- /dev/null +++ b/components/camel-cxf/src/test/resources/wssecurity/etc/Server_Decrypt.properties @@ -0,0 +1,5 @@ +org.apache.ws.security.crypto.provider=org.apache.ws.security.components.crypto.Merlin +org.apache.ws.security.crypto.merlin.keystore.type=jks +org.apache.ws.security.crypto.merlin.keystore.password=storepassword +org.apache.ws.security.crypto.merlin.keystore.alias=serverx509v1 +org.apache.ws.security.crypto.merlin.keystore.file=wssecurity/keystore/server-keystore.jks http://git-wip-us.apache.org/repos/asf/camel/blob/0db69352/components/camel-cxf/src/test/resources/wssecurity/etc/Server_SignVerf.properties ---------------------------------------------------------------------- diff --git a/components/camel-cxf/src/test/resources/wssecurity/etc/Server_SignVerf.properties b/components/camel-cxf/src/test/resources/wssecurity/etc/Server_SignVerf.properties new file mode 100644 index 0000000..3557dc7 --- /dev/null +++ b/components/camel-cxf/src/test/resources/wssecurity/etc/Server_SignVerf.properties @@ -0,0 +1,5 @@ +org.apache.ws.security.crypto.provider=org.apache.ws.security.components.crypto.Merlin +org.apache.ws.security.crypto.merlin.keystore.type=jks +org.apache.ws.security.crypto.merlin.keystore.password=storepassword +org.apache.ws.security.crypto.merlin.keystore.alias=clientx509v1 +org.apache.ws.security.crypto.merlin.keystore.file=wssecurity/keystore/server-truststore.jks http://git-wip-us.apache.org/repos/asf/camel/blob/0db69352/components/camel-cxf/src/test/resources/wssecurity/keystore/client-keystore.jks ---------------------------------------------------------------------- diff --git a/components/camel-cxf/src/test/resources/wssecurity/keystore/client-keystore.jks b/components/camel-cxf/src/test/resources/wssecurity/keystore/client-keystore.jks new file mode 100644 index 0000000..bc744f9 Binary files /dev/null and b/components/camel-cxf/src/test/resources/wssecurity/keystore/client-keystore.jks differ http://git-wip-us.apache.org/repos/asf/camel/blob/0db69352/components/camel-cxf/src/test/resources/wssecurity/keystore/client-truststore.jks ---------------------------------------------------------------------- diff --git a/components/camel-cxf/src/test/resources/wssecurity/keystore/client-truststore.jks b/components/camel-cxf/src/test/resources/wssecurity/keystore/client-truststore.jks new file mode 100644 index 0000000..216bddb Binary files /dev/null and b/components/camel-cxf/src/test/resources/wssecurity/keystore/client-truststore.jks differ http://git-wip-us.apache.org/repos/asf/camel/blob/0db69352/components/camel-cxf/src/test/resources/wssecurity/keystore/server-keystore.jks ---------------------------------------------------------------------- diff --git a/components/camel-cxf/src/test/resources/wssecurity/keystore/server-keystore.jks b/components/camel-cxf/src/test/resources/wssecurity/keystore/server-keystore.jks new file mode 100644 index 0000000..22fd44e Binary files /dev/null and b/components/camel-cxf/src/test/resources/wssecurity/keystore/server-keystore.jks differ http://git-wip-us.apache.org/repos/asf/camel/blob/0db69352/components/camel-cxf/src/test/resources/wssecurity/keystore/server-truststore.jks ---------------------------------------------------------------------- diff --git a/components/camel-cxf/src/test/resources/wssecurity/keystore/server-truststore.jks b/components/camel-cxf/src/test/resources/wssecurity/keystore/server-truststore.jks new file mode 100644 index 0000000..2447028 Binary files /dev/null and b/components/camel-cxf/src/test/resources/wssecurity/keystore/server-truststore.jks differ