You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by ng...@apache.org on 2006/10/17 07:53:15 UTC

svn commit: r464822 - in /webservices/axis2/trunk/java/modules/jaxws: ./ src/org/apache/axis2/jaxws/core/controller/ src/org/apache/axis2/jaxws/i18n/ test/org/apache/axis2/jaxws/framework/ test/org/apache/axis2/jaxws/security/ test/org/apache/axis2/jax...

Author: ngallardo
Date: Mon Oct 16 22:53:13 2006
New Revision: 464822

URL: http://svn.apache.org/viewvc?view=rev&rev=464822
Log:
AXIS2-1318
Contributor: Samuel Isokpunwu

Add checking to the client side to configure Basic Auth properties.

Added:
    webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/security/
    webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/security/BasicAuthSecurityTests.java
    webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/security/server/
    webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/security/server/META-INF/
    webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/security/server/META-INF/MANIFEST.MF
    webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/security/server/META-INF/services.xml
    webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/security/server/SecurityProvider.java
Modified:
    webservices/axis2/trunk/java/modules/jaxws/maven.xml
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/core/controller/AxisInvocationController.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/i18n/resource.properties
    webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/framework/JAXWSTest.java

Modified: webservices/axis2/trunk/java/modules/jaxws/maven.xml
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/maven.xml?view=diff&rev=464822&r1=464821&r2=464822
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/maven.xml (original)
+++ webservices/axis2/trunk/java/modules/jaxws/maven.xml Mon Oct 16 22:53:13 2006
@@ -79,12 +79,12 @@
 			<arg line="-d ${schema.generated.src.dir} -quiet -wsdl ${wsdl.source.dir}/ProxyDocLitnonWrapped.wsdl"/>
 		</java>
     	<ant:echo>Generating java from AddNumbers.wsdl</ant:echo>
-    	    	    	<java classname="com.sun.tools.xjc.Driver" fork="true"> 
-    	    	    		<jvmarg line="${maven.junit.jvmargs}"/>
-    	    	    	    <classpath refid="maven.dependency.classpath"/>
-    	    	    	    <classpath location="${compiled.classes.dir}"/>
-    	   	    	    	<arg line="-d ${schema.generated.src.dir} -quiet -wsdl ${wsdl.source.dir}/AddNumbers.wsdl"/>
-    	     	    	</java>
+    	<java classname="com.sun.tools.xjc.Driver" fork="true"> 
+    	    <jvmarg line="${maven.junit.jvmargs}"/>
+    	    <classpath refid="maven.dependency.classpath"/>
+    	    <classpath location="${compiled.classes.dir}"/>
+    	   	<arg line="-d ${schema.generated.src.dir} -quiet -wsdl ${wsdl.source.dir}/AddNumbers.wsdl"/>
+    	</java>
     	<ant:echo>Generating java from jaxbsource</ant:echo>
     	<java classname="com.sun.tools.xjc.Driver" fork="true"> 
     	    <jvmarg line="${maven.junit.jvmargs}"/>
@@ -144,6 +144,17 @@
         <!-- ================================================================ -->
         <!--- Provider endpoint Service Samples -->
         <!-- ================================================================ -->
+		<ant:copy toDir="target/test-classes/services/BasicAuthSecurityService/">
+			<ant:fileset dir="target/test-classes">
+				<ant:include name="org/apache/axis2/jaxws/security/server/**"/>
+			</ant:fileset>
+			<ant:fileset dir="test/org/apache/axis2/jaxws/security/server">
+				<ant:include name="META-INF/**"/>
+			</ant:fileset>
+			<ant:fileset dir="target/classes">
+    			<ant:include name="org/apache/axis2/jaxws/server/**"/>
+			</ant:fileset>
+		</ant:copy>
 		<ant:copy toDir="target/test-classes/services/StringProviderService/">
 			<ant:fileset dir="target/test-classes">
 				<ant:include name="org/apache/axis2/jaxws/provider/string/**"/>

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/core/controller/AxisInvocationController.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/core/controller/AxisInvocationController.java?view=diff&rev=464822&r1=464821&r2=464822
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/core/controller/AxisInvocationController.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/core/controller/AxisInvocationController.java Mon Oct 16 22:53:13 2006
@@ -16,6 +16,8 @@
  */
 package org.apache.axis2.jaxws.core.controller;
 
