Author: davsclaus Date: Fri Jul 23 06:00:11 2010 New Revision: 966975 URL: http://svn.apache.org/viewvc?rev=966975&view=rev Log: Added ws securiry example
Modified: camel/trunk/examples/camel-example-reportincident-ws-security-osgi/ (props changed) camel/trunk/examples/camel-example-reportincident-ws-security-osgi/README.txt camel/trunk/examples/camel-example-reportincident-ws-security-osgi/pom.xml camel/trunk/examples/camel-example-reportincident-ws-security-osgi/src/main/java/org/apache/camel/example/reportincident/UTPasswordCallback.java camel/trunk/examples/camel-example-reportincident-ws-security-osgi/src/main/resources/META-INF/spring/camel-context.xml camel/trunk/examples/camel-example-reportincident-ws-security-osgi/src/main/resources/log4j.properties camel/trunk/examples/camel-example-reportincident-ws-security-osgi/src/test/java/org/apache/camel/example/reportincident/ReportIncidentRoutesTest.java camel/trunk/examples/camel-example-reportincident-ws-security-osgi/src/test/resources/log4j.properties camel/trunk/examples/pom.xml Propchange: camel/trunk/examples/camel-example-reportincident-ws-security-osgi/ ------------------------------------------------------------------------------ --- svn:ignore (added) +++ svn:ignore Fri Jul 23 06:00:11 2010 @@ -0,0 +1,10 @@ +.project +.checkstyle +.pmd +.classpath +target +.settings +eclipse-classes +*.i?? +classes +write Modified: camel/trunk/examples/camel-example-reportincident-ws-security-osgi/README.txt URL: http://svn.apache.org/viewvc/camel/trunk/examples/camel-example-reportincident-ws-security-osgi/README.txt?rev=966975&r1=966974&r2=966975&view=diff ============================================================================== --- camel/trunk/examples/camel-example-reportincident-ws-security-osgi/README.txt (original) +++ camel/trunk/examples/camel-example-reportincident-ws-security-osgi/README.txt Fri Jul 23 06:00:11 2010 @@ -11,14 +11,14 @@ the user using the WSS4J callback You will need to compile this example first: mvn install -Remarks : +Remarks: - During the compilation phase, a unit test will be performed, this unit test simulates the -communication between a client calling the web services exposed by our camel/cxf routes. During the call, -the user "charles" is used to authenticate the web service call and the SOAP message created can be -retrieved from log file target/camel-example-reportincident-wssecurity.log + communication between a client calling the web services exposed by our camel/cxf routes. During the call, + the user "charles" is used to authenticate the web service call and the SOAP message created can be + retrieved from log file target/camel-example-reportincident-wssecurity.log - A mock SMTP server is used during unit test - In Eclipse, I have used the following option when starting the junit test case. This option tells - CXF that it must use log4j : -Dorg.apache.cxf.Logger=org.apache.cxf.common.logging.Log4jLogger + CXF that it must use log4j : -Dorg.apache.cxf.Logger=org.apache.cxf.common.logging.Log4jLogger To run the example on Apache ServiceMix 4.x or Apache Karaf 1.x / 2.x @@ -32,8 +32,8 @@ To run the example on Apache ServiceMix features:install camel-mail features:install camel-velocity - remark : As the camel route sends email to a SMTP server, you must configure a user/password in your favorite - SMTP Server (James by example). User = someone and password = secret + remark: As the camel route sends email to a SMTP server, you must configure a user/password in your favorite + SMTP Server (James by example). User = someone and password = secret 3) Deploy our example osgi:install -s mvn:org.apache.example.reportincident/camel-example-reportincident-wssecurity @@ -93,11 +93,12 @@ To run the example on Apache ServiceMix </soap:Envelope> - You can use another user : james, claus and retry. + You can use another user: james, claus and retry. 6) Check email Check through a POP request that a message has been published in the mailbox of someone (email address : incid...@mycompany.com) - + + For the latest & greatest documentation on how to use this example please see http://camel.apache.org/tutorial-example-reportincident-wssecurity.html Modified: camel/trunk/examples/camel-example-reportincident-ws-security-osgi/pom.xml URL: http://svn.apache.org/viewvc/camel/trunk/examples/camel-example-reportincident-ws-security-osgi/pom.xml?rev=966975&r1=966974&r2=966975&view=diff ============================================================================== --- camel/trunk/examples/camel-example-reportincident-ws-security-osgi/pom.xml (original) +++ camel/trunk/examples/camel-example-reportincident-ws-security-osgi/pom.xml Fri Jul 23 06:00:11 2010 @@ -25,14 +25,6 @@ <version>2.5-SNAPSHOT</version> </parent> - <!-- USED TO TEST camel 2.4.0 on Karaf/SMX - <parent> - <groupId>org.apache.camel</groupId> - <artifactId>camel-parent</artifactId> - <version>2.4.0</version> - </parent> - --> - <artifactId>camel-example-reportincident-wssecurity</artifactId> <name>Camel :: Example :: Report Incident :: WS-Security</name> <description>An example based on real life use case for reporting incidents using webservice that are transformed @@ -72,11 +64,6 @@ <artifactId>camel-mail</artifactId> </dependency> - <dependency> - <groupId>org.fusesource.commonman</groupId> - <artifactId>commons-management</artifactId> - </dependency> - <!-- mock mail server so we do not send an email for real --> <dependency> <groupId>org.jvnet.mock-javamail</groupId> @@ -109,7 +96,6 @@ <version>${cxf-version}</version> </dependency> - <!-- regular http transport --> <dependency> <groupId>org.apache.cxf</groupId> @@ -129,7 +115,6 @@ <version>${cxf-version}</version> </dependency> - <!-- logging --> <dependency> <groupId>log4j</groupId> @@ -270,8 +255,8 @@ </instructions> </configuration> </plugin> - </plugins> </build> + </project> Modified: camel/trunk/examples/camel-example-reportincident-ws-security-osgi/src/main/java/org/apache/camel/example/reportincident/UTPasswordCallback.java URL: http://svn.apache.org/viewvc/camel/trunk/examples/camel-example-reportincident-ws-security-osgi/src/main/java/org/apache/camel/example/reportincident/UTPasswordCallback.java?rev=966975&r1=966974&r2=966975&view=diff ============================================================================== --- camel/trunk/examples/camel-example-reportincident-ws-security-osgi/src/main/java/org/apache/camel/example/reportincident/UTPasswordCallback.java (original) +++ camel/trunk/examples/camel-example-reportincident-ws-security-osgi/src/main/java/org/apache/camel/example/reportincident/UTPasswordCallback.java Fri Jul 23 06:00:11 2010 @@ -1,20 +1,18 @@ /** - * 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 + * 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 + * 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. + * 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.example.reportincident; @@ -29,32 +27,30 @@ import javax.security.auth.callback.Unsu import org.apache.ws.security.WSPasswordCallback; /** + * Callback handler to handle passwords */ - public class UTPasswordCallback implements CallbackHandler { - private Map<String, String> passwords = - new HashMap<String, String>(); + private Map<String, String> passwords = new HashMap<String, String>(); public UTPasswordCallback() { passwords.put("claus", "sualc"); passwords.put("charles", "selrahc"); passwords.put("james", "semaj"); - passwords.put("abcd", "dcba"); + passwords.put("abcd", "dcba"); } /** - * Here, we attempt to get the password from the private - * alias/passwords map. + * Here, we attempt to get the password from the private alias/passwords map. */ public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException { - - String user = ""; - + + String user = ""; + for (int i = 0; i < callbacks.length; i++) { - WSPasswordCallback pc = (WSPasswordCallback)callbacks[i]; - user = pc.getIdentifier(); - + WSPasswordCallback pc = (WSPasswordCallback) callbacks[i]; + user = pc.getIdentifier(); + String pass = passwords.get(user); if (pass != null) { pc.setPassword(pass); @@ -62,11 +58,8 @@ public class UTPasswordCallback implemen } } - // // Password not found - // throw new IOException("Password does not exist for the user : " + user); - } /** Modified: camel/trunk/examples/camel-example-reportincident-ws-security-osgi/src/main/resources/META-INF/spring/camel-context.xml URL: http://svn.apache.org/viewvc/camel/trunk/examples/camel-example-reportincident-ws-security-osgi/src/main/resources/META-INF/spring/camel-context.xml?rev=966975&r1=966974&r2=966975&view=diff ============================================================================== --- camel/trunk/examples/camel-example-reportincident-ws-security-osgi/src/main/resources/META-INF/spring/camel-context.xml (original) +++ camel/trunk/examples/camel-example-reportincident-ws-security-osgi/src/main/resources/META-INF/spring/camel-context.xml Fri Jul 23 06:00:11 2010 @@ -19,93 +19,90 @@ <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="http://camel.apache.org/schema/cxf" xsi:schemaLocation=" - http://www.springframework.org/schema/beans - http://www.springframework.org/schema/beans/spring-beans-2.5.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"> - - <import resource="classpath:META-INF/cxf/cxf.xml"/> - <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml"/> - <import resource="classpath:META-INF/cxf/cxf-extension-http-jetty.xml"/> - - <bean id="loggingOutInterceptor" class="org.apache.cxf.interceptor.LoggingOutInterceptor"> + 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"> + + <import resource="classpath:META-INF/cxf/cxf.xml"/> + <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml"/> + <import resource="classpath:META-INF/cxf/cxf-extension-http-jetty.xml"/> + + <bean id="loggingOutInterceptor" class="org.apache.cxf.interceptor.LoggingOutInterceptor"> <!-- it really should have been user-prestream but CXF does have such phase! --> - <constructor-arg value="write"/> + <constructor-arg value="write"/> + </bean> + + <bean id="loggingInInterceptor" class="org.apache.cxf.interceptor.LoggingInInterceptor"/> + + <bean id="wss4jInInterceptor" class="org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor"> + <constructor-arg> + <map> + <entry key="action" value="UsernameToken Timestamp"/> + <entry key="passwordType" value="PasswordDigest"/> + <entry key="passwordCallbackClass" value="org.apache.camel.example.reportincident.UTPasswordCallback"/> + </map> + </constructor-arg> + </bean> + + <!-- + <bean id="wss4jOutInterceptor" class="org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor"> + <constructor-arg> + <map> + <entry key="action" value="UsernameToken Timestamp"/> + <entry key="passwordType" value="PasswordText"/> + <entry key="user" value="Alice"/> + <entry key="passwordCallbackClass" value="org.apache.camel.example.reportincident.UTPasswordCallback"/> + </map> + </constructor-arg> </bean> - - <bean id="loggingInInterceptor" class="org.apache.cxf.interceptor.LoggingInInterceptor" /> - - <bean id="wss4jInInterceptor" class="org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor"> - <constructor-arg> - <map> - <entry key="action" value="UsernameToken Timestamp"/> - <entry key="passwordType" value="PasswordDigest"/> - <entry key="passwordCallbackClass" value="org.apache.camel.example.reportincident.UTPasswordCallback"/> - </map> - </constructor-arg> - </bean> - - <!-- - <bean id="wss4jOutInterceptor" class="org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor"> - <constructor-arg> - <map> - <entry key="action" value="UsernameToken Timestamp"/> - <entry key="passwordType" value="PasswordText"/> - <entry key="user" value="Alice"/> - <entry key="passwordCallbackClass" value="org.apache.camel.example.reportincident.UTPasswordCallback"/> - </map> - </constructor-arg> - </bean> - --> + --> - <cxf:cxfEndpoint id="reportIncident" + <cxf:cxfEndpoint id="reportIncident" address="http://localhost:9080/camel-example-reportincident/webservices/incident" wsdlURL="etc/report_incident.wsdl" serviceClass="org.apache.camel.example.reportincident.ReportIncidentEndpoint"> - + <cxf:inInterceptors> - <ref bean="loggingInInterceptor"/> - <ref bean="wss4jInInterceptor"/> + <ref bean="loggingInInterceptor"/> + <ref bean="wss4jInInterceptor"/> </cxf:inInterceptors> - + <cxf:outInterceptors> - <ref bean="loggingOutInterceptor"/> - <!-- <ref bean="wss4jOutInterceptor"/> --> + <ref bean="loggingOutInterceptor"/> + <!-- <ref bean="wss4jOutInterceptor"/> --> </cxf:outInterceptors> - - </cxf:cxfEndpoint> - - <bean id="myBean" class="org.apache.camel.example.reportincident.MyBean"/> - <bean id="filenameGenerator" class="org.apache.camel.example.reportincident.FilenameGenerator"/> - - <camel:camelContext id="camel"> - <camel:route> - <camel:from uri="cxf:bean:reportIncident" /> - <camel:convertBodyTo - type="org.apache.camel.example.reportincident.InputReportIncident" /> - <camel:setHeader headerName="CamelFileName"> - <camel:method bean="filenameGenerator" method="generateFilename" /> - </camel:setHeader> - <camel:to uri="velocity:etc/MailBody.vm"/> - <camel:to uri="file://target/subfolder"/> - <camel:transform> - <camel:method bean="myBean" method="getOK" /> - </camel:transform> - </camel:route> - - - <camel:route> - <camel:from uri="file://target/subfolder"/> - <camel:setHeader headerName="subject"> - <camel:constant>new incident reported</camel:constant> - </camel:setHeader> - <camel:to uri="log:com.mycompany.incident?level=INFO"/> - <camel:to uri="smtp://some...@localhost?password=secret&to=incid...@localhost"/> - </camel:route> -</camel:camelContext> + </cxf:cxfEndpoint> + + <bean id="myBean" class="org.apache.camel.example.reportincident.MyBean"/> + <bean id="filenameGenerator" class="org.apache.camel.example.reportincident.FilenameGenerator"/> + + <camel:camelContext id="camel"> + <camel:route> + <camel:from uri="cxf:bean:reportIncident"/> + <camel:convertBodyTo type="org.apache.camel.example.reportincident.InputReportIncident"/> + <camel:setHeader headerName="CamelFileName"> + <camel:method bean="filenameGenerator" method="generateFilename"/> + </camel:setHeader> + <camel:to uri="velocity:etc/MailBody.vm"/> + <camel:to uri="file://target/subfolder"/> + <camel:transform> + <camel:method bean="myBean" method="getOK"/> + </camel:transform> + </camel:route> + + + <camel:route> + <camel:from uri="file://target/subfolder"/> + <camel:setHeader headerName="subject"> + <camel:constant>new incident reported</camel:constant> + </camel:setHeader> + <camel:to uri="log:com.mycompany.incident?level=INFO"/> + <camel:to uri="smtp://some...@localhost?password=secret&to=incid...@localhost"/> + </camel:route> + + </camel:camelContext> + </beans> Modified: camel/trunk/examples/camel-example-reportincident-ws-security-osgi/src/main/resources/log4j.properties URL: http://svn.apache.org/viewvc/camel/trunk/examples/camel-example-reportincident-ws-security-osgi/src/main/resources/log4j.properties?rev=966975&r1=966974&r2=966975&view=diff ============================================================================== --- camel/trunk/examples/camel-example-reportincident-ws-security-osgi/src/main/resources/log4j.properties (original) +++ camel/trunk/examples/camel-example-reportincident-ws-security-osgi/src/main/resources/log4j.properties Fri Jul 23 06:00:11 2010 @@ -27,14 +27,16 @@ log4j.appender.console.layout.Conversion log4j.appender.file=org.apache.log4j.FileAppender log4j.appender.file.layout=org.apache.log4j.PatternLayout log4j.appender.file.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n -log4j.appender.file.file=target/camel-example-reportincident.log +log4j.appender.file.file=target/camel-example-reportincident-wssecurity.log log4j.appender.file.append=true # settings for specific packages -#log4j.logger.org.springframework=WARN -#log4j.logger.org.apache.cxf=WARN +log4j.logger.org.springframework=WARN # Camel logging #log4j.logger.org.apache.camel=DEBUG +# Cxf logging +#log4j.logger.org.apache.cxf=DEBUG + log4j.throwableRenderer=org.apache.log4j.EnhancedThrowableRenderer \ No newline at end of file Modified: camel/trunk/examples/camel-example-reportincident-ws-security-osgi/src/test/java/org/apache/camel/example/reportincident/ReportIncidentRoutesTest.java URL: http://svn.apache.org/viewvc/camel/trunk/examples/camel-example-reportincident-ws-security-osgi/src/test/java/org/apache/camel/example/reportincident/ReportIncidentRoutesTest.java?rev=966975&r1=966974&r2=966975&view=diff ============================================================================== --- camel/trunk/examples/camel-example-reportincident-ws-security-osgi/src/test/java/org/apache/camel/example/reportincident/ReportIncidentRoutesTest.java (original) +++ camel/trunk/examples/camel-example-reportincident-ws-security-osgi/src/test/java/org/apache/camel/example/reportincident/ReportIncidentRoutesTest.java Fri Jul 23 06:00:11 2010 @@ -21,7 +21,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import junit.framework.TestCase; import org.apache.camel.CamelContext; import org.apache.camel.test.junit4.CamelSpringTestSupport; import org.apache.cxf.interceptor.LoggingOutInterceptor; @@ -31,22 +30,25 @@ import org.junit.Test; import org.jvnet.mock_javamail.Mailbox; import org.springframework.context.support.AbstractXmlApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; -import static org.junit.Assert.assertEquals; /** * Unit test of our routes */ public class ReportIncidentRoutesTest extends CamelSpringTestSupport { - + // should be the same address as we have in our route private static final String URL = "http://localhost:9080/camel-example-reportincident/webservices/incident"; protected CamelContext camel; + @Override + protected AbstractXmlApplicationContext createApplicationContext() { + return new ClassPathXmlApplicationContext("/META-INF/spring/camel-context.xml"); + } + protected static ReportIncidentEndpoint createCXFClient() { - List outInterceptors = new ArrayList(); - + // Define WSS4j properties for flow outgoing Map<String, Object> outProps = new HashMap<String, Object>(); outProps.put("action", "UsernameToken Timestamp"); @@ -54,15 +56,15 @@ public class ReportIncidentRoutesTest ex outProps.put("passwordType", "PasswordDigest"); outProps.put("user", "charles"); outProps.put("passwordCallbackClass", "org.apache.camel.example.reportincident.UTPasswordCallback"); - + WSS4JOutInterceptor wss4j = new WSS4JOutInterceptor(outProps); // Add LoggingOutInterceptor - LoggingOutInterceptor loggingOutInterceptor = new LoggingOutInterceptor (); - + LoggingOutInterceptor loggingOutInterceptor = new LoggingOutInterceptor(); + outInterceptors.add(wss4j); outInterceptors.add(loggingOutInterceptor); - + // we use CXF to create a client for us as its easier than JAXWS and works JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean(); factory.setOutInterceptors(outInterceptors); @@ -73,11 +75,6 @@ public class ReportIncidentRoutesTest ex @Test public void testRendportIncident() throws Exception { - runTest(); - } - - protected void runTest() throws Exception { - // assert mailbox is empty before starting Mailbox inbox = Mailbox.get("incid...@localhost"); inbox.clear(); @@ -106,11 +103,6 @@ public class ReportIncidentRoutesTest ex // assert mail box assertEquals("Should have got 1 mail", 1, inbox.size()); - } - @Override - protected AbstractXmlApplicationContext createApplicationContext() { - return new ClassPathXmlApplicationContext("/META-INF/spring/camel-context.xml"); - } } Modified: camel/trunk/examples/camel-example-reportincident-ws-security-osgi/src/test/resources/log4j.properties URL: http://svn.apache.org/viewvc/camel/trunk/examples/camel-example-reportincident-ws-security-osgi/src/test/resources/log4j.properties?rev=966975&r1=966974&r2=966975&view=diff ============================================================================== --- camel/trunk/examples/camel-example-reportincident-ws-security-osgi/src/test/resources/log4j.properties (original) +++ camel/trunk/examples/camel-example-reportincident-ws-security-osgi/src/test/resources/log4j.properties Fri Jul 23 06:00:11 2010 @@ -32,10 +32,11 @@ log4j.appender.file.append=true # settings for specific packages log4j.logger.org.springframework=WARN -log4j.logger.org.apache.cxf=WARN # Camel logging -log4j.logger.org.apache.camel=DEBUG +#log4j.logger.org.apache.camel=DEBUG # Cxf logging -log4j.logger.org.apache.cxf=DEBUG \ No newline at end of file +#log4j.logger.org.apache.cxf=DEBUG + +log4j.throwableRenderer=org.apache.log4j.EnhancedThrowableRenderer \ No newline at end of file Modified: camel/trunk/examples/pom.xml URL: http://svn.apache.org/viewvc/camel/trunk/examples/pom.xml?rev=966975&r1=966974&r2=966975&view=diff ============================================================================== --- camel/trunk/examples/pom.xml (original) +++ camel/trunk/examples/pom.xml Fri Jul 23 06:00:11 2010 @@ -65,6 +65,7 @@ <module>camel-example-osgi</module> <module>camel-example-pojo-messaging</module> <module>camel-example-reportincident</module> + <module>camel-example-reportincident-ws-security-osgi</module> <module>camel-example-route-throttling</module> <module>camel-example-spring</module> <module>camel-example-spring-javaconfig</module>