[jboss-svn-commits] JBL Code SVN: r38418 - in labs/jbossesb/tags/GSS-5.3.1-ONEOFF-1003/product/rosetta: src/org/jboss/soa/esb/services/security/auth/ws and 1 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Thu Sep 19 22:54:45 EDT 2013


Author: tcunning
Date: 2013-09-19 22:54:45 -0400 (Thu, 19 Sep 2013)
New Revision: 38418

Added:
   labs/jbossesb/tags/GSS-5.3.1-ONEOFF-1003/product/rosetta/tests/src/org/jboss/soa/esb/services/security/auth/ws/SOAP12UsernameTokenExtractorUnitTest.java
   labs/jbossesb/tags/GSS-5.3.1-ONEOFF-1003/product/rosetta/tests/src/org/jboss/soa/esb/services/security/auth/ws/soap1.2-sample.xml
   labs/jbossesb/tags/GSS-5.3.1-ONEOFF-1003/product/rosetta/tests/src/org/jboss/soa/esb/services/security/auth/ws/xml.xsd
Modified:
   labs/jbossesb/tags/GSS-5.3.1-ONEOFF-1003/product/rosetta/src/org/jboss/internal/soa/esb/webservice/BaseWebService.java
   labs/jbossesb/tags/GSS-5.3.1-ONEOFF-1003/product/rosetta/src/org/jboss/soa/esb/services/security/auth/ws/SoapConstants.java
   labs/jbossesb/tags/GSS-5.3.1-ONEOFF-1003/product/rosetta/src/org/jboss/soa/esb/services/security/auth/ws/SoapExtractionUtil.java
Log:
Merge changes from JBESB-3946.


Modified: labs/jbossesb/tags/GSS-5.3.1-ONEOFF-1003/product/rosetta/src/org/jboss/internal/soa/esb/webservice/BaseWebService.java
===================================================================
--- labs/jbossesb/tags/GSS-5.3.1-ONEOFF-1003/product/rosetta/src/org/jboss/internal/soa/esb/webservice/BaseWebService.java	2013-09-20 02:39:42 UTC (rev 38417)
+++ labs/jbossesb/tags/GSS-5.3.1-ONEOFF-1003/product/rosetta/src/org/jboss/internal/soa/esb/webservice/BaseWebService.java	2013-09-20 02:54:45 UTC (rev 38418)
@@ -36,6 +36,7 @@
 import javax.xml.soap.Detail;
 import javax.xml.soap.Node;
 import javax.xml.soap.SOAPBody;
+import javax.xml.soap.SOAPConstants;
 import javax.xml.soap.SOAPElement;
 import javax.xml.soap.SOAPException;
 import javax.xml.soap.SOAPFault;
