You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by re...@apache.org on 2020/06/28 17:31:18 UTC

[cxf] branch 3.3.x-fixes updated (ef67a7f -> 066e10a)

This is an automated email from the ASF dual-hosted git repository.

reta pushed a change to branch 3.3.x-fixes
in repository https://gitbox.apache.org/repos/asf/cxf.git.


    from ef67a7f  Updating project-reactor to 3.2.18.RELEASE
     new 1c67d06  Adding JAX-WS integration test for DefaultBasicAuthSupplier
     new 066e10a  Recording .gitmergeinfo Changes

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .gitmergeinfo                                      |  1 +
 .../cxf/systest/jaxws/JaxwsAsyncFailOverTest.java  |  6 ++
 ...ncFailOverTest.java => JaxwsBasicAuthTest.java} | 86 ++++++++++++++--------
 3 files changed, 64 insertions(+), 29 deletions(-)
 copy systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/{JaxwsAsyncFailOverTest.java => JaxwsBasicAuthTest.java} (52%)


[cxf] 02/02: Recording .gitmergeinfo Changes

Posted by re...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

reta pushed a commit to branch 3.3.x-fixes
in repository https://gitbox.apache.org/repos/asf/cxf.git

commit 066e10a27577e1d557e18159a7401e2f5753d842
Author: reta <dr...@gmail.com>
AuthorDate: Sun Jun 28 12:13:47 2020 -0400

    Recording .gitmergeinfo Changes
---
 .gitmergeinfo | 1 +
 1 file changed, 1 insertion(+)

diff --git a/.gitmergeinfo b/.gitmergeinfo
index 4b23692..baca2a6 100644
--- a/.gitmergeinfo
+++ b/.gitmergeinfo
@@ -325,6 +325,7 @@ M 7971b506283502c26aafb97c0f6e50633f126cdd
 M 7a655b49fd6d432127a55b38f15c1212f7064196
 M 7aa6e0a402b8ce7dfff8a931a507b884d7152cea
 M 7b50181ebc445bb84d3463b284643432399bc0f8
+M 7e1bc67acf02fe6049a4bfb7e13fe6933e618ae8
 M 7ef814556d727c147d6f625cbb1170edfd24a752
 M 7f733555945f1faed66b0b6163d24889d4cf60fc
 M 83c9d2701fbf4ed54bd704ca7c4cf67f57e1048d


[cxf] 01/02: Adding JAX-WS integration test for DefaultBasicAuthSupplier

Posted by re...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

reta pushed a commit to branch 3.3.x-fixes
in repository https://gitbox.apache.org/repos/asf/cxf.git

commit 1c67d067ec967b907f56e1c5e0c268dc73452300
Author: reta <dr...@gmail.com>
AuthorDate: Sun Jun 28 11:35:28 2020 -0400

    Adding JAX-WS integration test for DefaultBasicAuthSupplier
    
    (cherry picked from commit 7a13bfff60babe60ebfcdb45b5838eee6947e191)
---
 .../cxf/systest/jaxws/JaxwsAsyncFailOverTest.java  |  6 ++
 ...ncFailOverTest.java => JaxwsBasicAuthTest.java} | 86 ++++++++++++++--------
 2 files changed, 63 insertions(+), 29 deletions(-)

diff --git a/systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/JaxwsAsyncFailOverTest.java b/systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/JaxwsAsyncFailOverTest.java
index 70dc8c8..df8e9d5 100644
--- a/systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/JaxwsAsyncFailOverTest.java
+++ b/systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/JaxwsAsyncFailOverTest.java
@@ -34,6 +34,7 @@ import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
 import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
 import org.apache.cxf.testutil.common.AbstractBusTestServerBase;
 
+import org.junit.AfterClass;
 import org.junit.BeforeClass;
 import org.junit.Test;
 
@@ -79,6 +80,11 @@ public class JaxwsAsyncFailOverTest  extends AbstractBusClientServerTestBase {
         assertTrue("server did not launch correctly", launchServer(Server.class, true));
     }
 
