Repository: cxf-fediz
Updated Branches:
  refs/heads/master 2e4dac9be -> 36480e970


FEDIZ-197: wsdlLocation shouldn't be changed

We should change wsdlLocation to use localPort
only if port 0 has been explicitly set.

Otherwise, we should use wsdlLocation as is.

Signed-off-by: Colm O hEigeartaigh <cohei...@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/cxf-fediz/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf-fediz/commit/07ce8579
Tree: http://git-wip-us.apache.org/repos/asf/cxf-fediz/tree/07ce8579
Diff: http://git-wip-us.apache.org/repos/asf/cxf-fediz/diff/07ce8579

Branch: refs/heads/master
Commit: 07ce85792079b36a962f9ba39dd296894c76d779
Parents: 2e4dac9
Author: gonzalad <adr_gonza...@yahoo.fr>
Authored: Wed Mar 29 09:15:10 2017 +0200
Committer: Colm O hEigeartaigh <cohei...@apache.org>
Committed: Wed Mar 29 16:08:06 2017 +0100

----------------------------------------------------------------------
 .../service/idp/beans/STSClientAction.java      |  2 +-
 .../cxf/fediz/service/idp/util/WebUtils.java    | 17 ++--
 .../service/idp/beans/STSClientActionTest.java  | 87 ++++++++++++++++++++
 3 files changed, 96 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf-fediz/blob/07ce8579/services/idp-core/src/main/java/org/apache/cxf/fediz/service/idp/beans/STSClientAction.java
----------------------------------------------------------------------
diff --git 
a/services/idp-core/src/main/java/org/apache/cxf/fediz/service/idp/beans/STSClientAction.java
 
