servicemix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r412730 - in /incubator/servicemix/trunk: ./ servicemix-http/src/main/java/org/apache/servicemix/http/ servicemix-http/src/main/java/org/apache/servicemix/http/processors/ servicemix-http/src/test/java/org/apache/servicemix/http/ servicemix...
Date Thu, 08 Jun 2006 12:10:24 GMT
Author: gnodet
Date: Thu Jun  8 05:10:23 2006
New Revision: 412730

URL: http://svn.apache.org/viewvc?rev=412730&view=rev
Log:
SM-447, SM-279: support for ws-sec inbound authentication using UsernamePassword token

Added:
    incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/handlers/addressing/
    incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/handlers/addressing/AddressingHandler.java
    incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/handlers/security/
    incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/handlers/security/BaseSecurityCallbackHandler.java
    incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/handlers/security/WSSecurityHandler.java
    incubator/servicemix/trunk/servicemix-soap/src/test/java/org/apache/servicemix/soap/handlers/
    incubator/servicemix/trunk/servicemix-soap/src/test/java/org/apache/servicemix/soap/handlers/WSSecurityHandlerTest.java
    incubator/servicemix/trunk/servicemix-soap/src/test/resources/org/apache/servicemix/soap/handlers/
    incubator/servicemix/trunk/servicemix-soap/src/test/resources/org/apache/servicemix/soap/handlers/sample-wsse-request.xml
Removed:
    incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/handlers/AddressingHandler.java
Modified:
    incubator/servicemix/trunk/pom.xml
    incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/HttpEndpoint.java
    incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/processors/ConsumerProcessor.java
    incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/processors/ProviderProcessor.java
    incubator/servicemix/trunk/servicemix-http/src/test/java/org/apache/servicemix/http/HttpWsdlTest.java
    incubator/servicemix/trunk/servicemix-http/src/test/java/org/apache/servicemix/http/security/HttpSecurityTest.java
    incubator/servicemix/trunk/servicemix-http/src/test/resources/org/apache/servicemix/http/security/secure.xml
    incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/JmsComponent.java
    incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/multiplexing/MultiplexingConsumerProcessor.java
    incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/multiplexing/MultiplexingProviderProcessor.java
    incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/standard/StandardConsumerProcessor.java
    incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/standard/StandardProviderProcessor.java
    incubator/servicemix/trunk/servicemix-soap/pom.xml
    incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/Handler.java
    incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/SoapEndpoint.java
    incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/SoapHelper.java
    incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/handlers/AbstractHandler.java
    incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/marshalers/SoapWriter.java

Modified: incubator/servicemix/trunk/pom.xml
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/pom.xml?rev=412730&r1=412729&r2=412730&view=diff
==============================================================================
--- incubator/servicemix/trunk/pom.xml (original)
+++ incubator/servicemix/trunk/pom.xml Thu Jun  8 05:10:23 2006
@@ -1571,6 +1571,26 @@
       <artifactId>tranql-connector</artifactId>
       <version>1.1</version>
     </dependency>
+    <dependency>
+      <groupId>wss4j</groupId>
+      <artifactId>wss4j</artifactId>
+      <version>1.5.0</version>
+    </dependency>
+    <dependency>
+      <groupId>bouncycastle</groupId>
+      <artifactId>bcprov-jdk14</artifactId>
+      <version>124</version>
+    </dependency>
+    <dependency>
+      <groupId>org.opensaml</groupId>
+      <artifactId>opensaml</artifactId>
+      <version>1.0.1</version>
+    </dependency>
+    <dependency>
+      <groupId>xml-security</groupId>
+      <artifactId>xmlsec</artifactId>
+      <version>1.3.0</version>
+    </dependency>
     </dependencies>
   </dependencyManagement>
   

Modified: incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/HttpEndpoint.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/HttpEndpoint.java?rev=412730&r1=412729&r2=412730&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/HttpEndpoint.java (original)
+++ incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/HttpEndpoint.java Thu Jun  8 05:10:23 2006
@@ -15,17 +15,25 @@
  */
 package org.apache.servicemix.http;
 
+import java.net.URI;
 import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
 
 import javax.jbi.servicedesc.ServiceEndpoint;
 import javax.wsdl.Binding;
 import javax.wsdl.Definition;
+import javax.wsdl.Import;
 import javax.wsdl.Port;
 import javax.wsdl.PortType;
 import javax.wsdl.Service;
+import javax.wsdl.Types;
 import javax.wsdl.extensions.ExtensibilityElement;
 import javax.wsdl.extensions.http.HTTPAddress;
+import javax.wsdl.extensions.schema.Schema;
+import javax.wsdl.extensions.schema.SchemaImport;
+import javax.wsdl.extensions.schema.SchemaReference;
 import javax.xml.namespace.QName;
 
 import org.apache.servicemix.common.ExchangeProcessor;
@@ -208,6 +216,44 @@
                         endpoint);       
                 wsdls.put("main.wsdl", definition);
                 wsdls.put("porttypedef.wsdl", def);
+            }
+            mapImports(def);
+        }
+    }
+    
+    protected void mapImports(Definition def) {
+        // Add other imports to mapping
+        Map imports = def.getImports();
+        for (Iterator iter = imports.values().iterator(); iter.hasNext();) {
+            List imps = (List) iter.next();
+            for (Iterator iterator = imps.iterator(); iterator.hasNext();) {
+                Import imp = (Import) iterator.next();
+                Definition impDef = imp.getDefinition();
+                String impLoc = imp.getLocationURI();
+                if (impDef != null && impLoc != null && !URI.create(impLoc).isAbsolute()) {
+                    wsdls.put(impLoc, impDef);
+                    mapImports(impDef);
+                }
+            }
+        }
+        // Add schemas to mapping
+        Types types = def.getTypes();
+        for (Iterator it = types.getExtensibilityElements().iterator(); it.hasNext();) {
+            ExtensibilityElement ee = (ExtensibilityElement) it.next();
+            if (ee instanceof Schema) {
+                Schema schema = (Schema) ee;
+                Map schemaImports = schema.getImports();
+                for (Iterator iter = schemaImports.values().iterator(); iter.hasNext();) {
+                    List imps = (List) iter.next();
+                    for (Iterator iterator = imps.iterator(); iterator.hasNext();) {
+                        SchemaImport schemaImport = (SchemaImport) iterator.next();
+                        Schema schemaImp = schemaImport.getReferencedSchema();
+                        String schemaLoc = schemaImport.getSchemaLocationURI();
+                        if (schemaLoc != null && schemaImp != null && schemaImp.getElement() != null && !URI.create(schemaLoc).isAbsolute()) {
+                            wsdls.put(schemaLoc, schemaImp.getElement());
+                        }
+                    }
+                }
             }
         }
     }

Modified: incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/processors/ConsumerProcessor.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/processors/ConsumerProcessor.java?rev=412730&r1=412729&r2=412730&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/processors/ConsumerProcessor.java (original)
+++ incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/processors/ConsumerProcessor.java Thu Jun  8 05:10:23 2006
@@ -31,6 +31,8 @@
 import javax.wsdl.Definition;
 import javax.wsdl.factory.WSDLFactory;
 import javax.xml.namespace.QName;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
 
 import org.apache.servicemix.JbiConstants;
 import org.apache.servicemix.common.BaseLifeCycle;
@@ -41,17 +43,17 @@
 import org.apache.servicemix.http.ServerManager;
 import org.apache.servicemix.http.SslParameters;
 import org.apache.servicemix.http.jetty.JaasJettyPrincipal;
+import org.apache.servicemix.jbi.jaxp.SourceTransformer;
 import org.apache.servicemix.soap.Context;
 import org.apache.servicemix.soap.SoapFault;
 import org.apache.servicemix.soap.SoapHelper;
-import org.apache.servicemix.soap.handlers.AddressingHandler;
 import org.apache.servicemix.soap.marshalers.JBIMarshaler;
-import org.apache.servicemix.soap.marshalers.SoapMarshaler;
 import org.apache.servicemix.soap.marshalers.SoapMessage;
 import org.apache.servicemix.soap.marshalers.SoapWriter;
 import org.mortbay.jetty.handler.ContextHandler;
 import org.mortbay.util.ajax.Continuation;
 import org.mortbay.util.ajax.ContinuationSupport;
+import org.w3c.dom.Element;
 
 import edu.emory.mathcs.backport.java.util.concurrent.ConcurrentHashMap;
 
@@ -65,19 +67,13 @@
     protected ContextHandler httpContext;
     protected ComponentContext context;
     protected DeliveryChannel channel;
-    protected SoapMarshaler soapMarshaler;
     protected SoapHelper soapHelper;
     protected Map locks;
     protected Map exchanges;
         
     public ConsumerProcessor(HttpEndpoint endpoint) {
         this.endpoint = endpoint;
-        this.soapMarshaler = new SoapMarshaler(endpoint.isSoap());
-        if (endpoint.isSoap() && "1.1".equals(endpoint.getSoapVersion())) {
-            this.soapMarshaler.setSoapUri(SoapMarshaler.SOAP_11_URI);
-        }
         this.soapHelper = new SoapHelper(endpoint);
-        this.soapHelper.addPolicy(new AddressingHandler());
         this.locks = new ConcurrentHashMap();
         this.exchanges = new ConcurrentHashMap();
     }
