[jbossws-commits] JBossWS SVN: r4392 - in stack/native/branches/native-2.0/src: test/java/org/jboss/test/ws/jaxws/samples/wssecurity and 1 other directories.

jbossws-commits at lists.jboss.org jbossws-commits at lists.jboss.org
Thu Aug 16 13:27:54 EDT 2007


Author: thomas.diesler at jboss.com
Date: 2007-08-16 13:27:54 -0400 (Thu, 16 Aug 2007)
New Revision: 4392

Modified:
   stack/native/branches/native-2.0/src/main/java/org/jboss/ws/extensions/security/WSSecurityDispatcher.java
   stack/native/branches/native-2.0/src/test/java/org/jboss/test/ws/jaxws/samples/wssecurity/SimpleUsernameTestCase.java
   stack/native/branches/native-2.0/src/test/java/org/jboss/test/ws/jaxws/samples/wssecurity/UsernameBean.java
   stack/native/branches/native-2.0/src/test/java/org/jboss/test/ws/jaxws/samples/wssecurity/UsernameEndpoint.java
   stack/native/branches/native-2.0/src/test/resources/jaxws/samples/wssecurity/simple-username/META-INF/wsdl/UsernameService.wsdl
Log:
[JBWS-1766] UsernameToken ignores BindingProvider.USERNAME_PROPERTY

Modified: stack/native/branches/native-2.0/src/main/java/org/jboss/ws/extensions/security/WSSecurityDispatcher.java
===================================================================
--- stack/native/branches/native-2.0/src/main/java/org/jboss/ws/extensions/security/WSSecurityDispatcher.java	2007-08-16 15:31:49 UTC (rev 4391)
+++ stack/native/branches/native-2.0/src/main/java/org/jboss/ws/extensions/security/WSSecurityDispatcher.java	2007-08-16 17:27:54 UTC (rev 4392)
@@ -31,6 +31,7 @@
 import javax.xml.rpc.soap.SOAPFaultException;
 import javax.xml.soap.SOAPException;
 import javax.xml.soap.SOAPHeader;
+import javax.xml.ws.BindingProvider;
 
 import org.jboss.logging.Logger;
 import org.jboss.ws.WSException;