+    @AfterClass
+    public static void stopServers() throws Exception {
+        stopAllServers();
+    }
+
     @Test
     public void testUseFailOverOnClient() throws Exception {
         List<String> serviceList = new ArrayList<>();
diff --git a/systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/JaxwsAsyncFailOverTest.java b/systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/JaxwsBasicAuthTest.java
similarity index 52%
copy from systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/JaxwsAsyncFailOverTest.java
copy to systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/JaxwsBasicAuthTest.java
index 70dc8c8..0a24474 100644
--- a/systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/JaxwsAsyncFailOverTest.java
+++ b/systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/JaxwsBasicAuthTest.java
@@ -19,29 +19,37 @@
 
 package org.apache.cxf.systest.jaxws;
 
-import java.util.ArrayList;
 import java.util.List;
+import java.util.Map;
 
+import javax.annotation.Resource;
 import javax.jws.WebService;
-import javax.xml.ws.Response;
+import javax.xml.ws.BindingProvider;
+import javax.xml.ws.WebServiceContext;
+import javax.xml.ws.WebServiceException;
+import javax.xml.ws.handler.MessageContext;
 
-import org.apache.cxf.clustering.FailoverFeature;
-import org.apache.cxf.clustering.RandomStrategy;
+import org.apache.cxf.endpoint.Client;
+import org.apache.cxf.frontend.ClientProxy;
 import org.apache.cxf.greeter_control.AbstractGreeterImpl;
 import org.apache.cxf.greeter_control.Greeter;
-import org.apache.cxf.greeter_control.types.GreetMeResponse;
+import org.apache.cxf.helpers.CastUtils;
 import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
 import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
 import org.apache.cxf.testutil.common.AbstractBusTestServerBase;
+import org.apache.cxf.transport.http.HTTPConduit;
+import org.apache.cxf.transport.http.auth.DefaultBasicAuthSupplier;
 
+import org.junit.AfterClass;
 import org.junit.BeforeClass;
 import org.junit.Test;
 
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.junit.Assert.assertThat;
 import static org.junit.Assert.assertTrue;
 
-public class JaxwsAsyncFailOverTest  extends AbstractBusClientServerTestBase {
-    static final String PORT = allocatePort(ServerNoBodyParts.class, 1);
-    static final String PORT2 = allocatePort(ServerNoBodyParts.class, 2);
+public class JaxwsBasicAuthTest extends AbstractBusClientServerTestBase {
+    static final String PORT = allocatePort(JaxwsBasicAuthTest.class);
 
     public static class Server extends AbstractBusTestServerBase {
 
@@ -64,12 +72,34 @@ public class JaxwsAsyncFailOverTest  extends AbstractBusClientServerTestBase {
             }
         }
 
-        @WebService(serviceName = "BasicGreeterService",
+        @WebService(serviceName = "ProtectedGreeterService",
                     portName = "GreeterPort",
                     endpointInterface = "org.apache.cxf.greeter_control.Greeter",
                     targetNamespace = "http://cxf.apache.org/greeter_control",
                     wsdlLocation = "testutils/greeter_control.wsdl")
         public class GreeterImpl extends AbstractGreeterImpl {
+            @Resource private WebServiceContext context;
+            
+            @Override
+            public String greetMe(String arg) {
+                final MessageContext messageContext = context.getMessageContext();
+                
+                final Map<String, List<String>> headers =
+                    CastUtils.cast((Map<?, ?>)messageContext.get(MessageContext.HTTP_REQUEST_HEADERS));
+
+                if (headers == null) {
+                    throw new WebServiceException("Not authorized");
+                }
+
+                final String authorization = headers.get("Authorization").get(0);
+                final String expected = DefaultBasicAuthSupplier.getBasicAuthHeader("user", "test", true);
+                
+                if (!expected.equals(authorization)) {
+                    throw new WebServiceException("Not authorized");
+                }
+
+                return "CXF is protected: " + arg;
+            }
         }
     }
 
@@ -78,34 +108,32 @@ public class JaxwsAsyncFailOverTest  extends AbstractBusClientServerTestBase {
     public static void startServers() throws Exception {
         assertTrue("server did not launch correctly", launchServer(Server.class, true));
     }
+    
+    @AfterClass
+    public static void stopServers() throws Exception {
+        stopAllServers();
+    }
 
     @Test
-    public void testUseFailOverOnClient() throws Exception {
-        List<String> serviceList = new ArrayList<>();
-        serviceList.add("http://localhost:" + PORT + "/SoapContext/GreeterPort");
-
-        RandomStrategy strategy = new RandomStrategy();
-        strategy.setAlternateAddresses(serviceList);
-
-        FailoverFeature ff = new FailoverFeature();
-        ff.setStrategy(strategy);
-
+    public void testUseBasicAuthFromClient() throws Exception {
         // setup the feature by using JAXWS front-end API
         JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
         // set a fake address to kick off the failover feature
-        factory.setAddress("http://localhost:" + PORT2 + "/SoapContext/GreeterPort");
-        factory.getFeatures().add(ff);
+        factory.setAddress("http://localhost:" + PORT + "/SoapContext/GreeterPort");
         factory.setServiceClass(Greeter.class);
         Greeter proxy = factory.create(Greeter.class);
 
-        Response<GreetMeResponse>  response = proxy.greetMeAsync("cxf");
-        int waitCount = 0;
-        while (!response.isDone() && waitCount < 15) {
-            Thread.sleep(1000);
-            waitCount++;
-        }
-        assertTrue("Response still not received.", response.isDone());
-
+        Client clientProxy = ClientProxy.getClient(proxy);
+        HTTPConduit conduit = (HTTPConduit) clientProxy.getConduit();
+        conduit.getAuthorization().setAuthorizationType("Basic");
+        conduit.getAuthorization().setUserName("user");
+        conduit.getAuthorization().setPassword("test");
+        
+        final BindingProvider bindingProvider = (BindingProvider) proxy;
+        bindingProvider.getRequestContext().put("encode.basicauth.with.iso8859", true);
+
+        String response = proxy.greetMe("cxf");
+        assertThat("CXF is protected: cxf", equalTo(response));
     }
 
 }