+import java.net.MalformedURLException;
+import java.net.URL;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.Map;
@@ -61,6 +63,8 @@
 import org.apache.axis2.jaxws.message.impl.AttachmentImpl;
 import org.apache.axis2.jaxws.registry.FactoryRegistry;
 import org.apache.axis2.jaxws.util.Constants;
+import org.apache.axis2.transport.http.HTTPConstants;
+import org.apache.axis2.transport.http.HttpTransportProperties;
 import org.apache.axis2.util.CallbackReceiver;
 import org.apache.axis2.util.ThreadContextMigratorUtil;
 import org.apache.axis2.wsdl.WSDLConstants;
@@ -504,6 +508,44 @@
         Message msg = mc.getMessage();
         if (msg.isMTOMEnabled()) {
             ops.setProperty(Configuration.ENABLE_MTOM, "true");
+        }
+        
+        // Check to see if BASIC_AUTH is enabled.  If so, make sure
+        // the properties are setup correctly.
+        if (properties.containsKey(BindingProvider.USERNAME_PROPERTY) &&
+            properties.containsKey(BindingProvider.PASSWORD_PROPERTY)) {
+       
+            String userId = (String) properties.get(BindingProvider.USERNAME_PROPERTY);
+            if (userId == null || userId == "") {
+                throw ExceptionFactory.makeWebServiceException(Messages.getMessage("checkUserName"));
+            }
+   
+            String password = (String)properties.get(BindingProvider.PASSWORD_PROPERTY);
+            if (password == null || password == "") {
+                throw ExceptionFactory.makeWebServiceException(Messages.getMessage("checkPassword"));
+            }
+       
+            URL url = null;
+            try {
+                url = new URL((String)mc.getProperties().get(BindingProvider.ENDPOINT_ADDRESS_PROPERTY));
+            }
+            catch (MalformedURLException e) {
+                throw ExceptionFactory.makeWebServiceException(e);
+            }
+                
+            HttpTransportProperties.Authenticator basicAuthentication = new HttpTransportProperties.Authenticator();
+            basicAuthentication.setUsername(userId);
+            basicAuthentication.setPassword(password);
+            basicAuthentication.setHost(url.getHost());
+            basicAuthentication.setPort(url.getPort());
+       
+            ops.setProperty(HTTPConstants.AUTHENTICATE, basicAuthentication);
+        }
+        else if((!properties.containsKey(BindingProvider.USERNAME_PROPERTY) &&
+            properties.containsKey(BindingProvider.PASSWORD_PROPERTY)) || 
+            (properties.containsKey(BindingProvider.USERNAME_PROPERTY) &&
+            !properties.containsKey(BindingProvider.PASSWORD_PROPERTY))){
+            throw ExceptionFactory.makeWebServiceException(Messages.getMessage("checkUsernameAndPassword"));
         }
     }
     

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/i18n/resource.properties
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/i18n/resource.properties?view=diff&rev=464822&r1=464821&r2=464822
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/i18n/resource.properties (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/i18n/resource.properties Mon Oct 16 22:53:13 2006
@@ -112,3 +112,6 @@
 dispatchNullParamHttpBinding=The parameter cannot be null for a Dispatch invocation using the XML/HTTP Binding.
 dispatchInvalidParam=The parameter for the Dispatch invocation was invalid.
 prepareRequestFail=An error occurred while preparing the request message.
+validateUserName=Error: A value must be specified when setting the property javax.xml.ws.security.auth.username.
+validatePassword=Error: A value must be specified when setting the property javax.xml.ws.security.auth.password.
+checkUsernameAndPassword=Error: A username (javax.xml.ws.security.auth.username) and a password (javax.xml.ws.security.auth.password) must be specified.

Modified: webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/framework/JAXWSTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/framework/JAXWSTest.java?view=diff&rev=464822&r1=464821&r2=464822
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/framework/JAXWSTest.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/framework/JAXWSTest.java Mon Oct 16 22:53:13 2006
@@ -48,6 +48,7 @@
 import org.apache.axis2.jaxws.sample.MtomSampleTests;
 import org.apache.axis2.jaxws.sample.NonWrapTests;
 import org.apache.axis2.jaxws.sample.WrapTests;
+import org.apache.axis2.jaxws.security.BasicAuthSecurityTests;
 import org.apache.axis2.proxy.ProxyNonWrappedTests;
 import org.apache.axis2.proxy.ProxyTests;
 
@@ -91,6 +92,7 @@
         suite.addTestSuite(ProxyTests.class);
         suite.addTestSuite(ProxyNonWrappedTests.class);
         suite.addTestSuite(ExceptionFactoryTests.class);
+        suite.addTestSuite(BasicAuthSecurityTests.class);
 
         suite.addTestSuite(AddressBookTests.class);
         suite.addTestSuite(MtomSampleTests.class);

Added: webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/security/BasicAuthSecurityTests.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/security/BasicAuthSecurityTests.java?view=auto&rev=464822
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/security/BasicAuthSecurityTests.java (added)
+++ webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/security/BasicAuthSecurityTests.java Mon Oct 16 22:53:13 2006
@@ -0,0 +1,148 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ * Copyright 2006 International Business Machines Corp.
+ *
+ * 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.axis2.jaxws.security;
+
+import javax.xml.namespace.QName;
+import javax.xml.ws.Dispatch;
+import javax.xml.ws.Service;
+import javax.xml.ws.WebServiceException;
+import javax.xml.ws.soap.SOAPBinding;
+
+import org.apache.axis2.jaxws.BindingProvider;
+
+import junit.framework.TestCase;
+
+public class BasicAuthSecurityTests extends TestCase {
+
+    private String endpointUrl = "http://localhost:8080/axis2/services/BasicAuthSecurityService";
+    private String xmlString = "<invoke>test input</invoke>";
+    private QName SERVICE_QNAME = new QName("http://ws.apache.org/axis2", "BasicAuthSecurityService");
+    private QName PORT_QNAME = new QName("http://ws.apache.org/axis2", "SimpleProviderServiceSOAP11port0");
+
+	private String USER_ID = "testid";
+	private String PASSWORD = "testid";
+
+    protected void setUp() throws Exception {
+            super.setUp();
+    }
+
+    protected void tearDown() throws Exception {
+            super.tearDown();
+    }
+
+    public BasicAuthSecurityTests(String name) {
+        super(name);
+    }
+    
+    public void testBasicAuth() throws Exception {
+        System.out.println("---------------------------------------");
+        System.out.println("test: " + getName());
+        
+        Dispatch<String> dispatch = getDispatch(Service.Mode.PAYLOAD,
+        		                                endpointUrl,
+        		                                SOAPBinding.SOAP11HTTP_BINDING);
+        
+        System.out.println(">> Invoking Dispatch<String> BasicAuthSecurityService");
+        String retVal = dispatch.invoke(xmlString);
+        System.out.println(">> Response [" + retVal + "]");
+    }
+    
+    public void testBasicAuth_uid_pwd() throws Exception {
+        System.out.println("---------------------------------------");
+        System.out.println("test: " + getName());
+        
+        Dispatch<String> dispatch = getDispatch(Service.Mode.PAYLOAD,
+        		                                endpointUrl,
+        		                                SOAPBinding.SOAP11HTTP_BINDING);
+        
+        dispatch.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, USER_ID);
+		dispatch.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, PASSWORD);
+
+        System.out.println(">> Invoking Dispatch<String> BasicAuthSecurityService");
+        String retVal = dispatch.invoke(xmlString);
+        System.out.println(">> Response [" + retVal + "]");
+    }
+    
+    public void testBasicAuth_uid()throws Exception{
+        System.out.println("---------------------------------------");
+        System.out.println("test: " + getName());
+        
+        Dispatch<String> dispatch = getDispatch(Service.Mode.PAYLOAD,
+        		                                endpointUrl,
+        		                                SOAPBinding.SOAP11HTTP_BINDING);
+        
+        dispatch.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, USER_ID);
+
+        System.out.println(">> Invoking Dispatch<String> BasicAuthSecurityService");
+        
+        try{
+        	String retVal = dispatch.invoke(xmlString);
+            System.out.println(">> Response [" + retVal + "]");
+            
+            fail("Set USERID with no PASSWORD: WebServiceException is expected");
+        }
+        catch(WebServiceException wse){
+        	System.out.println(getName()+": "+ wse);
+        }
+    }
+    
+    public void testBasicAuth_pwd()throws Exception{
+        System.out.println("---------------------------------------");
+        System.out.println("test: " + getName());
+        
+        Dispatch<String> dispatch = getDispatch(Service.Mode.PAYLOAD,
+        		                                endpointUrl,
+        		                                SOAPBinding.SOAP11HTTP_BINDING);
+        
+		dispatch.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, PASSWORD);
+
+        System.out.println(">> Invoking Dispatch<String> BasicAuthSecurityService");
+        
+        try{
+        	String retVal = dispatch.invoke(xmlString);
+            System.out.println(">> Response [" + retVal + "]");
+            
+            fail("Set PASSWORD with no USERID: WebServiceException is expected");
+        }
+        catch(WebServiceException wse){
+        	System.out.println(getName()+": "+ wse);
+        }
+    }
+    
+	/**
+	 * Auxiliary method, generates a Dispatch object on demand
+	 * 
+	 * @param mode
+	 *            Service.Mode
+	 * @param endpoint
+	 *            endpoint address
+	 * @param binding
+	 *            binding type
+	 * @return
+	 */
+	private Dispatch<String> getDispatch(Service.Mode mode, String endpoint,String binding) {
+		
+		Service service = Service.create(SERVICE_QNAME);
+		
+		service.addPort(PORT_QNAME, binding, endpoint);
+		javax.xml.ws.Dispatch<String> dispatch = service.createDispatch(PORT_QNAME, String.class,mode);
+
+		assertNotNull("Dispatch not null", dispatch);
+
+		return dispatch;
+	}
+}

