Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id C739E200C46 for ; Wed, 29 Mar 2017 17:22:19 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id C5A23160B95; Wed, 29 Mar 2017 15:22:19 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id E3A91160B7C for ; Wed, 29 Mar 2017 17:22:18 +0200 (CEST) Received: (qmail 60285 invoked by uid 500); 29 Mar 2017 15:22:18 -0000 Mailing-List: contact commits-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cxf.apache.org Delivered-To: mailing list commits@cxf.apache.org Received: (qmail 60276 invoked by uid 99); 29 Mar 2017 15:22:18 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 29 Mar 2017 15:22:18 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 04E66DFBCA; Wed, 29 Mar 2017 15:22:18 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: coheigea@apache.org To: commits@cxf.apache.org Date: Wed, 29 Mar 2017 15:22:18 -0000 Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: [1/2] cxf-fediz git commit: FEDIZ-197: wsdlLocation shouldn't be changed archived-at: Wed, 29 Mar 2017 15:22:20 -0000 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 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 Authored: Wed Mar 29 09:15:10 2017 +0200 Committer: Colm O hEigeartaigh 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; + } +}