b/services/idp-core/src/main/java/org/apache/cxf/fediz/service/idp/beans/STSClientAction.java
index e0d324e..ff9f65f 100644
--- 
a/services/idp-core/src/main/java/org/apache/cxf/fediz/service/idp/beans/STSClientAction.java
+++ 
b/services/idp-core/src/main/java/org/apache/cxf/fediz/service/idp/beans/STSClientAction.java
@@ -116,7 +116,7 @@ public class STSClientAction {
         this.wsdlLocation = wsdlLocation;
         try {
             URL url = new URL(wsdlLocation);
-            isPortSet = url.getPort() > 0;
+            isPortSet = url.getPort() != 0;
             if (!isPortSet) {
                 LOG.info("Port is 0 for 'wsdlLocation'. Port evaluated when 
processing first request.");
             }

http://git-wip-us.apache.org/repos/asf/cxf-fediz/blob/07ce8579/services/idp-core/src/main/java/org/apache/cxf/fediz/service/idp/util/WebUtils.java
----------------------------------------------------------------------
diff --git 
a/services/idp-core/src/main/java/org/apache/cxf/fediz/service/idp/util/WebUtils.java
 
b/services/idp-core/src/main/java/org/apache/cxf/fediz/service/idp/util/WebUtils.java
index edf9fde..a1da71a 100644
--- 
a/services/idp-core/src/main/java/org/apache/cxf/fediz/service/idp/util/WebUtils.java
+++ 
b/services/idp-core/src/main/java/org/apache/cxf/fediz/service/idp/util/WebUtils.java
@@ -24,7 +24,6 @@ import javax.servlet.http.HttpServletResponse;
 import javax.servlet.http.HttpSession;
 
 import org.springframework.util.Assert;
-import org.springframework.webflow.context.servlet.ServletExternalContext;
 import org.springframework.webflow.execution.RequestContext;
 
 /**
@@ -38,12 +37,12 @@ public final class WebUtils {
 
     public static HttpServletRequest getHttpServletRequest(
             final RequestContext context) {
-        Assert.isInstanceOf(ServletExternalContext.class,
-                context.getExternalContext(),
+        Object request =  context.getExternalContext().getNativeRequest();
+        Assert.isInstanceOf(HttpServletRequest.class,
+                request,
                 "Cannot obtain HttpServletRequest from event of type: "
                         + context.getExternalContext().getClass().getName());
-        return (HttpServletRequest) context.getExternalContext()
-                .getNativeRequest();
+        return (HttpServletRequest) request;
     }
 
     public static HttpSession getHttpSession(final RequestContext context) {
@@ -53,12 +52,12 @@ public final class WebUtils {
 
     public static HttpServletResponse getHttpServletResponse(
             final RequestContext context) {
-        Assert.isInstanceOf(ServletExternalContext.class,
-                context.getExternalContext(),
+        Object response =  context.getExternalContext().getNativeResponse();
+        Assert.isInstanceOf(HttpServletResponse.class,
+                response,
                 "Cannot obtain HttpServletResponse from event of type: "
                         + context.getExternalContext().getClass().getName());
-        return (HttpServletResponse) context.getExternalContext()
-                .getNativeResponse();
+        return (HttpServletResponse) response;
     }
 
     public static String getHttpHeader(RequestContext requestContext, String 
headerName) {

http://git-wip-us.apache.org/repos/asf/cxf-fediz/blob/07ce8579/services/idp-core/src/test/java/org/apache/cxf/fediz/service/idp/beans/STSClientActionTest.java
----------------------------------------------------------------------
diff --git 
a/services/idp-core/src/test/java/org/apache/cxf/fediz/service/idp/beans/STSClientActionTest.java
 
b/services/idp-core/src/test/java/org/apache/cxf/fediz/service/idp/beans/STSClientActionTest.java
new file mode 100644
index 0000000..6f4ae76
--- /dev/null
+++ 
b/services/idp-core/src/test/java/org/apache/cxf/fediz/service/idp/beans/STSClientActionTest.java
@@ -0,0 +1,87 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.cxf.fediz.service.idp.beans;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+import org.junit.Test;
+import org.springframework.mock.web.MockHttpServletRequest;
+import org.springframework.webflow.execution.RequestContext;
+import org.springframework.webflow.test.MockRequestContext;
+import static org.junit.Assert.assertEquals;
+
+public class STSClientActionTest {
+
+    private static final int LOCAL_PORT = 8080;
+
+    @Test
+    public void testWsdlWithDefaultPort() {
+        String wsdlLocation = "http://someserver/sts";;
+        STSClientAction action = new STSClientAction();
+        action.setWsdlLocation(wsdlLocation);
+        callProcessWsdlLocation(action, mockRequestContext());
+        assertEquals(wsdlLocation, action.getWsdlLocation());
+    }
+
+    @Test
+    public void testWsdlWithExplicitPort() {
+        String wsdlLocation = "http://someserver:91/sts";;
+        STSClientAction action = new STSClientAction();
+        action.setWsdlLocation(wsdlLocation);
+        callProcessWsdlLocation(action, mockRequestContext());
+        assertEquals(wsdlLocation, action.getWsdlLocation());
+    }
+
+    @Test
+    public void testWsdlWithPort0() {
+        String wsdlLocation = "http://someserver:0/sts";;
+        STSClientAction action = new STSClientAction();
+        action.setWsdlLocation(wsdlLocation);
+        callProcessWsdlLocation(action, mockRequestContext());
+        assertEquals("http://someserver:"; + LOCAL_PORT + "/sts", 
action.getWsdlLocation());
+    }
+
+    private void callProcessWsdlLocation(STSClientAction action, 
RequestContext requestContext) {
+        Method method = null;
+        try {
+            method = 
action.getClass().getDeclaredMethod("processWsdlLocation", 
RequestContext.class);
+        } catch (NoSuchMethodException e) {
+            throw new RuntimeException(e);
+        }
+        method.setAccessible(true);
+        try {
+            method.invoke(action, requestContext);
+        } catch (IllegalAccessException | InvocationTargetException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    /**
+     * Forces local port to pre-defined value to test if it's used
+     * by STSClientAction to compute STS urls.
+     */
+    private RequestContext mockRequestContext() {
+        MockRequestContext requestContext = new MockRequestContext();
+        MockHttpServletRequest servletRequest = new MockHttpServletRequest();
+        servletRequest.setLocalPort(LOCAL_PORT);
+        
requestContext.getMockExternalContext().setNativeRequest(servletRequest);
+        return requestContext;
+    }
+}

Reply via email to