cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r504722 - in /incubator/cxf/trunk: api/src/main/java/org/apache/cxf/message/ rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/ rt/transports/http/src/main/java/org/apache/cxf/transport/http/ rt/transports/http/src/test/java/org/...
Date Wed, 07 Feb 2007 22:32:21 GMT
Author: dkulp
Date: Wed Feb  7 14:32:20 2007
New Revision: 504722

URL: http://svn.apache.org/viewvc?view=rev&rev=504722
Log:
Fix basic-auth

* Remove Message.USERNAME and Message.PASSWORD properties.   Authentication should be through
the AuthenticationPolicy object.
* Change JAX-WS frontend context mapping to map the JAX-WS properties to an AuthenticationPolicy
* Map server side AuthenticationPolicy to JAX-WS mapping


Modified:
    incubator/cxf/trunk/api/src/main/java/org/apache/cxf/message/Message.java
    incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/ContextPropertiesMapping.java
    incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java
    incubator/cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/http/HTTPConduitTest.java
    incubator/cxf/trunk/rt/transports/http2/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java
    incubator/cxf/trunk/rt/transports/http2/src/test/java/org/apache/cxf/transport/http/HTTPConduitTest.java
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/ClientServerTest.java
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/rm/SequenceTest.java
    incubator/cxf/trunk/testutils/src/main/java/org/apache/hello_world_soap_http/GreeterImpl.java

Modified: incubator/cxf/trunk/api/src/main/java/org/apache/cxf/message/Message.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/api/src/main/java/org/apache/cxf/message/Message.java?view=diff&rev=504722&r1=504721&r2=504722
==============================================================================
--- incubator/cxf/trunk/api/src/main/java/org/apache/cxf/message/Message.java (original)
+++ incubator/cxf/trunk/api/src/main/java/org/apache/cxf/message/Message.java Wed Feb  7 14:32:20
2007
@@ -43,8 +43,6 @@
     String DECOUPLED_CHANNEL_MESSAGE = "decoupled.channel.message";
     String PARTIAL_RESPONSE_MESSAGE = "org.apache.cxf.partial.response";
     