@@ -252,6 +253,12 @@
       {
          Object user = ctx.get(Stub.USERNAME_PROPERTY);
          Object pass = ctx.get(Stub.PASSWORD_PROPERTY);
+         
+         if (user == null && pass == null)
+         {
+            user = ctx.get(BindingProvider.USERNAME_PROPERTY);
+            pass = ctx.get(BindingProvider.PASSWORD_PROPERTY);
+         }
 
          if (user != null && pass != null)
          {

Modified: stack/native/branches/native-2.0/src/test/java/org/jboss/test/ws/jaxws/samples/wssecurity/SimpleUsernameTestCase.java
===================================================================
--- stack/native/branches/native-2.0/src/test/java/org/jboss/test/ws/jaxws/samples/wssecurity/SimpleUsernameTestCase.java	2007-08-16 15:31:49 UTC (rev 4391)
+++ stack/native/branches/native-2.0/src/test/java/org/jboss/test/ws/jaxws/samples/wssecurity/SimpleUsernameTestCase.java	2007-08-16 17:27:54 UTC (rev 4392)
@@ -41,50 +41,55 @@
  * Test WS-Security for Username Token
  *
  * @author <a href="mailto:mageshbk at jboss.com">Magesh Kumar B</a>
+ * @author Thomas.Diesler at jboss.com
  * @since 15-Aug-2007
- * @version $Revision$
  */
 public class SimpleUsernameTestCase extends JBossWSTest
 {
-   /** Deploy the test */
+   private static UsernameEndpoint port; 
+   
    public static Test suite() throws Exception
    {
       return new JBossWSTestSetup(SimpleUsernameTestCase.class, "jaxws-samples-wssecurity-username.war");
    }
+   
+   @Override
+   protected void setUp() throws Exception
+   {
+      if (port == null)
+      {
+         URL wsdlURL = new File("resources/jaxws/samples/wssecurity/simple-username/META-INF/wsdl/UsernameService.wsdl").toURL();
+         URL securityURL = new File("resources/jaxws/samples/wssecurity/simple-username/META-INF/jboss-wsse-client.xml").toURL();
+         QName serviceName = new QName("http://org.jboss.ws/samples/wssecurity", "UsernameService");
 
-   /**
-    * Test SOAP Envelope for Username Token
-    */
-   public void testUsernameToken() throws Exception
+         Service service = Service.create(wsdlURL, serviceName);
+         
+         port = (UsernameEndpoint)service.getPort(UsernameEndpoint.class);
+         ((StubExt)port).setSecurityConfig(securityURL.toExternalForm());
+         ((StubExt)port).setConfigName("Standard WSSecurity Client");
+      }
+   }
+
+   public void testUsernameTokenNegative() throws Exception
    {
-      UsernameEndpoint username = getPort();
-      String retObj = username.getUsernameToken();
-      
-      System.out.println("FIXME [JBWS-1790]: UsernameToken is no longer present in Header after it is processed");
-      //assertTrue(retObj.indexOf("UsernameToken") > 0);
+      try
+      {
+         port.getUsernameToken();
+         fail("Server should respond with [401] - Unauthorized");
+      }
+      catch (Exception ex)
+      {
+         // this should be ok
+      }
    }
 
-   private UsernameEndpoint getPort() throws Exception
+   public void testUsernameToken() throws Exception
    {
-      URL wsdlURL = new File("resources/jaxws/samples/wssecurity/simple-username/META-INF/wsdl/UsernameService.wsdl").toURL();
-      URL securityURL = new File("resources/jaxws/samples/wssecurity/simple-username/META-INF/jboss-wsse-client.xml").toURL();
-      QName serviceName = new QName("http://org.jboss.ws/samples/wssecurity", "UsernameService");
-
-      Service service = Service.create(wsdlURL, serviceName);
-      
-      UsernameEndpoint port = (UsernameEndpoint)service.getPort(UsernameEndpoint.class);
-      ((StubExt)port).setSecurityConfig(securityURL.toExternalForm());
-      ((StubExt)port).setConfigName("Standard WSSecurity Client");
-
       Map<String, Object> reqContext = ((BindingProvider)port).getRequestContext();
-	   reqContext.put(BindingProvider.USERNAME_PROPERTY, "kermit");
+      reqContext.put(BindingProvider.USERNAME_PROPERTY, "kermit");
       reqContext.put(BindingProvider.PASSWORD_PROPERTY, "thefrog");
-      // If these below parameters are set it appears in the log, but the test fails as another
-      // request for the getHeader() returns empty <env:Header></env:Header>
-      //reqContext.put("javax.xml.rpc.security.auth.username", "kermit");
-      //reqContext.put("javax.xml.rpc.security.auth.password", "thefrog");
-      reqContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://" + getServerHost() + ":8080/jaxws-samples-wssecurity-username");
-
-      return port;
+      
+      String retObj = port.getUsernameToken();
+      assertEquals("kermit", retObj);
    }
 }
\ No newline at end of file

Modified: stack/native/branches/native-2.0/src/test/java/org/jboss/test/ws/jaxws/samples/wssecurity/UsernameBean.java
===================================================================
--- stack/native/branches/native-2.0/src/test/java/org/jboss/test/ws/jaxws/samples/wssecurity/UsernameBean.java	2007-08-16 15:31:49 UTC (rev 4391)
+++ stack/native/branches/native-2.0/src/test/java/org/jboss/test/ws/jaxws/samples/wssecurity/UsernameBean.java	2007-08-16 17:27:54 UTC (rev 4392)
@@ -21,41 +21,26 @@
  */
 package org.jboss.test.ws.jaxws.samples.wssecurity;
 
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.StringWriter;
-import java.util.Iterator;
+// $Id$
 
+import java.security.Principal;
+
 import javax.annotation.Resource;
 import javax.jws.WebMethod;
-import javax.jws.WebParam;
+import javax.jws.WebResult;
 import javax.jws.WebService;
 import javax.jws.soap.SOAPBinding;
-import javax.xml.namespace.QName;
-import javax.xml.soap.SOAPEnvelope;
-import javax.xml.soap.SOAPException;
-import javax.xml.soap.SOAPHeader;
-import javax.xml.soap.SOAPMessage;
-import javax.xml.soap.SOAPPart;
-import javax.xml.ws.handler.MessageContext;
-import javax.xml.ws.handler.soap.SOAPMessageContext;
 import javax.xml.ws.WebServiceContext;
 
 import org.jboss.logging.Logger;
 import org.jboss.ws.annotation.EndpointConfig;
-import org.jboss.ws.extensions.security.Constants;
-import org.jboss.ws.extensions.security.Util;
-import org.jboss.ws.core.soap.SOAPElementImpl;
-import org.jboss.ws.core.soap.SOAPEnvelopeImpl;
-import org.jboss.ws.core.soap.SOAPHeaderImpl;
-import org.w3c.dom.Element;
 
 /**
  * The SEI implementation used by the SimpleUsernameTestCase
  *
  * @author <a href="mailto:mageshbk at jboss.com">Magesh Kumar B</a>
+ * @author Thomas.Diesler at jboss.com
  * @since 15-Aug-2007
- * @version $Revision$ 
  */
 @WebService(name = "UsernameEndpoint", serviceName = "UsernameService", targetNamespace = "http://org.jboss.ws/samples/wssecurity")
 @EndpointConfig(configName = "Standard WSSecurity Endpoint")
@@ -63,46 +48,16 @@
 public class UsernameBean
 {
    private Logger log = Logger.getLogger(UsernameBean.class);
-   
+
    @Resource
    WebServiceContext wsCtx;
 
    @WebMethod
+   @WebResult(partName = "return")
    public String getUsernameToken()
    {
-      String retObj = "";
-      try
-      {       
-         MessageContext jaxwsContext = (MessageContext)wsCtx.getMessageContext();
-         SOAPMessage soapMessage = ((SOAPMessageContext)jaxwsContext).getMessage();
-         ByteArrayOutputStream stream = new ByteArrayOutputStream();
-         soapMessage.writeTo(stream);
-         log.info(stream.toString());
-         
-         SOAPPart soapPart = soapMessage.getSOAPPart();
-         SOAPEnvelope soapEnvelope = soapPart.getEnvelope();
-         StringWriter strw = new StringWriter();
-         ((SOAPEnvelopeImpl)soapEnvelope).writeElement(strw);
-         log.info(strw.toString());
-
-         SOAPHeader soapHeader = soapEnvelope.getHeader();
-         strw = new StringWriter();
-         ((SOAPHeaderImpl)soapHeader).writeElement(strw);
-         retObj = strw.toString();
-         log.info(retObj);
-
-         QName secQName = new QName(Constants.WSSE_NS, "Security");
-         Element secHeaderElement = Util.findElement(soapHeader, secQName);
-         log.info(secHeaderElement);
-      }
-      catch (SOAPException se)
-      {
-         log.error(se.getMessage());
-      }
-      catch (IOException ioe)
-      {
-         log.error(ioe.getMessage());
-      }
-      return retObj;
+      Principal principal = wsCtx.getUserPrincipal();
+      log.info("getUsernameToken: " + principal);
+      return principal.toString();
    }
 }

Modified: stack/native/branches/native-2.0/src/test/java/org/jboss/test/ws/jaxws/samples/wssecurity/UsernameEndpoint.java
===================================================================
--- stack/native/branches/native-2.0/src/test/java/org/jboss/test/ws/jaxws/samples/wssecurity/UsernameEndpoint.java	2007-08-16 15:31:49 UTC (rev 4391)
+++ stack/native/branches/native-2.0/src/test/java/org/jboss/test/ws/jaxws/samples/wssecurity/UsernameEndpoint.java	2007-08-16 17:27:54 UTC (rev 4392)
@@ -1,12 +1,30 @@
-
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
 package org.jboss.test.ws.jaxws.samples.wssecurity;
 
 import javax.jws.WebMethod;
-import javax.jws.WebParam;
 import javax.jws.WebResult;
 import javax.jws.WebService;
 import javax.jws.soap.SOAPBinding;
-import javax.jws.soap.SOAPBinding.Style;
 
 /**
  * The SEI
@@ -19,11 +37,6 @@
 @SOAPBinding(style = SOAPBinding.Style.RPC)
 public interface UsernameEndpoint {
 
-    /**
-     * 
-     * @return
-     *     returns java.lang.String
-     */
     @WebMethod
     @WebResult(partName = "return")
     public String getUsernameToken();

Modified: stack/native/branches/native-2.0/src/test/resources/jaxws/samples/wssecurity/simple-username/META-INF/wsdl/UsernameService.wsdl
===================================================================
--- stack/native/branches/native-2.0/src/test/resources/jaxws/samples/wssecurity/simple-username/META-INF/wsdl/UsernameService.wsdl	2007-08-16 15:31:49 UTC (rev 4391)
+++ stack/native/branches/native-2.0/src/test/resources/jaxws/samples/wssecurity/simple-username/META-INF/wsdl/UsernameService.wsdl	2007-08-16 17:27:54 UTC (rev 4392)
@@ -24,7 +24,7 @@
  </binding>
  <service name='UsernameService'>
   <port binding='tns:UsernameEndpointBinding' name='UsernameEndpointPort'>
-   <soap:address location='REPLACE_WITH_ACTUAL_URL'/>
+   <soap:address location='http://@jboss.bind.address@:8080/jaxws-samples-wssecurity-username'/>
   </port>
  </service>
 </definitions>
\ No newline at end of file




More information about the jbossws-commits mailing list