cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cohei...@apache.org
Subject svn commit: r1558487 - in /cxf/trunk/distribution/src/main/release/samples/ws_security: sign_enc/src/main/java/demo/wssec/client/ sign_enc/src/main/java/demo/wssec/server/ ut/ ut/src/main/java/demo/wssec/client/ ut/src/main/java/demo/wssec/server/
Date Wed, 15 Jan 2014 18:00:54 GMT
Author: coheigea
Date: Wed Jan 15 18:00:54 2014
New Revision: 1558487

URL: http://svn.apache.org/r1558487
Log:
Adding streaming-based "ut" demo

Added:
    cxf/trunk/distribution/src/main/release/samples/ws_security/ut/src/main/java/demo/wssec/client/StaxClient.java
      - copied, changed from r1558445, cxf/trunk/distribution/src/main/release/samples/ws_security/ut/src/main/java/demo/wssec/client/Client.java
    cxf/trunk/distribution/src/main/release/samples/ws_security/ut/src/main/java/demo/wssec/server/StaxServer.java
Modified:
    cxf/trunk/distribution/src/main/release/samples/ws_security/sign_enc/src/main/java/demo/wssec/client/StaxClient.java
    cxf/trunk/distribution/src/main/release/samples/ws_security/sign_enc/src/main/java/demo/wssec/server/StaxServer.java
    cxf/trunk/distribution/src/main/release/samples/ws_security/ut/README.txt
    cxf/trunk/distribution/src/main/release/samples/ws_security/ut/pom.xml
    cxf/trunk/distribution/src/main/release/samples/ws_security/ut/src/main/java/demo/wssec/client/Client.java
    cxf/trunk/distribution/src/main/release/samples/ws_security/ut/src/main/java/demo/wssec/server/Server.java