@@ -90,11 +91,17 @@
 public abstract class BaseWebService implements Provider<SOAPMessage>
 {
     private static final QName SERVER_FAULT_QN = new QName("http://schemas.xmlsoap.org/soap/envelope/", "Server") ;
+    private static final QName SOAP_12_SERVER_FAULT_QN = new QName("http://www.w3.org/2003/05/soap-envelope", "Server");
+    
+    private static final QName SOAP_BODY_QN = new QName("http://schemas.xmlsoap.org/soap/envelope/", "Body");
+    private static final QName SOAP_12_BODY_QN = new QName("http://www.w3.org/2003/05/soap-envelope", "Body");
 
     private static final boolean RETURN_STACK_TRACES ;
     private static final Logger LOGGER = Logger.getLogger(BaseWebService.class);
     private static final javax.xml.soap.MessageFactory SOAP_MESSAGE_FACTORY ;
+    private static final javax.xml.soap.MessageFactory SOAP_12_MESSAGE_FACTORY ;
 
+    
     private static final MAPBuilder ADDRESSING_BUILDER = MAPBuilderFactory.getInstance().getBuilderInstance() ;
     private static final String ADDRESSING_NAMESPACE = AddressingConstants.Core.NS ;
     private static final QName ADDRESSING_REPLY = new QName(ADDRESSING_NAMESPACE, "Reply") ;
@@ -111,7 +118,7 @@
     protected final MessagePayloadProxy requestProxy ;
     protected final MessagePayloadProxy responseProxy ;
     protected final String action ;
-    protected final Integer messageFlowPriority ;
+    protected final Integer messageFlowPriority;
 
     protected BaseWebService(final String deployment, final ServiceInvoker serviceInvoker, final String requestLocation, final String responseLocation, final String action,
         final Integer messageFlowPriority)
@@ -141,9 +148,14 @@
         {
             Thread.currentThread().setContextClassLoader(deploymentClassLoader) ;
         }
+        boolean isSoap12 = false;
         try
         {
-            final SOAPBody soapBody = request.getSOAPBody() ;
+            final SOAPBody soapBody = request.getSOAPBody();
+            if (soapBody.getElementName().toString().equals(SOAP_12_BODY_QN.toString())) {
+                isSoap12 = true;
+            }
+          
             if (soapBody == null)
             {
                 throw new WebServiceException("Missing SOAP body from request") ;
@@ -205,7 +217,13 @@
 	            MessageFlowContext.setMessageFlowPriority(null) ;
 	        }
             
-            final SOAPMessage response = SOAP_MESSAGE_FACTORY.createMessage();
+            SOAPMessage response = null;
+            if (isSoap12) {
+                response = SOAP_12_MESSAGE_FACTORY.createMessage();
+
+            } else {
+                response = SOAP_MESSAGE_FACTORY.createMessage();
+            }
             if (esbRes != null)
             {
                 final Object input = responseProxy.getPayload(esbRes) ;
@@ -257,7 +275,11 @@
 
                         if (faultCode != null)
                         {
-                            faultMsg = SOAP_MESSAGE_FACTORY.createMessage() ;
+                            if (isSoap12) {
+                                faultMsg = SOAP_12_MESSAGE_FACTORY.createMessage();
+                            } else {
+                                faultMsg = SOAP_MESSAGE_FACTORY.createMessage();
+                            }
                             final SOAPFault fault = faultMsg.getSOAPBody().addFault(faultCode, faultDescription) ;
                             if (faultDetail != null)
                             {
@@ -276,14 +298,14 @@
                         else
                         {
                             final Throwable cause = fme.getCause() ;
-                            faultMsg = (cause != null) ? generateFault(cause) : generateFault(ex) ;
+                            faultMsg = (cause != null) ? generateFault(isSoap12, cause) : generateFault(isSoap12, ex) ;
                         }
                     }
                 }
 
                 if (faultMsg == null)
                 {
-                    faultMsg = generateFault(ex) ;
+                    faultMsg = generateFault(isSoap12, ex) ;
                 }
                 return faultMsg ;
             }
@@ -316,10 +338,15 @@
         }
     }
 
-    private SOAPMessage generateFault(final Throwable th)
+    private SOAPMessage generateFault(boolean isSoap12, final Throwable th)
         throws SOAPException
     {
-        final SOAPMessage faultMsg = SOAP_MESSAGE_FACTORY.createMessage() ;
+        SOAPMessage faultMsg = null;
+        if (isSoap12) {
+            faultMsg = SOAP_MESSAGE_FACTORY.createMessage() ;
+        } else {
+            faultMsg = SOAP_12_MESSAGE_FACTORY.createMessage();
+        }
         if (RETURN_STACK_TRACES)
         {
             final StringWriter sw = new StringWriter() ;
@@ -327,11 +354,20 @@
             th.printStackTrace(pw) ;
             pw.flush() ;
             pw.close() ;
-            faultMsg.getSOAPBody().addFault(SERVER_FAULT_QN, sw.toString());
+            if (isSoap12) {
+                faultMsg.getSOAPBody().addFault(SOAP_12_SERVER_FAULT_QN, sw.toString());
+                
+            } else {
+                faultMsg.getSOAPBody().addFault(SERVER_FAULT_QN, sw.toString());
+            }
         }
         else
         {
-            faultMsg.getSOAPBody().addFault(SERVER_FAULT_QN, th.getMessage());
+            if (isSoap12) {
+                faultMsg.getSOAPBody().addFault(SOAP_12_SERVER_FAULT_QN, th.getMessage());
+            } else {
+                faultMsg.getSOAPBody().addFault(SERVER_FAULT_QN, th.getMessage());                
+            }
         }
         return faultMsg ;
     }