-    String USERNAME = Message.class.getName() + ".USERNAME";
-    String PASSWORD = Message.class.getName() + ".PASSWORD";
     String PROTOCOL_HEADERS = Message.class.getName() + ".PROTOCOL_HEADERS";
     String RESPONSE_CODE = Message.class.getName() + ".RESPONSE_CODE";
     String ENDPOINT_ADDRESS = Message.class.getName() + ".ENDPOINT_ADDRESS";

Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/ContextPropertiesMapping.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/ContextPropertiesMapping.java?view=diff&rev=504722&r1=504721&r2=504722
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/ContextPropertiesMapping.java
(original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/ContextPropertiesMapping.java
Wed Feb  7 14:32:20 2007
@@ -30,6 +30,7 @@
 import javax.xml.ws.BindingProvider;
 import javax.xml.ws.handler.MessageContext;
 
+import org.apache.cxf.configuration.security.AuthorizationPolicy;
 import org.apache.cxf.jaxws.context.WrappedMessageContext;
 import org.apache.cxf.message.Attachment;
 import org.apache.cxf.message.Exchange;
@@ -47,10 +48,6 @@
     static {
         cxf2jaxwsMap.put(Message.ENDPOINT_ADDRESS, 
                           BindingProvider.ENDPOINT_ADDRESS_PROPERTY);
-        cxf2jaxwsMap.put(Message.USERNAME,
-                          BindingProvider.USERNAME_PROPERTY);
-        cxf2jaxwsMap.put(Message.PASSWORD,
-                          BindingProvider.PASSWORD_PROPERTY);
         
         cxf2jaxwsMap.put(Message.HTTP_REQUEST_METHOD,
                           MessageContext.HTTP_REQUEST_METHOD);
@@ -63,10 +60,6 @@
         
         jaxws2cxfMap.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, 
                          Message.ENDPOINT_ADDRESS);
-        jaxws2cxfMap.put(BindingProvider.USERNAME_PROPERTY,
-                         Message.USERNAME);
-        jaxws2cxfMap.put(BindingProvider.PASSWORD_PROPERTY,
-                         Message.PASSWORD);
                 
         jaxws2cxfMap.put(MessageContext.HTTP_REQUEST_METHOD,
                          Message.HTTP_REQUEST_METHOD);
@@ -119,10 +112,23 @@
     
     private static void mapJaxws2Cxf(Map<String, Object> context) {
         mapContext(context, jaxws2cxfMap);
+        if (context.containsKey(BindingProvider.USERNAME_PROPERTY)) {
+            AuthorizationPolicy authPolicy = new AuthorizationPolicy();
+            authPolicy.setUserName((String)context.get(BindingProvider.USERNAME_PROPERTY));
+            authPolicy.setPassword((String)context.get(BindingProvider.PASSWORD_PROPERTY));
+            context.put(AuthorizationPolicy.class.getName(), authPolicy);
+        }
     }
         
     private static void mapCxf2Jaxws(Map<String, Object> context) {
         mapContext(context, cxf2jaxwsMap);
+        
+        if (context.containsKey(AuthorizationPolicy.class.getName())) {
+            AuthorizationPolicy authPolicy =
+                (AuthorizationPolicy)context.get(AuthorizationPolicy.class.getName());
+            context.put(BindingProvider.USERNAME_PROPERTY, authPolicy.getUserName());
+            context.put(BindingProvider.PASSWORD_PROPERTY, authPolicy.getPassword());
+        }
     }
     
     

Modified: incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java?view=diff&rev=504722&r1=504721&r2=504722
==============================================================================
--- incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java
(original)
+++ incubator/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java
Wed Feb  7 14:32:20 2007
@@ -445,9 +445,9 @@
     private void setPolicies(Message message, Map<String, List<String>> headers)
{
         AuthorizationPolicy authPolicy = getAuthorization();
         AuthorizationPolicy newPolicy = message.get(AuthorizationPolicy.class);
-        String userName = (String)message.get(Message.USERNAME);
-        String passwd = (String)message.get(Message.PASSWORD);
-        if (null != newPolicy && null != userName) {
+        String userName = null;
+        String passwd = null;
+        if (null != newPolicy) {
             userName = newPolicy.getUserName();
             passwd = newPolicy.getPassword();
         }

Modified: incubator/cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/http/HTTPConduitTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/http/HTTPConduitTest.java?view=diff&rev=504722&r1=504721&r2=504722
==============================================================================
--- incubator/cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/http/HTTPConduitTest.java
(original)
+++ incubator/cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/http/HTTPConduitTest.java
Wed Feb  7 14:32:20 2007
@@ -36,6 +36,7 @@
 import junit.framework.TestCase;
 
 import org.apache.cxf.bus.CXFBusImpl;
+import org.apache.cxf.configuration.security.AuthorizationPolicy;
 import org.apache.cxf.helpers.CastUtils;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.message.MessageImpl;
@@ -139,8 +140,11 @@
         contentTypes.add("charset=utf8");
         headers.put("content-type", contentTypes);
         message.put(Message.PROTOCOL_HEADERS, headers);        
-        message.put(Message.USERNAME, "BJ");
-        message.put(Message.PASSWORD, "value");
+        
+        AuthorizationPolicy authPolicy = new AuthorizationPolicy();
+        authPolicy.setUserName("BJ");
+        authPolicy.setPassword("value");
+        message.put(AuthorizationPolicy.class, authPolicy);        
     }
 
     private HTTPConduit setUpConduit(boolean send) throws Exception {

Modified: incubator/cxf/trunk/rt/transports/http2/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/transports/http2/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java?view=diff&rev=504722&r1=504721&r2=504722
==============================================================================
--- incubator/cxf/trunk/rt/transports/http2/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java
(original)
+++ incubator/cxf/trunk/rt/transports/http2/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java
Wed Feb  7 14:32:20 2007
@@ -445,9 +445,9 @@
     private void setPolicies(Message message, Map<String, List<String>> headers)
{
         AuthorizationPolicy authPolicy = config.getAuthorization();
         AuthorizationPolicy newPolicy = message.get(AuthorizationPolicy.class);
-        String userName = (String)message.get(Message.USERNAME);
-        String passwd = (String)message.get(Message.PASSWORD);
-        if (null != newPolicy && null != userName) {
+        String userName = null;
+        String passwd = null;
+        if (null != newPolicy) {
             userName = newPolicy.getUserName();
             passwd = newPolicy.getPassword();
         }

Modified: incubator/cxf/trunk/rt/transports/http2/src/test/java/org/apache/cxf/transport/http/HTTPConduitTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/transports/http2/src/test/java/org/apache/cxf/transport/http/HTTPConduitTest.java?view=diff&rev=504722&r1=504721&r2=504722
==============================================================================
--- incubator/cxf/trunk/rt/transports/http2/src/test/java/org/apache/cxf/transport/http/HTTPConduitTest.java
(original)
+++ incubator/cxf/trunk/rt/transports/http2/src/test/java/org/apache/cxf/transport/http/HTTPConduitTest.java
Wed Feb  7 14:32:20 2007
@@ -39,6 +39,7 @@
 import junit.framework.TestCase;
 
 import org.apache.cxf.bus.CXFBusImpl;
+import org.apache.cxf.configuration.security.AuthorizationPolicy;
 import org.apache.cxf.helpers.CastUtils;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.message.MessageImpl;
@@ -142,9 +143,13 @@
         contentTypes.add("text/xml");
         contentTypes.add("charset=utf8");
         headers.put("content-type", contentTypes);
-        message.put(Message.PROTOCOL_HEADERS, headers);        
-        message.put(Message.USERNAME, "BJ");
-        message.put(Message.PASSWORD, "value");
+        message.put(Message.PROTOCOL_HEADERS, headers);
+        
+        
+        AuthorizationPolicy authPolicy = new AuthorizationPolicy();
+        authPolicy.setUserName("BJ");
+        authPolicy.setPassword("value");
+        message.put(AuthorizationPolicy.class, authPolicy);        
     }
 
     private HTTPConduit setUpConduit(boolean send) throws Exception {

Modified: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/ClientServerTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/ClientServerTest.java?view=diff&rev=504722&r1=504721&r2=504722
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/ClientServerTest.java
(original)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/ClientServerTest.java
Wed Feb  7 14:32:20 2007
@@ -81,7 +81,7 @@
         TestSuite suite = new TestSuite(ClientServerTest.class);
         return new ClientServerSetupBase(suite) {
                 public void startServers() throws Exception {                    
-                    assertTrue("server did not launch correctly", launchServer(Server.class));
+                    assertTrue("server did not launch correctly", launchServer(Server.class,
true));
                 }
                 public void setUp() throws Exception {
                     // set up configuration to enable schema validation
@@ -93,7 +93,6 @@
             };
     }
 
-    
     public void testBasicConnection() throws Exception {
 
         SOAPService service = new SOAPService();
@@ -631,7 +630,24 @@
                                                body, 
                                                XPathConstants.STRING);
         assertEquals("Hello cxf (was CeltixFire)", response);
-    }    
+    }
+    
+    public void testBasicAuth() throws Exception {
+        Service service = Service.create(serviceName);
+        service.addPort(fakePortName, "http://schemas.xmlsoap.org/soap/", 
+                        "http://localhost:9000/SoapContext/SoapPort");
+        Greeter greeter = service.getPort(fakePortName, Greeter.class);
+
+        try {
+            BindingProvider bp = (BindingProvider)greeter;
+            bp.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, "BJ");
+            bp.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, "pswd");
+            String s = greeter.greetMe("secure");
+            assertEquals("Hello BJ", s);
+        } catch (UndeclaredThrowableException ex) {
+            throw (Exception)ex.getCause();
+        }
+    }
     
     public static void main(String[] args) {
         junit.textui.TestRunner.run(ClientServerTest.class);

Modified: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/rm/SequenceTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/rm/SequenceTest.java?view=diff&rev=504722&r1=504721&r2=504722
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/rm/SequenceTest.java
(original)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/rm/SequenceTest.java
Wed Feb  7 14:32:20 2007
@@ -820,7 +820,6 @@
     }
 
     private void removeRMInterceptors(List<Interceptor> interceptors) {
-        int n = interceptors.size();
         for (Iterator<Interceptor> it = interceptors.iterator(); it.hasNext();) {
             Interceptor i = it.next();
             if (i instanceof RMSoapInterceptor

Modified: incubator/cxf/trunk/testutils/src/main/java/org/apache/hello_world_soap_http/GreeterImpl.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/testutils/src/main/java/org/apache/hello_world_soap_http/GreeterImpl.java?view=diff&rev=504722&r1=504721&r2=504722
==============================================================================
--- incubator/cxf/trunk/testutils/src/main/java/org/apache/hello_world_soap_http/GreeterImpl.java
(original)
+++ incubator/cxf/trunk/testutils/src/main/java/org/apache/hello_world_soap_http/GreeterImpl.java
Wed Feb  7 14:32:20 2007
@@ -28,8 +28,10 @@
 
 import javax.jws.WebService;
 import javax.xml.ws.AsyncHandler;
+import javax.xml.ws.BindingProvider;
 import javax.xml.ws.Response;
 import javax.xml.ws.WebServiceContext;
+import javax.xml.ws.handler.MessageContext;
 
 import org.apache.hello_world_soap_http.types.BareDocumentResponse;
 import org.apache.hello_world_soap_http.types.ErrorCode;
@@ -58,6 +60,12 @@
     }
 
     public String greetMe(String me) {
+        if ("secure".equals(me)) {
+            MessageContext ctx = context.getMessageContext();
+            return "Hello " + ctx.get(BindingProvider.USERNAME_PROPERTY);
+        }
+        
+        
         LOG.info("Invoking greetMe " + me);
         invocationCount++;
         return "Hello " + me;



Mime
View raw message