@@ -134,6 +130,10 @@
                 Definition def = (Definition) endpoint.getWsdls().get(path);
                 generateWSDL(response, def);
                 return;
+            } else if (path.endsWith(".xsd")) {
+                Element el = (Element) endpoint.getWsdls().get(path);
+                generateXSD(response, el);
+                return;
             }
         }
         if (!"POST".equals(request.getMethod())) {
@@ -146,8 +146,9 @@
         // If the continuation is not a retry
         if (!cont.isPending()) {
             try {
-                SoapMessage message = soapMarshaler.createReader().read(request.getInputStream(), 
-                                                                        request.getHeader("Content-Type"));
+                SoapMessage message = soapHelper.getSoapMarshaler().createReader().read(
+                                            request.getInputStream(), 
+                                            request.getHeader("Content-Type"));
                 Context context = soapHelper.createContext(message);
                 if (request.getUserPrincipal() != null) {
                     if (request.getUserPrincipal() instanceof JaasJettyPrincipal) {
@@ -208,7 +209,7 @@
                     if (outMsg != null) {
                         Context context = (Context) request.getAttribute(Context.class.getName());
                         SoapMessage out = soapHelper.onReply(context, outMsg);
-                        SoapWriter writer = soapMarshaler.createWriter(out);
+                        SoapWriter writer = soapHelper.getSoapMarshaler().createWriter(out);
                         response.setContentType(writer.getContentType());
                         writer.write(response.getOutputStream());
                     }
@@ -228,7 +229,7 @@
         }
         Context context = (Context) request.getAttribute(Context.class.getName());
         SoapMessage soapFault = soapHelper.onFault(context, fault);
-        SoapWriter writer = soapMarshaler.createWriter(soapFault);
+        SoapWriter writer = soapHelper.getSoapMarshaler().createWriter(soapFault);
         response.setContentType(writer.getContentType());
         writer.write(response.getOutputStream());
     }
@@ -257,6 +258,16 @@
         response.setStatus(200);
         response.setContentType("text/xml");
         WSDLFactory.newInstance().newWSDLWriter().writeWSDL(def, response.getOutputStream());
+    }
+    
+    protected void generateXSD(HttpServletResponse response, Element element) throws Exception {
+        if (element == null) {
+            response.sendError(HttpServletResponse.SC_NOT_FOUND, "Unable to find requested resource");
+            return;
+        }
+        response.setStatus(200);
+        response.setContentType("text/xml");
+        new SourceTransformer().toResult(new DOMSource(element), new StreamResult(response.getOutputStream()));
     }
 
 }

Modified: incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/processors/ProviderProcessor.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/processors/ProviderProcessor.java?rev=412730&r1=412729&r2=412730&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/processors/ProviderProcessor.java (original)
+++ incubator/servicemix/trunk/servicemix-http/src/main/java/org/apache/servicemix/http/processors/ProviderProcessor.java Thu Jun  8 05:10:23 2006
@@ -49,8 +49,7 @@
 import org.apache.servicemix.common.ExchangeProcessor;
 import org.apache.servicemix.http.HttpEndpoint;
 import org.apache.servicemix.http.HttpLifeCycle;
-import org.apache.servicemix.soap.marshalers.JBIMarshaler;
-import org.apache.servicemix.soap.marshalers.SoapMarshaler;
+import org.apache.servicemix.soap.SoapHelper;
 import org.apache.servicemix.soap.marshalers.SoapMessage;
 import org.apache.servicemix.soap.marshalers.SoapReader;
 import org.apache.servicemix.soap.marshalers.SoapWriter;
@@ -65,18 +64,13 @@
 
     protected HttpEndpoint endpoint;
     protected HostConfiguration host;
-    protected SoapMarshaler soapMarshaler;
-    protected JBIMarshaler jbiMarshaler;
+    protected SoapHelper soapHelper;
     protected DeliveryChannel channel;
     private String relUri;
     
     public ProviderProcessor(HttpEndpoint endpoint) {
         this.endpoint = endpoint;
-        this.soapMarshaler = new SoapMarshaler(endpoint.isSoap());
-        if (endpoint.isSoap() && "1.1".equals(endpoint.getSoapVersion())) {
-            this.soapMarshaler.setSoapUri(SoapMarshaler.SOAP_11_URI);
-        }
-        this.jbiMarshaler = new JBIMarshaler();
+        this.soapHelper = new SoapHelper(endpoint);
         java.net.URI uri = java.net.URI.create(endpoint.getLocationURI());
         relUri = uri.getPath();
         if (!relUri.startsWith("/")) {
@@ -99,8 +93,8 @@
         PostMethod method = new PostMethod(relUri);
         SoapMessage soapMessage = new SoapMessage();
         NormalizedMessage nm = exchange.getMessage("in");
-        jbiMarshaler.fromNMS(soapMessage, nm);
-        SoapWriter writer = soapMarshaler.createWriter(soapMessage);
+        soapHelper.getJBIMarshaler().fromNMS(soapMessage, nm);
+        SoapWriter writer = soapHelper.getSoapMarshaler().createWriter(soapMessage);
         Map headers = (Map) nm.getProperty(JbiConstants.PROTOCOL_HEADERS);
         if (headers != null) {
             for (Iterator it = headers.keySet().iterator(); it.hasNext();) {
@@ -124,13 +118,13 @@
             int response = getClient().executeMethod(host, method);
             if (response != HttpStatus.SC_OK) {
                 if (exchange instanceof InOnly == false) {
-                    SoapReader reader = soapMarshaler.createReader();
+                    SoapReader reader = soapHelper.getSoapMarshaler().createReader();
                     Header contentType = method.getResponseHeader("Content-Type");
                     soapMessage = reader.read(method.getResponseBodyAsStream(), 
                                               contentType != null ? contentType.getValue() : null);
                     Fault fault = exchange.createFault();
                     fault.setProperty(JbiConstants.PROTOCOL_HEADERS, getHeaders(method));
-                    jbiMarshaler.toNMS(fault, soapMessage);
+                    soapHelper.getJBIMarshaler().toNMS(fault, soapMessage);
                     exchange.setFault(fault);
                     channel.send(exchange);
                     return;
@@ -140,12 +134,12 @@
             }
             if (exchange instanceof InOut) {
                 NormalizedMessage msg = exchange.createMessage();
-                SoapReader reader = soapMarshaler.createReader();
+                SoapReader reader = soapHelper.getSoapMarshaler().createReader();
                 Header contentType = method.getResponseHeader("Content-Type");
                 soapMessage = reader.read(method.getResponseBodyAsStream(), 
                                           contentType != null ? contentType.getValue() : null);
                 msg.setProperty(JbiConstants.PROTOCOL_HEADERS, getHeaders(method));
-                jbiMarshaler.toNMS(msg, soapMessage);
+                soapHelper.getJBIMarshaler().toNMS(msg, soapMessage);
                 ((InOut) exchange).setOutMessage(msg);
                 channel.sendSync(exchange);
             } else if (exchange instanceof InOptionalOut) {
@@ -154,11 +148,11 @@
                     channel.send(exchange);
                 } else {
                     NormalizedMessage msg = exchange.createMessage();
-                    SoapReader reader = soapMarshaler.createReader();
+                    SoapReader reader = soapHelper.getSoapMarshaler().createReader();
                     soapMessage = reader.read(method.getResponseBodyAsStream(), 
                                               method.getResponseHeader("Content-Type").getValue());
                     msg.setProperty(JbiConstants.PROTOCOL_HEADERS, getHeaders(method));
-                    jbiMarshaler.toNMS(msg, soapMessage);
+                    soapHelper.getJBIMarshaler().toNMS(msg, soapMessage);
                     ((InOptionalOut) exchange).setOutMessage(msg);
                     channel.sendSync(exchange);
                 }

Modified: incubator/servicemix/trunk/servicemix-http/src/test/java/org/apache/servicemix/http/HttpWsdlTest.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-http/src/test/java/org/apache/servicemix/http/HttpWsdlTest.java?rev=412730&r1=412729&r2=412730&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-http/src/test/java/org/apache/servicemix/http/HttpWsdlTest.java (original)
+++ incubator/servicemix/trunk/servicemix-http/src/test/java/org/apache/servicemix/http/HttpWsdlTest.java Thu Jun  8 05:10:23 2006
@@ -32,6 +32,7 @@
 import org.apache.servicemix.jbi.container.JBIContainer;
 import org.apache.servicemix.jbi.jaxp.SourceTransformer;
 import org.apache.servicemix.jbi.jaxp.StringSource;
+import org.springframework.core.io.UrlResource;
 import org.w3c.dom.Document;
 
 public class HttpWsdlTest extends TestCase {
@@ -98,6 +99,36 @@
         WSDLReader reader = factory.newWSDLReader();
         Definition def;
         def = reader.readWSDL("http://localhost:8195/Service/?wsdl", doc);
+        assertNotNull(def);
+        assertNotNull(def.getImports());
+        assertEquals(1, def.getImports().size());
+    }
+    
+    public void testExternalNonStandaloneWsdl() throws Exception {
+        // HTTP Component
+        HttpEndpoint ep = new HttpEndpoint();
+        ep.setService(new QName("http://test", "MyConsumerService"));
+        ep.setEndpoint("myConsumer");
+        ep.setRoleAsString("consumer");
+        ep.setLocationURI("http://localhost:8196/Service/");
+        ep.setWsdlResource(new UrlResource("http://www.ws-i.org/SampleApplications/SupplyChainManagement/2002-08/Retailer.wsdl"));
+        HttpSpringComponent http = new HttpSpringComponent();
+        http.setEndpoints(new HttpEndpoint[] { ep });
+        container.activateComponent(http, "HttpWsdlTest");
+        
+        // Start container
+        container.start();
+
+        GetMethod get = new GetMethod("http://localhost:8196/Service/?wsdl");
+        int state = new HttpClient().executeMethod(get);
+        assertEquals(HttpServletResponse.SC_OK, state);
+        Document doc = (Document) new SourceTransformer().toDOMNode(new StringSource(get.getResponseBodyAsString()));
+        
+        // Test WSDL
+        WSDLFactory factory = WSDLFactory.newInstance();
+        WSDLReader reader = factory.newWSDLReader();
+        Definition def;
+        def = reader.readWSDL("http://localhost:8196/Service/?wsdl", doc);
         assertNotNull(def);
         assertNotNull(def.getImports());
         assertEquals(1, def.getImports().size());

Modified: incubator/servicemix/trunk/servicemix-http/src/test/java/org/apache/servicemix/http/security/HttpSecurityTest.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-http/src/test/java/org/apache/servicemix/http/security/HttpSecurityTest.java?rev=412730&r1=412729&r2=412730&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-http/src/test/java/org/apache/servicemix/http/security/HttpSecurityTest.java (original)
+++ incubator/servicemix/trunk/servicemix-http/src/test/java/org/apache/servicemix/http/security/HttpSecurityTest.java Thu Jun  8 05:10:23 2006
@@ -15,6 +15,7 @@
  */
 package org.apache.servicemix.http.security;
 
+import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.net.URL;
 
@@ -85,6 +86,25 @@
         try {
             method.setDoAuthentication(true);
             method.setRequestEntity(new StringRequestEntity("<hello>world</hello>"));
+            int state = client.executeMethod(method);
+            if (state != HttpServletResponse.SC_OK) {
+                throw new IllegalStateException("Http status: " + state);
+            }
+            FileUtil.copyInputStream(method.getResponseBodyAsStream(), System.out);
+        } finally {
+            method.releaseConnection();
+        }
+    }
+    
+    public void testWSSec() throws Exception {
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        FileUtil.copyInputStream(getClass().getResourceAsStream("request.xml"), out);
+        String request = out.toString();
+        HttpClient client = new HttpClient();
+        PostMethod method = new PostMethod("http://localhost:8192/WSSec/");
+        try {
+            method.setDoAuthentication(true);
+            method.setRequestEntity(new StringRequestEntity(request));
             int state = client.executeMethod(method);
             if (state != HttpServletResponse.SC_OK) {
                 throw new IllegalStateException("Http status: " + state);

Modified: incubator/servicemix/trunk/servicemix-http/src/test/resources/org/apache/servicemix/http/security/secure.xml
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-http/src/test/resources/org/apache/servicemix/http/security/secure.xml?rev=412730&r1=412729&r2=412730&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-http/src/test/resources/org/apache/servicemix/http/security/secure.xml (original)
+++ incubator/servicemix/trunk/servicemix-http/src/test/resources/org/apache/servicemix/http/security/secure.xml Thu Jun  8 05:10:23 2006
@@ -1,5 +1,6 @@
 <beans xmlns:sm="http://servicemix.apache.org/config/1.0"
        xmlns:http="http://servicemix.apache.org/http/1.0"
+       xmlns:soap="http://servicemix.apache.org/soap/1.0"
        xmlns:ex="http://servicemix.org/example">
 
   <sm:container id="jbi" embedded="true" useMBeanServer="false">
@@ -29,7 +30,20 @@
 	                         role="consumer"
 	                         locationURI="http://localhost:8192/Service/"
 	          				 authMethod="basic" 
-	          				 defaultMep="http://www.w3.org/2004/08/wsdl/in-only" />
+	          				 defaultMep="http://www.w3.org/2004/08/wsdl/in-only">
+              </http:endpoint>
+              <http:endpoint service="ex:receiver"
+                             endpoint="http-wssec"
+                             targetService="ex:receiver"
+                             role="consumer"
+                             locationURI="http://localhost:8192/WSSec/"
+                             defaultMep="http://www.w3.org/2004/08/wsdl/in-only"
+                             soap="true">
+                 <http:policies>
+                   <soap:ws-addressing />
+                   <soap:ws-security receiveAction="UsernameToken" />
+                 </http:policies>
+              </http:endpoint>
 	        </http:endpoints>
 	      </http:component>
 	    </sm:component>

Modified: incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/JmsComponent.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/JmsComponent.java?rev=412730&r1=412729&r2=412730&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/JmsComponent.java (original)
+++ incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/JmsComponent.java Thu Jun  8 05:10:23 2006
@@ -21,10 +21,7 @@
 import org.apache.servicemix.common.BaseLifeCycle;
 import org.apache.servicemix.common.BaseServiceUnitManager;
 import org.apache.servicemix.common.Deployer;
-import org.apache.servicemix.jbi.util.DOMUtil;
 import org.w3c.dom.DocumentFragment;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
 
 public class JmsComponent extends BaseComponent {
 

Modified: incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/multiplexing/MultiplexingConsumerProcessor.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/multiplexing/MultiplexingConsumerProcessor.java?rev=412730&r1=412729&r2=412730&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/multiplexing/MultiplexingConsumerProcessor.java (original)
+++ incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/multiplexing/MultiplexingConsumerProcessor.java Thu Jun  8 05:10:23 2006
@@ -44,8 +44,6 @@
 import org.apache.servicemix.soap.Context;
 import org.apache.servicemix.soap.SoapFault;
 import org.apache.servicemix.soap.SoapHelper;
-import org.apache.servicemix.soap.handlers.AddressingHandler;
-import org.apache.servicemix.soap.marshalers.SoapMarshaler;
 import org.apache.servicemix.soap.marshalers.SoapMessage;
 import org.apache.servicemix.soap.marshalers.SoapWriter;
 
@@ -61,16 +59,10 @@
     protected Map pendingMessages = new ConcurrentHashMap();
     protected DeliveryChannel channel;
     protected SoapHelper soapHelper;
-    protected SoapMarshaler soapMarshaler;
     
     public MultiplexingConsumerProcessor(JmsEndpoint endpoint) {
         super(endpoint);
-        this.soapMarshaler = new SoapMarshaler(endpoint.isSoap());
-        if (endpoint.isSoap() && "1.1".equals(endpoint.getSoapVersion())) {
-            this.soapMarshaler.setSoapUri(SoapMarshaler.SOAP_11_URI);
-        }
         this.soapHelper = new SoapHelper(endpoint);
-        this.soapHelper.addPolicy(new AddressingHandler());
     }
 
     protected void doStart(InitialContext ctx) throws Exception {
@@ -127,7 +119,7 @@
                             throw new IllegalArgumentException("JMS message should be a text or bytes message");
                         }
                         String contentType = message.getStringProperty("Content-Type");
-                        SoapMessage soap = soapMarshaler.createReader().read(is, contentType);
+                        SoapMessage soap = soapHelper.getSoapMarshaler().createReader().read(is, contentType);
                         Context context = soapHelper.createContext(soap);
                         MessageExchange exchange = soapHelper.onReceive(context);
                         context.setProperty(Message.class.getName(), message);
@@ -163,7 +155,7 @@
                     SoapFault fault = new SoapFault(SoapFault.RECEIVER, null, null, null, exchange.getFault().getContent());
                     SoapMessage soapFault = soapHelper.onFault(context, fault);
                     ByteArrayOutputStream baos = new ByteArrayOutputStream();
-                    SoapWriter writer = soapMarshaler.createWriter(soapFault);
+                    SoapWriter writer = soapHelper.getSoapMarshaler().createWriter(soapFault);
                     writer.write(baos);
                     response = session.createTextMessage(baos.toString());
                     response.setStringProperty("Content-Type", writer.getContentType());
@@ -173,7 +165,7 @@
                     if (outMsg != null) {
                         SoapMessage out = soapHelper.onReply(context, outMsg);
                         ByteArrayOutputStream baos = new ByteArrayOutputStream();
-                        SoapWriter writer = soapMarshaler.createWriter(out);
+                        SoapWriter writer = soapHelper.getSoapMarshaler().createWriter(out);
                         writer.write(baos);
                         response = session.createTextMessage(baos.toString());
                         response.setStringProperty("Content-Type", writer.getContentType());

Modified: incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/multiplexing/MultiplexingProviderProcessor.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/multiplexing/MultiplexingProviderProcessor.java?rev=412730&r1=412729&r2=412730&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/multiplexing/MultiplexingProviderProcessor.java (original)
+++ incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/multiplexing/MultiplexingProviderProcessor.java Thu Jun  8 05:10:23 2006
@@ -47,8 +47,7 @@
 import org.apache.servicemix.JbiConstants;
 import org.apache.servicemix.jms.AbstractJmsProcessor;
 import org.apache.servicemix.jms.JmsEndpoint;
-import org.apache.servicemix.soap.marshalers.JBIMarshaler;
-import org.apache.servicemix.soap.marshalers.SoapMarshaler;
+import org.apache.servicemix.soap.SoapHelper;
 import org.apache.servicemix.soap.marshalers.SoapMessage;
 import org.apache.servicemix.soap.marshalers.SoapWriter;
 
@@ -65,13 +64,11 @@
     protected MessageProducer producer;
     protected Map pendingExchanges = new ConcurrentHashMap();
     protected DeliveryChannel channel;
-    protected SoapMarshaler soapMarshaler;
-    protected JBIMarshaler jbiMarshaler;
+    protected SoapHelper soapHelper;
     
     public MultiplexingProviderProcessor(JmsEndpoint endpoint) {
         super(endpoint);
-        this.soapMarshaler = new SoapMarshaler(endpoint.isSoap());
-        this.jbiMarshaler = new JBIMarshaler();
+        this.soapHelper = new SoapHelper(endpoint);
     }
 
     protected void doStart(InitialContext ctx) throws Exception {
@@ -147,9 +144,9 @@
                                 throw new IllegalArgumentException("JMS message should be a text or bytes message");
                             }
                             String contentType = message.getStringProperty("Content-Type");
-                            SoapMessage soap = soapMarshaler.createReader().read(is, contentType);
+                            SoapMessage soap = soapHelper.getSoapMarshaler().createReader().read(is, contentType);
                             NormalizedMessage out = exchange.createMessage();
-                            jbiMarshaler.toNMS(out, soap);
+                            soapHelper.getJBIMarshaler().toNMS(out, soap);
                             ((InOut) exchange).setOutMessage(out);
                         }
                         channel.send(exchange);
@@ -171,8 +168,8 @@
         }
         SoapMessage soapMessage = new SoapMessage();
         NormalizedMessage nm = exchange.getMessage("in");
-        jbiMarshaler.fromNMS(soapMessage, nm);
-        SoapWriter writer = soapMarshaler.createWriter(soapMessage);
+        soapHelper.getJBIMarshaler().fromNMS(soapMessage, nm);
+        SoapWriter writer = soapHelper.getSoapMarshaler().createWriter(soapMessage);
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         writer.write(baos);
         Message msg = session.createTextMessage(baos.toString());

Modified: incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/standard/StandardConsumerProcessor.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/standard/StandardConsumerProcessor.java?rev=412730&r1=412729&r2=412730&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/standard/StandardConsumerProcessor.java (original)
+++ incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/standard/StandardConsumerProcessor.java Thu Jun  8 05:10:23 2006
@@ -40,8 +40,6 @@
 import org.apache.servicemix.soap.Context;
 import org.apache.servicemix.soap.SoapFault;
 import org.apache.servicemix.soap.SoapHelper;
-import org.apache.servicemix.soap.handlers.AddressingHandler;
-import org.apache.servicemix.soap.marshalers.SoapMarshaler;
 import org.apache.servicemix.soap.marshalers.SoapMessage;
 import org.apache.servicemix.soap.marshalers.SoapWriter;
 
@@ -55,17 +53,11 @@
     protected Destination destination;
     protected DeliveryChannel channel;
     protected SoapHelper soapHelper;
-    protected SoapMarshaler soapMarshaler;
     protected AtomicBoolean running = new AtomicBoolean(false);
     
     public StandardConsumerProcessor(JmsEndpoint endpoint) {
         super(endpoint);
-        this.soapMarshaler = new SoapMarshaler(endpoint.isSoap());
-        if (endpoint.isSoap() && "1.1".equals(endpoint.getSoapVersion())) {
-            this.soapMarshaler.setSoapUri(SoapMarshaler.SOAP_11_URI);
-        }
         this.soapHelper = new SoapHelper(endpoint);
-        this.soapHelper.addPolicy(new AddressingHandler());
     }
 
     protected void doStart(InitialContext ctx) throws Exception {
@@ -152,7 +144,7 @@
                 throw new IllegalArgumentException("JMS message should be a text or bytes message");
             }
             String contentType = message.getStringProperty("Content-Type");
-            SoapMessage soap = soapMarshaler.createReader().read(is, contentType);
+            SoapMessage soap = soapHelper.getSoapMarshaler().createReader().read(is, contentType);
             Context context = soapHelper.createContext(soap);
             MessageExchange exchange = soapHelper.onReceive(context);
             context.setProperty(Message.class.getName(), message);
@@ -175,7 +167,7 @@
                         SoapFault fault = new SoapFault(SoapFault.RECEIVER, null, null, null, exchange.getFault().getContent());
                         SoapMessage soapFault = soapHelper.onFault(context, fault);
                         ByteArrayOutputStream baos = new ByteArrayOutputStream();
-                        SoapWriter writer = soapMarshaler.createWriter(soapFault);
+                        SoapWriter writer = soapHelper.getSoapMarshaler().createWriter(soapFault);
                         writer.write(baos);
                         response = session.createTextMessage(baos.toString());
                         response.setStringProperty("Content-Type", writer.getContentType());
@@ -185,7 +177,7 @@
                         if (outMsg != null) {
                             SoapMessage out = soapHelper.onReply(context, outMsg);
                             ByteArrayOutputStream baos = new ByteArrayOutputStream();
-                            SoapWriter writer = soapMarshaler.createWriter(out);
+                            SoapWriter writer = soapHelper.getSoapMarshaler().createWriter(out);
                             writer.write(baos);
                             response = session.createTextMessage(baos.toString());
                             response.setStringProperty("Content-Type", writer.getContentType());

Modified: incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/standard/StandardProviderProcessor.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/standard/StandardProviderProcessor.java?rev=412730&r1=412729&r2=412730&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/standard/StandardProviderProcessor.java (original)
+++ incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/standard/StandardProviderProcessor.java Thu Jun  8 05:10:23 2006
@@ -44,8 +44,7 @@
 import org.apache.servicemix.JbiConstants;
 import org.apache.servicemix.jms.AbstractJmsProcessor;
 import org.apache.servicemix.jms.JmsEndpoint;
-import org.apache.servicemix.soap.marshalers.JBIMarshaler;
-import org.apache.servicemix.soap.marshalers.SoapMarshaler;
+import org.apache.servicemix.soap.SoapHelper;
 import org.apache.servicemix.soap.marshalers.SoapMessage;
 import org.apache.servicemix.soap.marshalers.SoapWriter;
 
@@ -59,13 +58,11 @@
     protected MessageConsumer consumer;
     protected MessageProducer producer;
     protected DeliveryChannel channel;
-    protected SoapMarshaler soapMarshaler;
-    protected JBIMarshaler jbiMarshaler;
+    protected SoapHelper soapHelper;
     
     public StandardProviderProcessor(JmsEndpoint endpoint) {
         super(endpoint);
-        this.soapMarshaler = new SoapMarshaler(endpoint.isSoap());
-        this.jbiMarshaler = new JBIMarshaler();
+        this.soapHelper = new SoapHelper(endpoint);
     }
 
     protected void doStart(InitialContext ctx) throws Exception {
@@ -108,8 +105,8 @@
             
             SoapMessage soapMessage = new SoapMessage();
             NormalizedMessage nm = exchange.getMessage("in");
-            jbiMarshaler.fromNMS(soapMessage, nm);
-            SoapWriter writer = soapMarshaler.createWriter(soapMessage);
+            soapHelper.getJBIMarshaler().fromNMS(soapMessage, nm);
+            SoapWriter writer = soapHelper.getSoapMarshaler().createWriter(soapMessage);
             ByteArrayOutputStream baos = new ByteArrayOutputStream();
             writer.write(baos);
             Message msg = session.createTextMessage(baos.toString());
@@ -156,9 +153,9 @@
                         throw new IllegalArgumentException("JMS message should be a text or bytes message");
                     }
                     String contentType = message.getStringProperty("Content-Type");
-                    SoapMessage soap = soapMarshaler.createReader().read(is, contentType);
+                    SoapMessage soap = soapHelper.getSoapMarshaler().createReader().read(is, contentType);
                     NormalizedMessage out = exchange.createMessage();
-                    jbiMarshaler.toNMS(out, soap);
+                    soapHelper.getJBIMarshaler().toNMS(out, soap);
                     ((InOut) exchange).setOutMessage(out);
                 }
                 channel.send(exchange);

Modified: incubator/servicemix/trunk/servicemix-soap/pom.xml
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-soap/pom.xml?rev=412730&r1=412729&r2=412730&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-soap/pom.xml (original)
+++ incubator/servicemix/trunk/servicemix-soap/pom.xml Thu Jun  8 05:10:23 2006
@@ -51,6 +51,43 @@
       <artifactId>servicemix-core</artifactId>
       <scope>provided</scope>
     </dependency>
+    <dependency>
+      <groupId>wss4j</groupId>
+      <artifactId>wss4j</artifactId>
+    </dependency>
+    <!--
+    <dependency>
+      <groupId>bouncycastle</groupId>
+      <artifactId>bcprov-jdk14</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.opensaml</groupId>
+      <artifactId>opensaml</artifactId>
+    </dependency>
+    -->
+    <dependency>
+      <groupId>xml-security</groupId>
+      <artifactId>xmlsec</artifactId>
+    </dependency>
   </dependencies>
 
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.xbean</groupId>
+        <artifactId>maven-xbean-plugin</artifactId>
+        <executions>
+          <execution>
+            <configuration>
+              <namespace>http://servicemix.apache.org/soap/1.0</namespace>
+            </configuration>
+            <goals>
+              <goal>mapping</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+  
 </project>

Modified: incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/Handler.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/Handler.java?rev=412730&r1=412729&r2=412730&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/Handler.java (original)
+++ incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/Handler.java Thu Jun  8 05:10:23 2006
@@ -22,6 +22,12 @@
  * @since 3.0
  */
 public interface Handler {
+    
+    public boolean requireDOM();
+    
+    public void setRequired(boolean required);
+    
+    public boolean isRequired();
 
 	public void onReceive(Context context) throws Exception;
     

Modified: incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/SoapEndpoint.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/SoapEndpoint.java?rev=412730&r1=412729&r2=412730&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/SoapEndpoint.java (original)
+++ incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/SoapEndpoint.java Thu Jun  8 05:10:23 2006
@@ -15,9 +15,9 @@
  */
 package org.apache.servicemix.soap;
 
-import java.io.IOException;
-import java.io.InputStream;
 import java.net.URI;
+import java.util.Collections;
+import java.util.List;
 
 import javax.jbi.component.ComponentContext;
 import javax.jbi.messaging.MessageExchange.Role;
@@ -26,15 +26,14 @@
 import javax.wsdl.factory.WSDLFactory;
 import javax.wsdl.xml.WSDLReader;
 import javax.xml.namespace.QName;
-import javax.xml.parsers.DocumentBuilderFactory;
 
 import org.apache.servicemix.common.Endpoint;
 import org.apache.servicemix.common.ExchangeProcessor;
 import org.apache.servicemix.common.wsdl1.JbiExtension;
 import org.apache.servicemix.common.xbean.XBeanServiceUnit;
+import org.apache.servicemix.soap.handlers.addressing.AddressingHandler;
 import org.springframework.core.io.Resource;
 import org.w3c.dom.Document;
-import org.xml.sax.InputSource;
 
 public abstract class SoapEndpoint extends Endpoint {
 
@@ -49,7 +48,24 @@
     protected QName targetInterfaceName;
     protected QName targetService;
     protected String targetEndpoint;
+    protected List policies;
     
+    public SoapEndpoint() {
+        policies = Collections.singletonList(new AddressingHandler());
+    }
+    
+    /**
+     * @return the policies
+     */
+    public List getPolicies() {
+        return policies;
+    }
+    /**
+     * @param policies the policies to set
+     */
+    public void setPolicies(List policies) {
+        this.policies = policies;
+    }
     /**
      * @return Returns the defaultMep.
      */
@@ -180,29 +196,18 @@
     protected void loadWsdl() {
         // Load WSDL from the resource
         if (description == null && wsdlResource != null) {
-            InputStream is = null;
             ClassLoader cl = Thread.currentThread().getContextClassLoader();
             try {
                 if (serviceUnit instanceof XBeanServiceUnit) {
                     XBeanServiceUnit su = (XBeanServiceUnit) serviceUnit;
                     Thread.currentThread().setContextClassLoader(su.getKernel().getClassLoaderFor(su.getConfiguration()));
                 }
-                is = wsdlResource.getInputStream();
-                DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
-                dbf.setNamespaceAware(true);
-                Definition def = WSDLFactory.newInstance().newWSDLReader().readWSDL(null, new InputSource(is));
+                Definition def = WSDLFactory.newInstance().newWSDLReader().readWSDL(wsdlResource.getURL().toString());
                 overrideDefinition(def);
             } catch (Exception e) {
                 logger.warn("Could not load description from resource", e);
             } finally {
                 Thread.currentThread().setContextClassLoader(cl);
-                if (is != null) {
-                    try {
-                        is.close();
-                    } catch (IOException e) {
-                        // Ignore
-                    }
-                }
             }
         }
         // If the endpoint is a consumer, try to find

Modified: incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/SoapHelper.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/SoapHelper.java?rev=412730&r1=412729&r2=412730&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/SoapHelper.java (original)
+++ incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/SoapHelper.java Thu Jun  8 05:10:23 2006
@@ -16,7 +16,7 @@
 package org.apache.servicemix.soap;
 
 import java.net.URI;
-import java.util.ArrayList;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
@@ -40,6 +40,7 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.servicemix.soap.marshalers.JBIMarshaler;
+import org.apache.servicemix.soap.marshalers.SoapMarshaler;
 import org.apache.servicemix.soap.marshalers.SoapMessage;
 import org.w3c.dom.Document;
 
@@ -61,23 +62,42 @@
     private SoapEndpoint endpoint;
     private List policies;
     private JBIMarshaler jbiMarshaler;
+    private SoapMarshaler soapMarshaler;
     private Map definitions;
 
     public SoapHelper(SoapEndpoint endpoint) {
-        this.policies = new ArrayList();
+        this.policies = endpoint.getPolicies();
+        if (this.policies == null) {
+            this.policies = Collections.EMPTY_LIST;
+        }
         this.definitions = new HashMap();
         this.jbiMarshaler = new JBIMarshaler();
         this.endpoint = endpoint;
+        boolean requireDom = false;
+        for (Iterator iter = policies.iterator(); iter.hasNext();) {
+            Handler handler = (Handler) iter.next();
+            requireDom |= handler.requireDOM();
+        }
+        this.soapMarshaler = new SoapMarshaler(endpoint.isSoap(), requireDom);
+        if (endpoint.isSoap() && "1.1".equals(endpoint.getSoapVersion())) {
+            this.soapMarshaler.setSoapUri(SoapMarshaler.SOAP_11_URI);
+        }
     }
-
-    public void addPolicy(Handler policy) {
-        policies.add(policy);
+    
+    public SoapMarshaler getSoapMarshaler() {
+        return this.soapMarshaler;
+    }
+    
+    public JBIMarshaler getJBIMarshaler() {
+        return this.jbiMarshaler;
     }
 
     public MessageExchange onReceive(Context context) throws Exception {
-        for (Iterator it = policies.iterator(); it.hasNext();) {
-            Handler policy = (Handler) it.next();
-            policy.onReceive(context);
+        if (policies != null) {
+            for (Iterator it = policies.iterator(); it.hasNext();) {
+                Handler policy = (Handler) it.next();
+                policy.onReceive(context);
+            }
         }
         URI mep = findMep(context);
         if (mep == null) {
@@ -130,9 +150,11 @@
         }
         jbiMarshaler.fromNMS(out, outMsg);
         context.setOutMessage(out);
-        for (Iterator it = policies.iterator(); it.hasNext();) {
-            Handler policy = (Handler) it.next();
-            policy.onReply(context);
+        if (policies != null) {
+            for (Iterator it = policies.iterator(); it.hasNext();) {
+                Handler policy = (Handler) it.next();
+                policy.onReply(context);
+            }
         }
         return out;
     }
@@ -147,9 +169,11 @@
             soapFault.setEnvelopeName(context.getInMessage().getEnvelopeName());
         }
         context.setFaultMessage(soapFault);
-        for (Iterator it = policies.iterator(); it.hasNext();) {
-            Handler policy = (Handler) it.next();
-            policy.onFault(context);
+        if (policies != null) {
+            for (Iterator it = policies.iterator(); it.hasNext();) {
+                Handler policy = (Handler) it.next();
+                policy.onFault(context);
+            }
         }
         return soapFault;
     }

Modified: incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/handlers/AbstractHandler.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/handlers/AbstractHandler.java?rev=412730&r1=412729&r2=412730&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/handlers/AbstractHandler.java (original)
+++ incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/handlers/AbstractHandler.java Thu Jun  8 05:10:23 2006
@@ -25,6 +25,26 @@
  * @since 3.0
  */
 public class AbstractHandler implements Handler {
+    
+    private boolean required;
+
+    /**
+     * @return the required
+     */
+    public boolean isRequired() {
+        return required;
+    }
+
+    /**
+     * @param required the required to set
+     */
+    public void setRequired(boolean required) {
+        this.required = required;
+    }
+    
+    public boolean requireDOM() {
+        return false;
+    }
 
     public void onReceive(Context context) throws Exception {
     }

Added: incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/handlers/addressing/AddressingHandler.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/handlers/addressing/AddressingHandler.java?rev=412730&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/handlers/addressing/AddressingHandler.java (added)
+++ incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/handlers/addressing/AddressingHandler.java Thu Jun  8 05:10:23 2006
@@ -0,0 +1,162 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * 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.
+ */
+package org.apache.servicemix.soap.handlers.addressing;
+
+import java.util.Iterator;
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+
+import org.apache.activemq.util.IdGenerator;
+import org.apache.servicemix.jbi.jaxp.SourceTransformer;
+import org.apache.servicemix.jbi.util.DOMUtil;
+import org.apache.servicemix.soap.Context;
+import org.apache.servicemix.soap.SoapFault;
+import org.apache.servicemix.soap.handlers.AbstractHandler;
+import org.apache.servicemix.soap.marshalers.SoapMessage;
+import org.w3c.dom.Document;
+import org.w3c.dom.DocumentFragment;
+import org.w3c.dom.Element;
+
+/**
+ * 
+ * @author Guillaume Nodet
+ * @version $Revision: 1.5 $
+ * @since 3.0
+ * 
+ * @org.apache.xbean.XBean element="ws-addressing"
+ */
+public class AddressingHandler extends AbstractHandler {
+
+    public static final String WSA_NAMESPACE_200303 = "http://schemas.xmlsoap.org/ws/2003/03/addressing";
+    public static final String WSA_NAMESPACE_200403 = "http://schemas.xmlsoap.org/ws/2004/03/addressing";
+    public static final String WSA_NAMESPACE_200408 = "http://schemas.xmlsoap.org/ws/2004/08/addressing";
+    public static final String WSA_NAMESPACE_200508 = "http://www.w3.org/2005/08/addressing";
+    
+    public static final String WSA_PREFIX = "wsa";
+    
+    public static final String EL_ACTION = "Action";
+    public static final String EL_ADDRESS = "Address";
+    public static final String EL_FAULT_TO = "FaultTo";
+    public static final String EL_FROM = "From";
+    public static final String EL_MESSAGE_ID = "MessageID";
+    public static final String EL_METADATA = "Metadata";
+    public static final String EL_REFERENCE_PARAMETERS = "ReferenceParameters";
+    public static final String EL_RELATES_TO = "RelatesTo";
+    public static final String EL_REPLY_TO = "ReplyTo";
+    public static final String EL_TO = "To";
+    
+    protected final SourceTransformer sourceTransformer = new SourceTransformer();
+    protected final IdGenerator idGenerator = new IdGenerator();
+    
+	public void onReceive(Context context) throws Exception {
+		SoapMessage message = context.getInMessage();
+    	String action = null;
+    	String to = null;
+    	String nsUri = null;
+    	Map headers = message.getHeaders();
+    	if (headers != null) {
+	    	for (Iterator it = headers.keySet().iterator(); it.hasNext();) {
+	    		QName qname = (QName) it.next();
+	    		Object value = headers.get(qname);
+                if (isWSANamespace(qname.getNamespaceURI())) {
+	    			if (nsUri == null) {
+	    				nsUri = qname.getNamespaceURI();
+	    			} else if (!nsUri.equals(qname.getNamespaceURI())) {
+	    				throw new SoapFault(SoapFault.SENDER, "Inconsistent use of wsa namespaces");
+	    			}
+		    		if (EL_ACTION.equals(qname.getLocalPart())) {
+		    			action = getHeaderText(value);
+		        		String[] parts = split(action);
+		        		context.setProperty(Context.INTERFACE, new QName(parts[0], parts[1]));
+		        		context.setProperty(Context.OPERATION, new QName(parts[0], parts[2]));
+		    		} else if (EL_TO.equals(qname.getLocalPart())) {
+                        to = getHeaderText(value);
+		        		String[] parts = split(to);
+		        		context.setProperty(Context.SERVICE, new QName(parts[0], parts[1]));
+		        		context.setProperty(Context.ENDPOINT, parts[2]);
+		    		} else {
+		    			// TODO: what ?
+		    		}
+	    		}
+	    	}
+    	}
+	}
+    
+    public void onReply(Context context) throws Exception {
+        SoapMessage in = context.getInMessage();
+        SoapMessage out = context.getOutMessage();
+        Map headers = in.getHeaders();
+        if (headers != null) {
+            for (Iterator it = headers.keySet().iterator(); it.hasNext();) {
+                QName qname = (QName) it.next();
+                Object value = headers.get(qname);
+                if (isWSANamespace(qname.getNamespaceURI())) {
+                    if (EL_MESSAGE_ID.equals(qname.getLocalPart())) {
+                        QName name = new QName(qname.getNamespaceURI(), EL_MESSAGE_ID, qname.getPrefix() != null ? qname.getPrefix() : WSA_PREFIX);
+                        DocumentFragment df = createHeader(name, idGenerator.generateSanitizedId());
+                        out.addHeader(name, df);
+                        name = new QName(qname.getNamespaceURI(), EL_RELATES_TO, qname.getPrefix() != null ? qname.getPrefix() : WSA_PREFIX);
+                        df = createHeader(name, getHeaderText(value));
+                        out.addHeader(name, df);
+                    }
+                }
+            }
+        }
+    }
+    
+    public void onFault(Context context) throws Exception {
+        // TODO: handle MessageID ?
+    }
+    
+    protected boolean isWSANamespace(String ns) {
+        return WSA_NAMESPACE_200303.equals(ns) ||
+               WSA_NAMESPACE_200403.equals(ns) ||
+               WSA_NAMESPACE_200408.equals(ns) ||
+               WSA_NAMESPACE_200508.equals(ns);
+    }
+    
+    protected String getHeaderText(Object header) {
+        Element el = (Element) ((DocumentFragment) header).getFirstChild();
+        return DOMUtil.getElementText(el);
+    }
+    
+    protected DocumentFragment createHeader(QName name, String value) throws Exception {
+        Document doc = new SourceTransformer().createDocument();
+        DocumentFragment df = doc.createDocumentFragment();
+        Element el = doc.createElementNS(name.getNamespaceURI(), name.getPrefix() + ":" + name.getLocalPart());
+        el.appendChild(doc.createTextNode(value));
+        df.appendChild(el);
+        return df;
+    }
+    
+    protected String[] split(String uri) {
+		char sep;
+        uri = uri.trim();
+		if (uri.indexOf('/') > 0) {
+			sep = '/';
+		} else {
+			sep = ':';
+		}
+		int idx1 = uri.lastIndexOf(sep);
+		int idx2 = uri.lastIndexOf(sep, idx1 - 1);
+		String epName = uri.substring(idx1 + 1);
+		String svcName = uri.substring(idx2 + 1, idx1);
+		String nsUri   = uri.substring(0, idx2);
+    	return new String[] { nsUri, svcName, epName };
+    }
+    
+}

Added: incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/handlers/security/BaseSecurityCallbackHandler.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/handlers/security/BaseSecurityCallbackHandler.java?rev=412730&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/handlers/security/BaseSecurityCallbackHandler.java (added)
+++ incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/handlers/security/BaseSecurityCallbackHandler.java Thu Jun  8 05:10:23 2006
@@ -0,0 +1,119 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * 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.
+ */
+package org.apache.servicemix.soap.handlers.security;
+
+import java.io.IOException;
+
+import javax.security.auth.callback.Callback;
+import javax.security.auth.callback.CallbackHandler;
+import javax.security.auth.callback.UnsupportedCallbackException;
+
+import org.apache.ws.security.WSPasswordCallback;
+
+/**
+ * Base implementation for security callback handler.
+ * 
+ * @author gnodet
+ */
+public class BaseSecurityCallbackHandler implements CallbackHandler {
+    
+    public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
+        if (callbacks == null || callbacks.length == 0) {
+            throw new IllegalStateException("callbacks is null or empty");
+        }
+        for (int i = 0; i < callbacks.length; i++) {
+            if (callbacks[i] instanceof WSPasswordCallback == false) {
+                throw new UnsupportedCallbackException(callbacks[i]);
+            }
+            processCallback((WSPasswordCallback) callbacks[i]);
+        }
+    } 
+    
+    protected void processCallback(WSPasswordCallback callback) throws IOException, UnsupportedCallbackException {
+        switch (callback.getUsage()) {
+        case WSPasswordCallback.DECRYPT:
+            processDecrypt(callback);
+            break;
+        case WSPasswordCallback.USERNAME_TOKEN:
+            processUsernameToken(callback);
+            break;
+        case WSPasswordCallback.SIGNATURE:
+            processSignature(callback);
+            break;
+        case WSPasswordCallback.KEY_NAME:
+            processKeyName(callback);
+            break;
+        case WSPasswordCallback.USERNAME_TOKEN_UNKNOWN:
+            processUsernameTokenUnkown(callback);
+            break;
+        default:
+            throw new UnsupportedCallbackException(callback);
+        }
+    }
+
+    /**
+     * Need a password to get the private key of
+     * this identifier (username) from    the keystore. WSS4J uses this private
+     * key to decrypt the session (symmetric) key. Because the encryption
+     * method uses the public key to encrypt the session key it needs no
+     * password (a public key is usually not protected by a password)
+     */
+    protected void processDecrypt(WSPasswordCallback callback) throws IOException, UnsupportedCallbackException {
+        throw new UnsupportedCallbackException(callback);
+    }
+    
+    /** 
+     * Need the password to fill in or to
+     * verify a <code>UsernameToken</code>
+     */
+    protected void processUsernameToken(WSPasswordCallback callback) throws IOException, UnsupportedCallbackException {
+        throw new UnsupportedCallbackException(callback);
+    }
+    
+    /**
+     * Need the password to get the private key of
+     * this identifier (username) from    the keystore. WSS4J uses this private
+     * key to produce a signature. The signature verfication uses the public
+     * key to verfiy the signature
+     */
+    protected void processSignature(WSPasswordCallback callback) throws IOException, UnsupportedCallbackException {
+        throw new UnsupportedCallbackException(callback);
+    }
+    
+    /**
+     * Need the <i>key</i>, not the password,
+     * associated with the identifier. WSS4J uses this key to encrypt or
+     * decrypt parts of the SOAP request. Note, the key must match the
+     * symmetric encryption/decryption algorithm specified (refer to
+     * {@link org.apache.ws.security.handler.WSHandlerConstants#ENC_SYM_ALGO})
+     */
+    protected void processKeyName(WSPasswordCallback callback) throws IOException, UnsupportedCallbackException {
+        throw new UnsupportedCallbackException(callback);
+    }
+    
+    /**
+     * Either a not specified 
+     * password type or a password type passwordText. In these both cases <b>only</b>
+     * the password variable is <b>set</>. The callback class now may check if
+     * the username and password match. If they don't match the callback class must
+     * throw an exception. The exception can be a UnsupportedCallbackException or
+     * an IOException.</li>
+     */
+    protected void processUsernameTokenUnkown(WSPasswordCallback callback) throws IOException, UnsupportedCallbackException {
+        throw new UnsupportedCallbackException(callback);
+    }
+    
+}

Added: incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/handlers/security/WSSecurityHandler.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/handlers/security/WSSecurityHandler.java?rev=412730&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/handlers/security/WSSecurityHandler.java (added)
+++ incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/handlers/security/WSSecurityHandler.java Thu Jun  8 05:10:23 2006
@@ -0,0 +1,369 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * 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.
+ */
+package org.apache.servicemix.soap.handlers.security;
+
+import java.io.IOException;
+import java.security.Principal;
+import java.security.cert.X509Certificate;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Vector;
+
+import javax.security.auth.Subject;
+import javax.security.auth.callback.Callback;
+import javax.security.auth.callback.CallbackHandler;
+import javax.security.auth.callback.NameCallback;
+import javax.security.auth.callback.PasswordCallback;
+import javax.security.auth.callback.UnsupportedCallbackException;
+import javax.security.auth.login.LoginContext;
+import javax.security.auth.login.LoginException;
+import javax.xml.transform.Source;
+import javax.xml.transform.dom.DOMSource;
+
+import org.apache.servicemix.soap.Context;
+import org.apache.servicemix.soap.Handler;
+import org.apache.servicemix.soap.SoapFault;
+import org.apache.ws.security.WSConstants;
+import org.apache.ws.security.WSPasswordCallback;
+import org.apache.ws.security.WSSecurityEngineResult;
+import org.apache.ws.security.WSSecurityException;
+import org.apache.ws.security.handler.RequestData;
+import org.apache.ws.security.handler.WSHandler;
+import org.apache.ws.security.handler.WSHandlerConstants;
+import org.apache.ws.security.handler.WSHandlerResult;
+import org.apache.ws.security.message.token.Timestamp;
+import org.apache.ws.security.util.WSSecurityUtil;
+import org.w3c.dom.Document;
+
+/**
+ * WS-Security handler.
+ * This handler is heavily based on xfire-ws-security project.
+ * 
+ * @org.apache.xbean.XBean element="ws-security"
+ */
+public class WSSecurityHandler extends WSHandler implements Handler {
+
+    private Map properties = new HashMap();
+    private String domain = "servicemix-domain";
+
+    private boolean required;
+    private String sendAction;
+    private String receiveAction;
+    private String actor;
+    private CallbackHandler handler = new DefaultHandler();
+    
+    private ThreadLocal currentSubject = new ThreadLocal();
+
+    /**
+     * @return the actor
+     */
+    public String getActor() {
+        return actor;
+    }
+
+    /**
+     * @param actor the actor to set
+     */
+    public void setActor(String actor) {
+        this.actor = actor;
+    }
+
+    /**
+     * @return the domain
+     */
+    public String getDomain() {
+        return domain;
+    }
+
+    /**
+     * @param domain the domain to set
+     */
+    public void setDomain(String domain) {
+        this.domain = domain;
+    }
+
+    /**
+     * @return the receiveAction
+     */
+    public String getReceiveAction() {
+        return receiveAction;
+    }
+
+    /**
+     * @param receiveAction the receiveAction to set
+     */
+    public void setReceiveAction(String receiveAction) {
+        this.receiveAction = receiveAction;
+    }
+
+    /**
+     * @return the action
+     */
+    public String getSendAction() {
+        return sendAction;
+    }
+
+    /**
+     * @param action the action to set
+     */
+    public void setSendAction(String action) {
+        this.sendAction = action;
+    }
+
+    /**
+     * @return the required
+     */
+    public boolean isRequired() {
+        return required;
+    }
+
+    public boolean requireDOM() {
+        return true;
+    }
+
+    /**
+     * @param required the required to set
+     */
+    public void setRequired(boolean required) {
+        this.required = required;
+    }
+
+    public Object getOption(String key) {
+        return properties.get(key);
+    }
+
+    public void setOption(String key, Object value) {
+        this.properties.put(key, value);
+    }
+
+    public String getPassword(Object msgContext) {
+        return (String) ((Context) msgContext).getProperty("password");
+    }
+
+    public Object getProperty(Object msgContext, String key) {
+        return ((Context) msgContext).getProperty(key); 
+    }
+
+    public void setPassword(Object msgContext, String password) {
+        ((Context) msgContext).setProperty("password", password);
+    }
+
+    public void setProperty(Object msgContext, String key, Object value) {
+        ((Context) msgContext).setProperty(key, value);
+    }
+
+    public void onComplete(Context context) {
+        // TODO Auto-generated method stub
+
+    }
+
+    public void onException(Context context, Exception e) {
+        // TODO Auto-generated method stub
+
+    }
+
+    public void onFault(Context context) throws Exception {
+        // TODO Auto-generated method stub
+
+    }
+
+    public void onReceive(Context context) throws Exception {
+        RequestData reqData = new RequestData();
+        currentSubject.set(null);
+        try {
+            reqData.setMsgContext(context);
+
+            Vector actions = new Vector();
+            String action = this.receiveAction;
+            if (action == null) {
+                throw new IllegalStateException("WSSecurityHandler: No receiveAction defined");
+            }
+            int doAction = WSSecurityUtil.decodeAction(action, actions);
+
+            Source src = context.getInMessage().getSource();
+            if (src instanceof DOMSource == false) {
+                throw new IllegalStateException("WSSecurityHandler: The soap message has not been parsed using DOM");
+            }
+            Document doc = ((DOMSource) src).getNode().getOwnerDocument();
+
+            /*
+             * Get and check the Signature specific parameters first because
+             * they may be used for encryption too.
+             */
+            doReceiverAction(doAction, reqData);
+
+            Vector wsResult = null;
+
+            try {
+                wsResult = secEngine.processSecurityHeader(
+                                doc, actor, handler, 
+                                reqData.getSigCrypto(), 
+                                reqData.getDecCrypto());
+            } catch (WSSecurityException ex) {
+                throw new SoapFault(ex);
+            }
+
+            if (wsResult == null) { // no security header found
+                if (doAction == WSConstants.NO_SECURITY) {
+                    return;
+                } else {
+                    throw new SoapFault(new WSSecurityException(
+                                    "WSSecurityHandler: Request does not contain required Security header"));
+                }
+            }
+
+            if (reqData.getWssConfig().isEnableSignatureConfirmation()) {
+                checkSignatureConfirmation(reqData, wsResult);
+            }
+
+            /*
+             * Now we can check the certificate used to sign the message. In the
+             * following implementation the certificate is only trusted if
+             * either it itself or the certificate of the issuer is installed in
+             * the keystore.
+             * 
+             * Note: the method verifyTrust(X509Certificate) allows custom
+             * implementations with other validation algorithms for subclasses.
+             */
+
+            // Extract the signature action result from the action vector
+            WSSecurityEngineResult actionResult = WSSecurityUtil.fetchActionResult(wsResult, WSConstants.SIGN);
+
+            if (actionResult != null) {
+                X509Certificate returnCert = actionResult.getCertificate();
+
+                if (returnCert != null) {
+                    if (!verifyTrust(returnCert, reqData)) {
+                        throw new SoapFault(new WSSecurityException(
+                                        "WSSecurityHandler: the certificate used for the signature is not trusted"));
+                    }
+                }
+            }
+
+            /*
+             * Perform further checks on the timestamp that was transmitted in
+             * the header. In the following implementation the timestamp is
+             * valid if it was created after (now-ttl), where ttl is set on
+             * server side, not by the client.
+             * 
+             * Note: the method verifyTimestamp(Timestamp) allows custom
+             * implementations with other validation algorithms for subclasses.
+             */
+
+            // Extract the timestamp action result from the action vector
+            actionResult = WSSecurityUtil.fetchActionResult(wsResult, WSConstants.TS);
+
+            if (actionResult != null) {
+                Timestamp timestamp = actionResult.getTimestamp();
+
+                if (timestamp != null) {
+                    if (!verifyTimestamp(timestamp, decodeTimeToLive(reqData))) {
+                        throw new SoapFault(new WSSecurityException(
+                                        "WSSecurityHandler: the timestamp could not be validated"));
+                    }
+                }
+            }
+
+            /*
+             * now check the security actions: do they match, in right order?
+             */
+            if (!checkReceiverResults(wsResult, actions)) {
+                throw new SoapFault(new WSSecurityException(
+                                "WSSecurityHandler: security processing failed (actions mismatch)"));
+
+            }
+            /*
+             * All ok up to this point. Now construct and setup the security
+             * result structure. The service may fetch this and check it.
+             */
+            Vector results = null;
+            if ((results = (Vector) context.getProperty(WSHandlerConstants.RECV_RESULTS)) == null) {
+                results = new Vector();
+                context.setProperty(WSHandlerConstants.RECV_RESULTS, results);
+            }
+            WSHandlerResult rResult = new WSHandlerResult(actor, wsResult);
+            results.add(0, rResult);
+
+            // Add principals to the message
+            for (Iterator iter = results.iterator(); iter.hasNext();) {
+                WSHandlerResult hr = (WSHandlerResult) iter.next();
+                for (Iterator it = hr.getResults().iterator(); it.hasNext();) {
+                    WSSecurityEngineResult er = (WSSecurityEngineResult) it.next();
+                    if (er.getPrincipal() != null) {
+                        context.getInMessage().addPrincipal(er.getPrincipal());
+                    }
+                }
+            }
+            Subject s = (Subject) currentSubject.get();
+            if (s != null) {
+                for (Iterator iterator = s.getPrincipals().iterator(); iterator.hasNext();) {
+                    Principal p = (Principal) iterator.next();
+                    context.getInMessage().addPrincipal(p);
+                }
+            }
+
+        } finally {
+            reqData.clear();
+            currentSubject.set(null);
+        }
+    }
+
+    public void onReply(Context context) throws Exception {
+        // TODO Auto-generated method stub
+
+    }
+    
+    protected class DefaultHandler extends BaseSecurityCallbackHandler {
+
+        protected void processUsernameTokenUnkown(WSPasswordCallback callback) throws IOException, UnsupportedCallbackException {
+            /* either an not specified 
+             * password type or a password type passwordText. In these both cases <b>only</b>
+             * the password variable is <b>set</>. The callback class now may check if
+             * the username and password match. If they don't match the callback class must
+             * throw an exception. The exception can be a UnsupportedCallbackException or
+             * an IOException.</li>
+             */
+            final String username = callback.getIdentifer();
+            final String password = callback.getPassword();
+            Subject subject = (Subject) currentSubject.get();
+            if (subject == null) {
+                subject = new Subject();
+                currentSubject.set(subject);
+            }
+            try {
+                LoginContext loginContext = new LoginContext(domain, subject, new CallbackHandler() {
+                    public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
+                        for (int i = 0; i < callbacks.length; i++) {
+                            if (callbacks[i] instanceof NameCallback) {
+                                ((NameCallback) callbacks[i]).setName(username);
+                            } else if (callbacks[i] instanceof PasswordCallback) {
+                                ((PasswordCallback) callbacks[i]).setPassword(password.toCharArray());
+                            } else {
+                                throw new UnsupportedCallbackException(callbacks[i]);
+                            }
+                        }
+                    }
+                });
+                loginContext.login();
+            } catch (LoginException e) {
+                throw new UnsupportedCallbackException(callback, "Unable to authenticate user");
+            }
+        }
+        
+    }
+
+}

Modified: incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/marshalers/SoapWriter.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/marshalers/SoapWriter.java?rev=412730&r1=412729&r2=412730&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/marshalers/SoapWriter.java (original)
+++ incubator/servicemix/trunk/servicemix-soap/src/main/java/org/apache/servicemix/soap/marshalers/SoapWriter.java Thu Jun  8 05:10:23 2006
@@ -35,7 +35,6 @@
 import javax.mail.internet.MimeMultipart;
 import javax.xml.XMLConstants;
 import javax.xml.namespace.QName;
-import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
 import javax.xml.stream.XMLStreamWriter;
 import javax.xml.transform.Source;

Added: incubator/servicemix/trunk/servicemix-soap/src/test/java/org/apache/servicemix/soap/handlers/WSSecurityHandlerTest.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-soap/src/test/java/org/apache/servicemix/soap/handlers/WSSecurityHandlerTest.java?rev=412730&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-soap/src/test/java/org/apache/servicemix/soap/handlers/WSSecurityHandlerTest.java (added)
+++ incubator/servicemix/trunk/servicemix-soap/src/test/java/org/apache/servicemix/soap/handlers/WSSecurityHandlerTest.java Thu Jun  8 05:10:23 2006
@@ -0,0 +1,74 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * 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.
+ */
+package org.apache.servicemix.soap.handlers;
+
+import java.io.IOException;
+import java.security.Principal;
+import java.util.List;
+
+import javax.security.auth.callback.Callback;
+import javax.security.auth.callback.CallbackHandler;
+import javax.security.auth.callback.UnsupportedCallbackException;
+
+import junit.framework.TestCase;
+
+import org.apache.servicemix.soap.Context;
+import org.apache.servicemix.soap.handlers.security.WSSecurityHandler;
+import org.apache.servicemix.soap.marshalers.SoapMarshaler;
+import org.apache.servicemix.soap.marshalers.SoapMessage;
+import org.apache.servicemix.soap.marshalers.SoapReader;
+import org.apache.ws.security.WSSecurityEngineResult;
+import org.apache.ws.security.WSUsernameTokenPrincipal;
+import org.apache.ws.security.handler.WSHandlerConstants;
+import org.apache.ws.security.handler.WSHandlerResult;
+
+public class WSSecurityHandlerTest extends TestCase {
+    
+    public void testUserNameToken() throws Exception {
+        SoapMarshaler marshaler = new SoapMarshaler(true, true);
+        SoapReader reader = marshaler.createReader();
+        SoapMessage msg = reader.read(getClass().getResourceAsStream("sample-wsse-request.xml"));
+        Context ctx = new Context();
+        ctx.setInMessage(msg);
+        
+        WSSecurityHandler handler = new WSSecurityHandler();
+        handler.setOption(WSHandlerConstants.ACTION, WSHandlerConstants.USERNAME_TOKEN);
+        ctx.setProperty(WSHandlerConstants.PW_CALLBACK_REF, new CallbackHandler() {
+            public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
+                System.err.println("Callback");
+            } 
+        });
+        handler.onReceive(ctx);
+        List l = (List) ctx.getProperty(WSHandlerConstants.RECV_RESULTS);
+        assertNotNull(l);
+        assertEquals(1, l.size());
+        WSHandlerResult result = (WSHandlerResult) l.get(0);
+        assertNotNull(result);
+        assertNotNull(result.getResults());
+        assertEquals(1, result.getResults().size());
+        WSSecurityEngineResult engResult = (WSSecurityEngineResult) result.getResults().get(0);
+        assertNotNull(engResult);
+        Principal principal = engResult.getPrincipal();
+        assertNotNull(principal);
+        assertTrue(principal instanceof WSUsernameTokenPrincipal);
+        assertEquals("cupareq", ((WSUsernameTokenPrincipal) principal).getName());
+        assertEquals("cupareq1", ((WSUsernameTokenPrincipal) principal).getPassword());
+        assertNotNull(ctx.getInMessage().getSubject());
+        assertNotNull(ctx.getInMessage().getSubject().getPrincipals());
+        assertEquals(1, ctx.getInMessage().getSubject().getPrincipals().size());
+    }
+
+}

Added: incubator/servicemix/trunk/servicemix-soap/src/test/resources/org/apache/servicemix/soap/handlers/sample-wsse-request.xml
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-soap/src/test/resources/org/apache/servicemix/soap/handlers/sample-wsse-request.xml?rev=412730&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-soap/src/test/resources/org/apache/servicemix/soap/handlers/sample-wsse-request.xml (added)
+++ incubator/servicemix/trunk/servicemix-soap/src/test/resources/org/apache/servicemix/soap/handlers/sample-wsse-request.xml Thu Jun  8 05:10:23 2006
@@ -0,0 +1,32 @@
+<soapenv:Envelope
+  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+  xmlns:q0="http://www.gawda.org/GAWDA/"
+  xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
+  <soapenv:Header>
+    <wsse:Security soapenv:mustUnderstand="1">
+      <wsse:UsernameToken>
+        <wsse:Username>cupareq</wsse:Username>
+        <wsse:Password>cupareq1</wsse:Password>
+      </wsse:UsernameToken>
+    </wsse:Security>
+  </soapenv:Header>
+  <soapenv:Body>
+    <q0:PriceCheckRequest>
+      <q0:PriceCheckRequestHeader>
+        <q0:PriceCheckRequestID>Test Request</q0:PriceCheckRequestID>
+        <q0:PriceCheckRequestIssueDate>2005-11-15T15:22:42.296Z</q0:PriceCheckRequestIssueDate>
+        <q0:SellerDB>512001</q0:SellerDB>
+      </q0:PriceCheckRequestHeader>
+      <q0:PriceCheckRequestItemDetails>
+        <q0:PriceCheckRequestItemDetail>
+          <q0:BuyerLineItemNum>100</q0:BuyerLineItemNum>
+          <q0:ManufacturerItemNum>3M 1100</q0:ManufacturerItemNum>
+          <q0:RequestedQuantity>1</q0:RequestedQuantity>
+          <q0:UnitOfMeasurement>EA</q0:UnitOfMeasurement>
+        </q0:PriceCheckRequestItemDetail>
+      </q0:PriceCheckRequestItemDetails>
+    </q0:PriceCheckRequest>
+  </soapenv:Body>
+</soapenv:Envelope>



Mime
View raw message