@@ -376,14 +412,18 @@
         RETURN_STACK_TRACES = Boolean.parseBoolean(returnStackTraces) ;
         
         javax.xml.soap.MessageFactory soapMessageFactory = null ;
+        javax.xml.soap.MessageFactory soap12MessageFactory = null ;
+
         try
         {
             soapMessageFactory = javax.xml.soap.MessageFactory.newInstance() ;
+            soap12MessageFactory = javax.xml.soap.MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL) ;
         }
         catch (final SOAPException soape)
         {
             LOGGER.error("Could not instantiate SOAP Message Factory", soape) ;
         }
-        SOAP_MESSAGE_FACTORY = soapMessageFactory ;
+        SOAP_MESSAGE_FACTORY = soapMessageFactory;
+        SOAP_12_MESSAGE_FACTORY = soap12MessageFactory;
     }
 }

Modified: labs/jbossesb/tags/GSS-5.3.1-ONEOFF-1003/product/rosetta/src/org/jboss/soa/esb/services/security/auth/ws/SoapConstants.java
===================================================================
--- labs/jbossesb/tags/GSS-5.3.1-ONEOFF-1003/product/rosetta/src/org/jboss/soa/esb/services/security/auth/ws/SoapConstants.java	2013-09-20 02:39:42 UTC (rev 38417)
+++ labs/jbossesb/tags/GSS-5.3.1-ONEOFF-1003/product/rosetta/src/org/jboss/soa/esb/services/security/auth/ws/SoapConstants.java	2013-09-20 02:54:45 UTC (rev 38418)
@@ -35,9 +35,19 @@
     public static final QName SOAP_HEADER_QNAME = new QName("http://schemas.xmlsoap.org/soap/envelope/", "Header");
     
     /**
+     * Qname for SOAP 1.2 Header element.
+     */
+    public static final QName SOAP_12_HEADER_QNAME = new QName("http://www.w3.org/2003/05/soap-envelope", "Header");
+    
+    /**
      * QName for SOAP Body element.
      */
     public static final QName SOAP_BODY_QNAME = new QName("http://schemas.xmlsoap.org/soap/envelope/", "Body");
+
+    /**
+     * QName for SOAP 1.2 Body element. 
+     */
+    public static final QName SOAP_12_BODY_QNAME = new QName("http://www.w3.org/2003/05/soap-envelope", "Body");
     
     /**
      * Local name for Security header element.

Modified: labs/jbossesb/tags/GSS-5.3.1-ONEOFF-1003/product/rosetta/src/org/jboss/soa/esb/services/security/auth/ws/SoapExtractionUtil.java
===================================================================
--- labs/jbossesb/tags/GSS-5.3.1-ONEOFF-1003/product/rosetta/src/org/jboss/soa/esb/services/security/auth/ws/SoapExtractionUtil.java	2013-09-20 02:39:42 UTC (rev 38417)
+++ labs/jbossesb/tags/GSS-5.3.1-ONEOFF-1003/product/rosetta/src/org/jboss/soa/esb/services/security/auth/ws/SoapExtractionUtil.java	2013-09-20 02:54:45 UTC (rev 38418)
@@ -20,8 +20,13 @@
  */
 package org.jboss.soa.esb.services.security.auth.ws;
 import static org.jboss.soa.esb.services.security.auth.ws.SoapConstants.SOAP_HEADER_QNAME;