Added: webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/security/server/META-INF/MANIFEST.MF
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/security/server/META-INF/MANIFEST.MF?view=auto&rev=464822
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/security/server/META-INF/MANIFEST.MF (added)
+++ webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/security/server/META-INF/MANIFEST.MF Mon Oct 16 22:53:13 2006
@@ -0,0 +1 @@
+Manifest-Version: 1.0

Added: webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/security/server/META-INF/services.xml
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/security/server/META-INF/services.xml?view=auto&rev=464822
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/security/server/META-INF/services.xml (added)
+++ webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/security/server/META-INF/services.xml Mon Oct 16 22:53:13 2006
@@ -0,0 +1,12 @@
+<serviceGroup>
+ <service name="BasicAuthSecurityService">
+  <messageReceivers>
+   <messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-out" class="org.apache.axis2.jaxws.server.JAXWSMessageReceiver"/>
+  </messageReceivers>
+  <parameter locked="false" name="ServiceClass">org.apache.axis2.jaxws.security.server.SecurityProvider</parameter>
+  <operation name="invoke" mep="http://www.w3.org/2004/08/wsdl/in-out">
+    <actionMapping/>
+  </operation>
+ </service>
+</serviceGroup>
+

Added: webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/security/server/SecurityProvider.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/security/server/SecurityProvider.java?view=auto&rev=464822
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/security/server/SecurityProvider.java (added)
+++ webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/security/server/SecurityProvider.java Mon Oct 16 22:53:13 2006
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ * Copyright 2006 International Business Machines Corp.
+ *
+ * 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.axis2.jaxws.security.server;
+
+import javax.xml.ws.Provider;
+import javax.xml.ws.WebServiceProvider;
+
+@WebServiceProvider()
+public class SecurityProvider implements Provider<String> {
+
+    private static String responseGood = "<provider><message>request processed</message></provider>";
+    private static String responseBad  = "<provider><message>ERROR:null request received</message><provider>";
+    
+    public String invoke(String obj) {
+        if (obj != null) {
+            String str = (String) obj;
+            System.out.println(">> StringProvider received a new request");
+            System.out.println(">> request [" + str + "]");
+            
+            return responseGood;
+        }
+        System.out.println(">> ERROR:null request received");
+        return responseBad;
+    }
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org