Modified: cxf/trunk/distribution/src/main/release/samples/ws_security/sign_enc/src/main/java/demo/wssec/client/StaxClient.java
URL: http://svn.apache.org/viewvc/cxf/trunk/distribution/src/main/release/samples/ws_security/sign_enc/src/main/java/demo/wssec/client/StaxClient.java?rev=1558487&r1=1558486&r2=1558487&view=diff
==============================================================================
--- cxf/trunk/distribution/src/main/release/samples/ws_security/sign_enc/src/main/java/demo/wssec/client/StaxClient.java
(original)
+++ cxf/trunk/distribution/src/main/release/samples/ws_security/sign_enc/src/main/java/demo/wssec/client/StaxClient.java
Wed Jan 15 18:00:54 2014
@@ -110,6 +110,11 @@ public final class StaxClient {
             bus.getOutInterceptors().add(ohandler);
             
             WSSSecurityProperties inProperties = new WSSSecurityProperties();
+            inProperties.addAction(WSSConstants.USERNAMETOKEN);
+            inProperties.addAction(WSSConstants.TIMESTAMP);
+            inProperties.addAction(WSSConstants.SIGNATURE);
+            inProperties.addAction(WSSConstants.ENCRYPT);
+
             inProperties.setCallbackHandler(new UTPasswordCallback());
             inProperties.setDecryptionCryptoProperties(sigCryptoProperties);
             inProperties.setSignatureVerificationCryptoProperties(encCryptoProperties);

Modified: cxf/trunk/distribution/src/main/release/samples/ws_security/sign_enc/src/main/java/demo/wssec/server/StaxServer.java
URL: http://svn.apache.org/viewvc/cxf/trunk/distribution/src/main/release/samples/ws_security/sign_enc/src/main/java/demo/wssec/server/StaxServer.java?rev=1558487&r1=1558486&r2=1558487&view=diff
==============================================================================
--- cxf/trunk/distribution/src/main/release/samples/ws_security/sign_enc/src/main/java/demo/wssec/server/StaxServer.java
(original)
+++ cxf/trunk/distribution/src/main/release/samples/ws_security/sign_enc/src/main/java/demo/wssec/server/StaxServer.java
Wed Jan 15 18:00:54 2014
@@ -104,6 +104,11 @@ public class StaxServer {
         bus.getOutInterceptors().add(ohandler);
         
         WSSSecurityProperties inProperties = new WSSSecurityProperties();
+        inProperties.addAction(WSSConstants.USERNAMETOKEN);
+        inProperties.addAction(WSSConstants.TIMESTAMP);
+        inProperties.addAction(WSSConstants.SIGNATURE);
+        inProperties.addAction(WSSConstants.ENCRYPT);
+
         inProperties.setCallbackHandler(new UTPasswordCallback());
         inProperties.setDecryptionCryptoProperties(decCryptoProperties);
         inProperties.setSignatureVerificationCryptoProperties(sigVerCryptoProperties);

Modified: cxf/trunk/distribution/src/main/release/samples/ws_security/ut/README.txt
URL: http://svn.apache.org/viewvc/cxf/trunk/distribution/src/main/release/samples/ws_security/ut/README.txt?rev=1558487&r1=1558486&r2=1558487&view=diff
==============================================================================
--- cxf/trunk/distribution/src/main/release/samples/ws_security/ut/README.txt (original)
+++ cxf/trunk/distribution/src/main/release/samples/ws_security/ut/README.txt Wed Jan 15 18:00:54
2014
@@ -9,6 +9,9 @@ incoming interceptors. Various Actions l
 Signature, Encryption, etc., can be applied to the interceptors by passing
 appropriate configuration properties.
 
+CXF 3.0.0 supports both a DOM-based (in-memory) and StAX-based (streaming)
+approach to WS-Security. This demo shows how to use both approaches.
+
 The logging feature is used to log the inbound and outbound
 SOAP messages and display these to the console.
 
@@ -35,13 +38,20 @@ Building and running the demo using Mave
 From the base directory of this sample (i.e., where this README file is
 located), the maven pom.xml file can be used to build and run the demo.
 
-
 Using either UNIX or Windows:
 
   mvn install (builds the demo)
+
+To use the DOM-based WS-Security functionality:
+
   mvn -Pserver  (from one command line window)
   mvn -Pclient  (from a second command line window)
 
+To use the StAX-based WS-Security functionality:
+
+  mvn -Pstax-server  (from one command line window)
+  mvn -Pstax-client  (from a second command line window)
+
 On startup, the client makes a sequence of 4 two-way invocations.
 
 To remove the code generated from the WSDL file and the .class

Modified: cxf/trunk/distribution/src/main/release/samples/ws_security/ut/pom.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/distribution/src/main/release/samples/ws_security/ut/pom.xml?rev=1558487&r1=1558486&r2=1558487&view=diff
==============================================================================
--- cxf/trunk/distribution/src/main/release/samples/ws_security/ut/pom.xml (original)
+++ cxf/trunk/distribution/src/main/release/samples/ws_security/ut/pom.xml Wed Jan 15 18:00:54
2014
@@ -89,6 +89,29 @@
             </build>
         </profile>
         <profile>
+            <id>stax-server</id>
+            <build>
+                <defaultGoal>test</defaultGoal>
+                <plugins>
+                    <plugin>
+                        <groupId>org.codehaus.mojo</groupId>
+                        <artifactId>exec-maven-plugin</artifactId>
+                        <executions>
+                            <execution>
+                                <phase>test</phase>
+                                <goals>
+                                    <goal>java</goal>
+                                </goals>
+                                <configuration>
+                                    <mainClass>demo.wssec.server.StaxServer</mainClass>
+                                </configuration>
+                            </execution>
+                        </executions>
+                    </plugin>
+                </plugins>
+            </build>
+        </profile>
+        <profile>
             <id>client</id>
             <build>
                 <defaultGoal>test</defaultGoal>
@@ -111,6 +134,29 @@
                 </plugins>
             </build>
         </profile>
+        <profile>
+            <id>stax-client</id>
+            <build>
+                <defaultGoal>test</defaultGoal>
+                <plugins>
+                    <plugin>
+                        <groupId>org.codehaus.mojo</groupId>
+                        <artifactId>exec-maven-plugin</artifactId>
+                        <executions>
+                            <execution>
+                                <phase>test</phase>
+                                <goals>
+                                    <goal>java</goal>
+                                </goals>
+                                <configuration>
+                                    <mainClass>demo.wssec.client.StaxClient</mainClass>
+                                </configuration>
+                            </execution>
+                        </executions>
+                    </plugin>
+                </plugins>
+            </build>
+        </profile>
     </profiles>
     <dependencies>
         <dependency>

Modified: cxf/trunk/distribution/src/main/release/samples/ws_security/ut/src/main/java/demo/wssec/client/Client.java
URL: http://svn.apache.org/viewvc/cxf/trunk/distribution/src/main/release/samples/ws_security/ut/src/main/java/demo/wssec/client/Client.java?rev=1558487&r1=1558486&r2=1558487&view=diff
==============================================================================
--- cxf/trunk/distribution/src/main/release/samples/ws_security/ut/src/main/java/demo/wssec/client/Client.java
(original)
+++ cxf/trunk/distribution/src/main/release/samples/ws_security/ut/src/main/java/demo/wssec/client/Client.java
Wed Jan 15 18:00:54 2014
@@ -34,9 +34,9 @@ import org.apache.cxf.hello_world_soap_h
 import org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor;
 import org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor;
 
-
-
-
+/**
+ * A DOM-based client
+ */
 public final class Client {
 
     private Client() {
@@ -57,20 +57,16 @@ public final class Client {
             outProps.put("user", "abcd");
             outProps.put("passwordCallbackClass", "demo.wssec.client.UTPasswordCallback");
 
-
             Map<String, Object> inProps = new HashMap<String, Object>();
             inProps.put("action", "UsernameToken Timestamp");
             inProps.put("passwordType", "PasswordText");
             inProps.put("passwordCallbackClass", "demo.wssec.client.UTPasswordCallback");
 
-
             GreeterService service = new GreeterService();
             Greeter port = service.getGreeterPort();
             org.apache.cxf.endpoint.Client client = ClientProxy.getClient(port);
             client.getInInterceptors().add(new WSS4JInInterceptor(inProps));
             client.getOutInterceptors().add(new WSS4JOutInterceptor(outProps));
-            
-            
 
             String[] names = new String[] {"Anne", "Bill", "Chris", "Scott"};
             // make a sequence of 4 invocations

Copied: cxf/trunk/distribution/src/main/release/samples/ws_security/ut/src/main/java/demo/wssec/client/StaxClient.java
(from r1558445, cxf/trunk/distribution/src/main/release/samples/ws_security/ut/src/main/java/demo/wssec/client/Client.java)
URL: http://svn.apache.org/viewvc/cxf/trunk/distribution/src/main/release/samples/ws_security/ut/src/main/java/demo/wssec/client/StaxClient.java?p2=cxf/trunk/distribution/src/main/release/samples/ws_security/ut/src/main/java/demo/wssec/client/StaxClient.java&p1=cxf/trunk/distribution/src/main/release/samples/ws_security/ut/src/main/java/demo/wssec/client/Client.java&r1=1558445&r2=1558487&rev=1558487&view=diff
==============================================================================
--- cxf/trunk/distribution/src/main/release/samples/ws_security/ut/src/main/java/demo/wssec/client/Client.java
(original)
+++ cxf/trunk/distribution/src/main/release/samples/ws_security/ut/src/main/java/demo/wssec/client/StaxClient.java
Wed Jan 15 18:00:54 2014
@@ -22,8 +22,9 @@ package demo.wssec.client;
 import java.io.Closeable;
 import java.lang.reflect.UndeclaredThrowableException;
 import java.net.URL;
-import java.util.HashMap;
-import java.util.Map;
+import java.util.Properties;
+
+import javax.xml.namespace.QName;
 
 import org.apache.cxf.Bus;
 import org.apache.cxf.BusFactory;
@@ -31,46 +32,54 @@ import org.apache.cxf.bus.spring.SpringB
 import org.apache.cxf.frontend.ClientProxy;
 import org.apache.cxf.hello_world_soap_http.Greeter;
 import org.apache.cxf.hello_world_soap_http.GreeterService;
-import org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor;
-import org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor;
-
-
-
+import org.apache.cxf.ws.security.wss4j.StaxCryptoCoverageChecker;
+import org.apache.cxf.ws.security.wss4j.WSS4JStaxInInterceptor;
+import org.apache.cxf.ws.security.wss4j.WSS4JStaxOutInterceptor;
+import org.apache.wss4j.common.crypto.CryptoFactory;
+import org.apache.wss4j.stax.ext.WSSConstants;
+import org.apache.wss4j.stax.ext.WSSSecurityProperties;
+import org.apache.wss4j.stax.securityToken.WSSecurityTokenConstants;
+import org.apache.xml.security.stax.ext.SecurePart;
+import org.apache.xml.security.stax.ext.XMLSecurityConstants;
+
+import demo.wssec.server.UTPasswordCallback;
+
+/**
+ * A StAX-based client
+ */
+public final class StaxClient {
 
-public final class Client {
-
-    private Client() {
+    private StaxClient() {
     }
 
     public static void main(String args[]) throws Exception {
         try {
 
             SpringBusFactory bf = new SpringBusFactory();
-            URL busFile = Client.class.getResource("/wssec.xml");
+            URL busFile = StaxClient.class.getResource("/wssec.xml");
             Bus bus = bf.createBus(busFile.toString());
             BusFactory.setDefaultBus(bus);
 
-            Map<String, Object> outProps = new HashMap<String, Object>();
-            outProps.put("action", "UsernameToken Timestamp");
-
-            outProps.put("passwordType", "PasswordDigest");
-            outProps.put("user", "abcd");
-            outProps.put("passwordCallbackClass", "demo.wssec.client.UTPasswordCallback");
-
-
-            Map<String, Object> inProps = new HashMap<String, Object>();
-            inProps.put("action", "UsernameToken Timestamp");
-            inProps.put("passwordType", "PasswordText");
-            inProps.put("passwordCallbackClass", "demo.wssec.client.UTPasswordCallback");
-
+            WSSSecurityProperties properties = new WSSSecurityProperties();
+            properties.addAction(WSSConstants.USERNAMETOKEN);
+            properties.addAction(WSSConstants.TIMESTAMP);
+
+            properties.setUsernameTokenPasswordType(WSSConstants.UsernameTokenPasswordType.PASSWORD_DIGEST);
+            properties.setTokenUser("abcd");
+            properties.setCallbackHandler(new UTPasswordCallback());
+            
+            WSSSecurityProperties inProperties = new WSSSecurityProperties();
+            inProperties.addAction(WSSConstants.USERNAMETOKEN);
+            inProperties.addAction(WSSConstants.TIMESTAMP);
 
+            inProperties.setUsernameTokenPasswordType(WSSConstants.UsernameTokenPasswordType.PASSWORD_TEXT);
+            inProperties.setCallbackHandler(new UTPasswordCallback());
+            
             GreeterService service = new GreeterService();
             Greeter port = service.getGreeterPort();
             org.apache.cxf.endpoint.Client client = ClientProxy.getClient(port);
-            client.getInInterceptors().add(new WSS4JInInterceptor(inProps));
-            client.getOutInterceptors().add(new WSS4JOutInterceptor(outProps));
-            
-            
+            client.getInInterceptors().add(new WSS4JStaxInInterceptor(inProperties));
+            client.getOutInterceptors().add(new WSS4JStaxOutInterceptor(properties));
 
             String[] names = new String[] {"Anne", "Bill", "Chris", "Scott"};
             // make a sequence of 4 invocations
@@ -83,7 +92,6 @@ public final class Client {
             if (port instanceof Closeable) {
                 ((Closeable)port).close();
             }
-
             bus.shutdown(true);
 
         } catch (UndeclaredThrowableException ex) {

Modified: cxf/trunk/distribution/src/main/release/samples/ws_security/ut/src/main/java/demo/wssec/server/Server.java
URL: http://svn.apache.org/viewvc/cxf/trunk/distribution/src/main/release/samples/ws_security/ut/src/main/java/demo/wssec/server/Server.java?rev=1558487&r1=1558486&r2=1558487&view=diff
==============================================================================
--- cxf/trunk/distribution/src/main/release/samples/ws_security/ut/src/main/java/demo/wssec/server/Server.java
(original)
+++ cxf/trunk/distribution/src/main/release/samples/ws_security/ut/src/main/java/demo/wssec/server/Server.java
Wed Jan 15 18:00:54 2014
@@ -32,13 +32,14 @@ import org.apache.cxf.jaxws.EndpointImpl
 import org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor;
 import org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor;
 
-
+/**
+ * A DOM-based server
+ */
 public class Server {
 
     protected Server() throws Exception {
         System.out.println("Starting Server");
 
-
         Object implementor = new GreeterImpl();
         String address = "http://localhost:9000/SoapContext/GreeterPort";
         EndpointImpl impl = (EndpointImpl)Endpoint.publish(address, implementor);

Added: cxf/trunk/distribution/src/main/release/samples/ws_security/ut/src/main/java/demo/wssec/server/StaxServer.java
URL: http://svn.apache.org/viewvc/cxf/trunk/distribution/src/main/release/samples/ws_security/ut/src/main/java/demo/wssec/server/StaxServer.java?rev=1558487&view=auto
==============================================================================
--- cxf/trunk/distribution/src/main/release/samples/ws_security/ut/src/main/java/demo/wssec/server/StaxServer.java
(added)
+++ cxf/trunk/distribution/src/main/release/samples/ws_security/ut/src/main/java/demo/wssec/server/StaxServer.java
Wed Jan 15 18:00:54 2014
@@ -0,0 +1,89 @@
+/**
+ * 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 demo.wssec.server;
+
+import java.net.URL;
+import java.util.Properties;
+
+import javax.xml.namespace.QName;
+import javax.xml.ws.Endpoint;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.BusFactory;
+import org.apache.cxf.bus.spring.SpringBusFactory;
+import org.apache.cxf.jaxws.EndpointImpl;
+import org.apache.cxf.ws.security.wss4j.WSS4JStaxInInterceptor;
+import org.apache.cxf.ws.security.wss4j.WSS4JStaxOutInterceptor;
+import org.apache.wss4j.common.crypto.CryptoFactory;
+import org.apache.wss4j.stax.ext.WSSConstants;
+import org.apache.wss4j.stax.ext.WSSSecurityProperties;
+import org.apache.wss4j.stax.securityToken.WSSecurityTokenConstants;
+import org.apache.xml.security.stax.ext.XMLSecurityConstants;
+
+/**
+ * A StAX-based server
+ */
+public class StaxServer {
+
+     protected StaxServer() throws Exception {
+        System.out.println("Starting StaxServer");
+
+        Object implementor = new GreeterImpl();
+        String address = "http://localhost:9000/SoapContext/GreeterPort";
+        EndpointImpl impl = (EndpointImpl)Endpoint.publish(address, implementor);
+        
+        WSSSecurityProperties properties = new WSSSecurityProperties();
+        properties.addAction(WSSConstants.USERNAMETOKEN);
+        properties.addAction(WSSConstants.TIMESTAMP);
+
+        properties.setUsernameTokenPasswordType(WSSConstants.UsernameTokenPasswordType.PASSWORD_TEXT);
+        properties.setTokenUser("Alice");
+        
+        properties.setCallbackHandler(new UTPasswordCallback());
+        
+        impl.getOutInterceptors().add(new WSS4JStaxOutInterceptor(properties));
+
+        WSSSecurityProperties inProperties = new WSSSecurityProperties();
+        inProperties.addAction(WSSConstants.USERNAMETOKEN);
+        inProperties.addAction(WSSConstants.TIMESTAMP);
+        inProperties.setUsernameTokenPasswordType(WSSConstants.UsernameTokenPasswordType.PASSWORD_DIGEST);
+        inProperties.setCallbackHandler(new UTPasswordCallback());
+        
+        impl.getInInterceptors().add(new WSS4JStaxInInterceptor(inProperties));
+    }
+
+    public static void main(String args[]) throws Exception {
+
+        SpringBusFactory bf = new SpringBusFactory();
+        URL busFile = StaxServer.class.getResource("/wssec.xml");
+        Bus bus = bf.createBus(busFile.toString());
+
+        BusFactory.setDefaultBus(bus);
+
+        new StaxServer();
+        System.out.println("StaxServer ready...");
+
+        Thread.sleep(5 * 60 * 1000);
+
+        bus.shutdown(true);
+        System.out.println("StaxServer exiting");
+        System.exit(0);
+    }
+}



Mime
View raw message