+import static org.jboss.soa.esb.services.security.auth.ws.SoapConstants.SOAP_12_HEADER_QNAME;
+
 import static org.jboss.soa.esb.services.security.auth.ws.SoapConstants.SOAP_BODY_QNAME;
+import static org.jboss.soa.esb.services.security.auth.ws.SoapConstants.SOAP_12_BODY_QNAME;
 
+
+import javax.xml.namespace.QName;
 import javax.xml.stream.events.EndElement;
 import javax.xml.stream.events.StartElement;
 import javax.xml.stream.events.XMLEvent;
@@ -35,22 +40,57 @@
  */
 public final class SoapExtractionUtil
 {
-    private SoapExtractionUtil()
+    
+   private SoapExtractionUtil()
     {
     }
-    
+
     public static boolean isStartOfHeader(final XMLEvent event)
     {
-        return event.isStartElement() && ((StartElement)event).getName().equals(SOAP_HEADER_QNAME);
+        if (event.isStartElement()) {
+            // SOAP 1.0 case
+            if (((StartElement)event).getName().equals(SOAP_HEADER_QNAME)) {
+                return true;      
+            // SOAP 1.2 case
+            } else if (((StartElement)event).getName().equals(SOAP_12_HEADER_QNAME)) {
+                return true;                
+            } else {
+                return false;
+            }              
+        }
+        return false;
     }
     
     public static boolean isEndOfHeader(final XMLEvent event)
     {
-        return event.isEndElement() && ((EndElement)event).getName().equals(SOAP_HEADER_QNAME);
+        if (event.isEndElement()) {
+            // SOAP 1.0 case
+            if (((EndElement)event).getName().equals(SOAP_HEADER_QNAME)) {
+                return true;      
+            // SOAP 1.2 case
+            } else if (((EndElement)event).getName().equals(SOAP_12_HEADER_QNAME)) {
+                return true;                
+            } else {
+                return false;
+            }              
+        }
+        return false;
     }
     
     public static boolean isStartOfBody(final XMLEvent event)
     {
-        return event.isStartElement() && ((StartElement)event).getName().equals(SOAP_BODY_QNAME);
+
+        if (event.isStartElement()) {
+            // SOAP 1.0 case
+            if (((StartElement)event).getName().equals(SOAP_12_BODY_QNAME)) {
+                return true;      
+            // SOAP 1.2 case
+            } else if (((StartElement)event).getName().equals(SOAP_12_BODY_QNAME)) {
+                return true;                
+            } else {
+                return false;
+            }              
+        }
+        return false;
     }
 }

Added: labs/jbossesb/tags/GSS-5.3.1-ONEOFF-1003/product/rosetta/tests/src/org/jboss/soa/esb/services/security/auth/ws/SOAP12UsernameTokenExtractorUnitTest.java
===================================================================
--- labs/jbossesb/tags/GSS-5.3.1-ONEOFF-1003/product/rosetta/tests/src/org/jboss/soa/esb/services/security/auth/ws/SOAP12UsernameTokenExtractorUnitTest.java	                        (rev 0)
+++ labs/jbossesb/tags/GSS-5.3.1-ONEOFF-1003/product/rosetta/tests/src/org/jboss/soa/esb/services/security/auth/ws/SOAP12UsernameTokenExtractorUnitTest.java	2013-09-20 02:54:45 UTC (rev 38418)
@@ -0,0 +1,39 @@
+package org.jboss.soa.esb.services.security.auth.ws;
+
+import static org.junit.Assert.*;
+
+import java.io.InputStream;
+
+import org.jboss.internal.soa.esb.util.StreamUtils;
+import org.jboss.soa.esb.services.security.auth.AuthenticationRequest;
+import org.jboss.soa.esb.services.security.auth.ws.UsernameTokenExtractor;
+import org.jboss.soa.esb.util.ClassUtil;
+import org.junit.Test;
+
+public class SOAP12UsernameTokenExtractorUnitTest {
+
+    @Test
+    public void ExtractSecurityInfoTest() throws Exception
+    {
+        final UsernameTokenExtractor  extractor = new UsernameTokenExtractor("http://schemas.xmlsoap.org/ws/2002/04/secext");
+
+        final String soap = createUserPassSoapString("soap1.2-sample.xml");
+        AuthenticationRequest authRequest = null;
+
+        authRequest = extractor.extractSecurityInfo(soap);
+
+        assertNotNull(authRequest);
+        assertEquals( "00067890", authRequest.getPrincipal().getName());
+    }
+
+    private String createUserPassSoapString(final String filename) throws Exception
+    {
+        return getStringFromFile(filename);
+    }
+    
+    private String getStringFromFile(final String fileName ) throws Exception
+    {
+        InputStream inputStream = ClassUtil.getResourceAsStream(fileName, getClass() );
+        return new String(StreamUtils.readStream(inputStream));
+    }
+}

Added: labs/jbossesb/tags/GSS-5.3.1-ONEOFF-1003/product/rosetta/tests/src/org/jboss/soa/esb/services/security/auth/ws/soap1.2-sample.xml
===================================================================
--- labs/jbossesb/tags/GSS-5.3.1-ONEOFF-1003/product/rosetta/tests/src/org/jboss/soa/esb/services/security/auth/ws/soap1.2-sample.xml	                        (rev 0)
+++ labs/jbossesb/tags/GSS-5.3.1-ONEOFF-1003/product/rosetta/tests/src/org/jboss/soa/esb/services/security/auth/ws/soap1.2-sample.xml	2013-09-20 02:54:45 UTC (rev 38418)
@@ -0,0 +1,17 @@
+<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"
+               xmlns:abs="http://ws.abs.allianz.at/header"
+               xmlns:sec="http://schemas.xmlsoap.org/ws/2002/04/secext">
+ <soap:Header>
+  <sec:Security>
+   <sec:UsernameToken>
+    <sec:Username>00067890</sec:Username>
+    <sec:Password>12121212</sec:Password>
+   </sec:UsernameToken>
+  </sec:Security>
+  <abs:ABSHeader >
+   <abs:WSContext webuser="25352123"/>
+  </abs:ABSHeader>
+ </soap:Header>
+ <soap:Body>
+ </soap:Body>
+</soap:Envelope> 
\ No newline at end of file

Added: labs/jbossesb/tags/GSS-5.3.1-ONEOFF-1003/product/rosetta/tests/src/org/jboss/soa/esb/services/security/auth/ws/xml.xsd
===================================================================
--- labs/jbossesb/tags/GSS-5.3.1-ONEOFF-1003/product/rosetta/tests/src/org/jboss/soa/esb/services/security/auth/ws/xml.xsd	                        (rev 0)
+++ labs/jbossesb/tags/GSS-5.3.1-ONEOFF-1003/product/rosetta/tests/src/org/jboss/soa/esb/services/security/auth/ws/xml.xsd	2013-09-20 02:54:45 UTC (rev 38418)
@@ -0,0 +1,18 @@
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://ws.abs.allianz.at/header" elementFormDefault="qualified">
+<xs:import namespace="http://www.w3.org/XML/1998/namespace" schemaLocation="http://www.w3.org/2001/xml.xsd"/>
+<!--  Sample header  -->
+<xs:element name="ABSHeader" type="ABSHeaderType"/>
+<xs:complexType name="ABSHeaderType">
+ <xs:sequence>
+  <xs:element ref="WSContextType" minOccurs="1"/>
+ </xs:sequence>
+</xs:complexType>
+<xs:element name="WSContext" type="WSContextType"/>
+<xs:complexType name="WSContextType">
+ <xs:simpleContent>
+  <xs:extension base="xs:string">
+  <xs:attribute name="webuser" type="xs:string" default="0"/>
+  </xs:extension>
+ </xs:simpleContent>
+</xs:complexType>
+</xs:schema>
\ No newline at end of file



More information about the jboss-svn-commits mailing list