Repository: cxf
Updated Branches:
  refs/heads/master 0bc1a6030 -> 66e5cca3c


[CXF-7485] Better support for X-Forwarded-* headers


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

Branch: refs/heads/master
Commit: 66e5cca3ccd0857ec9abc0e4c4fa70115ad5ac75
Parents: 0bc1a60
Author: Sergey Beryozkin <[email protected]>
Authored: Mon Sep 4 17:18:40 2017 +0100
Committer: Sergey Beryozkin <[email protected]>
Committed: Mon Sep 4 17:18:40 2017 +0100

----------------------------------------------------------------------
 .../transport/servlet/AbstractHTTPServlet.java  | 133 +++++++++++++++----
 .../cxf/systest/jaxrs/JAXRSUriInfoTest.java     |  23 ++++
 .../systest/jaxrs/XForwardedServletFilter.java  |  81 +++++++++++
 .../AbstractSwagger2ServiceDescriptionTest.java |   9 +-
 .../jaxrs/description/Swagger2Server.java       |  82 ++++++++++++
 .../Swagger2XForwardedDescriptionTest.java      |  56 ++++++++
 .../resources/jaxrs_swagger2/WEB-INF/beans.xml  |  52 ++++++++
 .../resources/jaxrs_swagger2/WEB-INF/web.xml    |  57 ++++++++
 .../resources/jaxrs_uriinfo/WEB-INF/web.xml     |  16 ++-
 9 files changed, 480 insertions(+), 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/66e5cca3/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/AbstractHTTPServlet.java
----------------------------------------------------------------------
diff --git 
a/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/AbstractHTTPServlet.java
 
b/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/AbstractHTTPServlet.java
index 47ebb9f..f3a466e 100644
--- 
a/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/AbstractHTTPServlet.java
+++ 
b/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/AbstractHTTPServlet.java
@@ -20,6 +20,7 @@ package org.apache.cxf.transport.servlet;
 
 import java.io.IOException;
 import java.io.InputStream;
+import java.net.URI;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.Enumeration;
@@ -83,9 +84,12 @@ public abstract class AbstractHTTPServlet extends 
HttpServlet implements Filter
     private static final String USE_X_FORWARDED_HEADERS_PARAMETER = 
"use-x-forwarded-headers";
     private static final String X_FORWARDED_PROTO_HEADER = "X-Forwarded-Proto";
     private static final String X_FORWARDED_FOR_HEADER = "X-Forwarded-For";
+    private static final String X_FORWARDED_PREFIX_HEADER = 
"X-Forwarded-Prefix";
+    private static final String X_FORWARDED_HOST_HEADER = "X-Forwarded-Host";
+    private static final String X_FORWARDED_PORT_HEADER = "X-Forwarded-Port";
 
     private static final Map<String, String> DEFAULT_STATIC_CONTENT_TYPES;
-
+    
     static {
         DEFAULT_STATIC_CONTENT_TYPES = new HashMap<>();
         DEFAULT_STATIC_CONTENT_TYPES.put("html", "text/html");
@@ -95,7 +99,7 @@ public abstract class AbstractHTTPServlet extends HttpServlet 
implements Filter
         DEFAULT_STATIC_CONTENT_TYPES.put("xsd", "application/xml");
         DEFAULT_STATIC_CONTENT_TYPES.put("js", "application/javascript");
     }
-
+    
     private List<Pattern> staticResourcesList;
     private String staticWelcomeFile;
     private List<Pattern> redirectList;
@@ -299,10 +303,18 @@ public abstract class AbstractHTTPServlet extends 
HttpServlet implements Filter
 
     protected HttpServletRequest checkXForwardedHeaders(HttpServletRequest 
request) {
         if (useXForwardedHeaders) {
-            String originalProto = request.getHeader(X_FORWARDED_PROTO_HEADER);
-            String originalIp = request.getHeader(X_FORWARDED_FOR_HEADER);
-            if (originalProto != null || originalIp != null) {
-                return new HttpServletRequestXForwardedFilter(request, 
originalProto, originalIp);
+            String originalProtocol = 
request.getHeader(X_FORWARDED_PROTO_HEADER);
+            String originalRemoteAddr = 
request.getHeader(X_FORWARDED_FOR_HEADER);
+            String originalPrefix = 
request.getHeader(X_FORWARDED_PREFIX_HEADER);
+            String originalHost = request.getHeader(X_FORWARDED_HOST_HEADER);
+            String originalPort = request.getHeader(X_FORWARDED_PORT_HEADER);
+            if (originalProtocol != null || originalRemoteAddr != null) {
+                return new HttpServletRequestXForwardedFilter(request, 
+                                                              
originalProtocol, 
+                                                              
originalRemoteAddr,
+                                                              originalPrefix,
+                                                              originalHost,
+                                                              originalPort);
             }
         }
 
@@ -452,44 +464,113 @@ public abstract class AbstractHTTPServlet extends 
HttpServlet implements Filter
     }
     private static class HttpServletRequestXForwardedFilter extends 
HttpServletRequestWrapper {
 
-        private String originalProto;
-        private String originalClientIp;
-
+        private String newProtocol;
+        private String newRemoteAddr;
+        
+        private String newContextPath;
+        private String newServletPath;
+        private String newRequestUri;
+        private StringBuffer newRequestUrl;
+        
         HttpServletRequestXForwardedFilter(HttpServletRequest request,
                                            String originalProto,
-                                           String originalIp) {
+                                           String originalRemoteAddr,
+                                           String originalPrefix,
+                                           String originalHost,
+                                           String originalPort) {
             super(request);
-            this.originalProto = originalProto;
-            if (originalIp != null) {
-                originalClientIp = (originalIp.split(",")[0]).trim();
+            this.newProtocol = originalProto;
+            if (newRemoteAddr != null) {
+                newRemoteAddr = (originalRemoteAddr.split(",")[0]).trim();
+            }
+            newRequestUri = calculateNewRequestUri(request, originalPrefix);
+            newRequestUrl = calculateNewRequestUrl(request, 
+                                                   originalProto, 
+                                                   originalPrefix,
+                                                   originalHost,
+                                                   originalPort);
+            newContextPath = calculateNewContextPath(request, originalPrefix);
+            newServletPath = calculateNewServletPath(request, originalPrefix);
+        }
+        private static String calculateNewContextPath(HttpServletRequest 
request, String originalPrefix) {
+            if (originalPrefix != null) {
+                return originalPrefix;
+            } else {
+                return request.getContextPath();
             }
         }
+        private static String calculateNewServletPath(HttpServletRequest 
request, String originalPrefix) {
+            String servletPath = request.getServletPath();
+            if (originalPrefix != null) {
+                servletPath = request.getContextPath() + servletPath;
+            }
+            return servletPath;
+        }
+        private static String calculateNewRequestUri(HttpServletRequest 
request, String originalPrefix) {
+            String requestUri = request.getRequestURI();
+            if (originalPrefix != null) {
+                requestUri = originalPrefix + requestUri;
+            }
+            return requestUri;
+        }
+        private static StringBuffer calculateNewRequestUrl(HttpServletRequest 
request, 
+                                                           String 
originalProto,
+                                                           String 
originalPrefix, 
+                                                           String originalHost,
+                                                           String 
originalPort) {
+            URI uri = URI.create(request.getRequestURL().toString());
+            
+            StringBuffer sb = new StringBuffer();
+            
+            sb.append(originalProto != null ? originalProto : uri.getScheme())
+                .append("://")
+                .append(originalHost != null ? originalHost : uri.getHost())
+                .append(originalPort != null && !"-1".equals(originalPort) 
+                    ? ":" + originalPort : uri.getPort() != -1 ? ":" + 
uri.getPort() : "")
+                .append(originalPrefix != null ? originalPrefix : "")
+                .append(uri.getRawPath());
+                
+            String query = uri.getRawQuery();
+            if (query != null) {
+                sb.append('?').append(query);
+            }
+            
+            return sb;
+        }
         @Override
         public boolean isSecure() {
-            if (originalProto != null) {
-                return "https".equals(originalProto);
+            if (newProtocol != null) {
+                return "https".equals(newProtocol);
             }
             return super.isSecure();
         }
         @Override
         public StringBuffer getRequestURL() {
-            StringBuffer buf = super.getRequestURL();
-            if (originalProto != null && isSecure()) {
-                String str = buf.toString();
-                if (str.startsWith("http:")) {
-                    buf = new StringBuffer();
-                    buf.append("https").append(str.substring(4));
-                }
-            }
-            return buf;
+            return newRequestUrl;
         }
         @Override
         public String getRemoteAddr() {
-            if (originalClientIp != null) {
-                return originalClientIp;
+            if (newRemoteAddr != null) {
+                return newRemoteAddr;
             }
             return super.getRemoteAddr();
         }
+        
+        @Override
+        public String getRequestURI() {
+            return newRequestUri;
+        }
+        
+        @Override
+        public String getContextPath() {
+            return newContextPath;
+        }
+        
+        @Override
+        public String getServletPath() {
+            return newServletPath;
+        }
+        
 
     }
 

http://git-wip-us.apache.org/repos/asf/cxf/blob/66e5cca3/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSUriInfoTest.java
----------------------------------------------------------------------
diff --git 
a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSUriInfoTest.java
 
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSUriInfoTest.java
index 09e28ff..9e4b7c6 100644
--- 
a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSUriInfoTest.java
+++ 
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSUriInfoTest.java
@@ -80,6 +80,29 @@ public class JAXRSUriInfoTest extends 
AbstractClientServerTestBase {
         String data = wc.get(String.class);
         assertEquals("http://localhost:"; + PORT + "/app/v1/," + path + "," + 
pathParam, data);
     }
+    
+    @Test
+    public void testBasePathAndPathAndPathParamXForwarded() throws Exception {
+        checkUriInfoXForwarded("http://localhost:"; + PORT + "/app/v1", "\"\"", 
"/");
+        checkUriInfoXForwarded("http://localhost:"; + PORT + "/app/v1/", 
"\"\"", "/");
+        checkUriInfoXForwarded("http://localhost:"; + PORT + "/app/v1/test", 
"\"test\"", "test");
+        checkUriInfoXForwarded("http://localhost:"; + PORT + "/app/v1/", 
"\"\"", "/");
+        checkUriInfoXForwarded("http://localhost:"; + PORT + "/app/v1", "\"\"", 
"/");
+
+        checkUriInfoXForwarded("http://localhost:"; + PORT + "/app/v1/bar", 
"\"bar\"", "bar");
+        checkUriInfoXForwarded("http://localhost:"; + PORT + "/app/v1/bar", 
"\"bar\"", "bar");
+        checkUriInfoXForwarded("http://localhost:"; + PORT + 
"/app/v1/bar/test", "\"bar/test\"", "bar/test");
+        checkUriInfoXForwarded("http://localhost:"; + PORT + "/app/v1/bar", 
"\"bar\"", "bar");
+        checkUriInfoXForwarded("http://localhost:"; + PORT + "/app/v1/bar", 
"\"bar\"", "bar");
+    }
+    
+    private void checkUriInfoXForwarded(String address, String path, String 
pathParam) {
+        WebClient wc = WebClient.create(address);
+        wc.accept("text/plain");
+        wc.header("USE_XFORWARDED", true);
+        String data = wc.get(String.class);
+        assertEquals("https://external:8090/reverse/app/v1/,"; + path + "," + 
pathParam, data);
+    }
 
     @Ignore
     @Path("/")

http://git-wip-us.apache.org/repos/asf/cxf/blob/66e5cca3/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/XForwardedServletFilter.java
----------------------------------------------------------------------
diff --git 
a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/XForwardedServletFilter.java
 
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/XForwardedServletFilter.java
new file mode 100644
index 0000000..180921b
--- /dev/null
+++ 
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/XForwardedServletFilter.java
@@ -0,0 +1,81 @@
+/**
+ * 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.systest.jaxrs;
+
+import java.io.IOException;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletRequestWrapper;
+
+public class XForwardedServletFilter implements Filter {
+
+    @Override
+    public void destroy() {
+        // TODO Auto-generated method stub
+        
+    }
+
+    @Override
+    public void doFilter(ServletRequest req, ServletResponse resp, FilterChain 
chain)
+        throws IOException, ServletException {
+        HttpServletRequest httpReq = (HttpServletRequest)req;
+        if (httpReq.getHeader("USE_XFORWARDED") != null) {
+            httpReq = new HttpServletRequestXForwardedFilter(httpReq);
+        }
+        chain.doFilter(httpReq, resp);
+    }
+
+    @Override
+    public void init(FilterConfig arg0) throws ServletException {
+        // TODO Auto-generated method stub
+        
+    }
+
+    private static class HttpServletRequestXForwardedFilter extends 
HttpServletRequestWrapper {
+
+        HttpServletRequestXForwardedFilter(HttpServletRequest request) {
+            super(request);
+        }
+
+        @Override
+        public String getHeader(String name) {
+            if ("X-Forwarded-For".equals(name)) {
+                return "199.0.0.1";
+            } else if ("X-Forwarded-Proto".equals(name)) {
+                return "https";
+            } else if ("X-Forwarded-Prefix".equals(name)) {
+                return "/reverse";
+            } else if ("X-Forwarded-Port".equals(name)) {
+                return "8090";
+            } else if ("X-Forwarded-Host".equals(name)) {
+                return "external";
+            } else { 
+                return super.getHeader(name);
+            }
+        }
+        
+
+    }
+}

http://git-wip-us.apache.org/repos/asf/cxf/blob/66e5cca3/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/description/AbstractSwagger2ServiceDescriptionTest.java
----------------------------------------------------------------------
diff --git 
a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/description/AbstractSwagger2ServiceDescriptionTest.java
 
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/description/AbstractSwagger2ServiceDescriptionTest.java
index 7cc70aa..6667aeb 100644
--- 
a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/description/AbstractSwagger2ServiceDescriptionTest.java
+++ 
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/description/AbstractSwagger2ServiceDescriptionTest.java
@@ -126,12 +126,19 @@ public abstract class 
AbstractSwagger2ServiceDescriptionTest extends AbstractBus
     protected abstract String getExpectedFileYaml();
 
     protected void doTestApiListingIsProperlyReturnedJSON() throws Exception {
+        doTestApiListingIsProperlyReturnedJSON(false);
+    }
+    protected void doTestApiListingIsProperlyReturnedJSON(boolean 
useXForwarded) throws Exception {    
         final WebClient client = createWebClient("/swagger.json");
+        if (useXForwarded) {
+            client.header("USE_XFORWARDED", true);
+        }
         try {
             String swaggerJson = client.get(String.class);
             UserApplication ap = 
SwaggerParseUtils.getUserApplicationFromJson(swaggerJson);
             assertNotNull(ap);
-
+            assertEquals(useXForwarded ? "/reverse" : "/", ap.getBasePath());
+            
             List<UserResource> urs = ap.getResources();
             assertNotNull(urs);
             assertEquals(1, urs.size());

http://git-wip-us.apache.org/repos/asf/cxf/blob/66e5cca3/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/description/Swagger2Server.java
----------------------------------------------------------------------
diff --git 
a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/description/Swagger2Server.java
 
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/description/Swagger2Server.java
new file mode 100644
index 0000000..0fd86f4
--- /dev/null
+++ 
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/description/Swagger2Server.java
@@ -0,0 +1,82 @@
+/**
+ * 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.systest.jaxrs.description;
+
+import java.net.URISyntaxException;
+
+import org.apache.cxf.testutil.common.AbstractBusTestServerBase;
+import org.eclipse.jetty.server.Handler;
+import org.eclipse.jetty.server.handler.DefaultHandler;
+import org.eclipse.jetty.server.handler.HandlerCollection;
+import org.eclipse.jetty.webapp.WebAppContext;
+
+
+public class Swagger2Server extends AbstractBusTestServerBase {
+    static final String PORT = allocatePort(Swagger2Server.class);
+
+    private org.eclipse.jetty.server.Server server;
+
+    protected void run() {
+        server = new org.eclipse.jetty.server.Server(Integer.parseInt(PORT));
+
+        WebAppContext webappcontext = new WebAppContext();
+        String contextPath = null;
+        try {
+            contextPath = 
getClass().getResource("/jaxrs_swagger2").toURI().getPath();
+        } catch (URISyntaxException e1) {
+            e1.printStackTrace();
+        }
+        webappcontext.setContextPath("/");
+
+        webappcontext.setWar(contextPath);
+
+        HandlerCollection handlers = new HandlerCollection();
+        handlers.setHandlers(new Handler[] {webappcontext, new 
DefaultHandler()});
+
+        server.setHandler(handlers);
+        try {
+            server.start();
+
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+    public void tearDown() throws Exception {
+        super.tearDown();
+        if (server != null) {
+            server.stop();
+            server.destroy();
+            server = null;
+        }
+    }
+
+    public static void main(String args[]) {
+        try {
+            Swagger2Server s = new Swagger2Server();
+            s.start();
+        } catch (Exception ex) {
+            ex.printStackTrace();
+            System.exit(-1);
+        } finally {
+            System.out.println("done!");
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cxf/blob/66e5cca3/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/description/Swagger2XForwardedDescriptionTest.java
----------------------------------------------------------------------
diff --git 
a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/description/Swagger2XForwardedDescriptionTest.java
 
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/description/Swagger2XForwardedDescriptionTest.java
new file mode 100644
index 0000000..f635a06
--- /dev/null
+++ 
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/description/Swagger2XForwardedDescriptionTest.java
@@ -0,0 +1,56 @@
+/**
+ * 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.systest.jaxrs.description;
+
+import org.apache.cxf.jaxrs.model.AbstractResourceInfo;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class Swagger2XForwardedDescriptionTest extends 
AbstractSwagger2ServiceDescriptionTest {
+    private static final String PORT = Swagger2Server.PORT;
+
+    @BeforeClass
+    public static void startServers() throws Exception {
+        AbstractResourceInfo.clearAllMaps();
+        assertTrue("server did not launch correctly", 
launchServer(Swagger2Server.class));
+        createStaticBus();
+    }
+
+    @Test
+    public void testApiListingIsProperlyReturnedJSON() throws Exception {
+        doTestApiListingIsProperlyReturnedJSON();
+    }
+    
+    @Test
+    public void testApiListingIsProperlyReturnedJSONXForwarded() throws 
Exception {
+        doTestApiListingIsProperlyReturnedJSON(true);
+    }
+
+    @Override
+    protected String getPort() {
+        return PORT;
+    }
+
+    @Override
+    protected String getExpectedFileYaml() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+}

http://git-wip-us.apache.org/repos/asf/cxf/blob/66e5cca3/systests/jaxrs/src/test/resources/jaxrs_swagger2/WEB-INF/beans.xml
----------------------------------------------------------------------
diff --git a/systests/jaxrs/src/test/resources/jaxrs_swagger2/WEB-INF/beans.xml 
b/systests/jaxrs/src/test/resources/jaxrs_swagger2/WEB-INF/beans.xml
new file mode 100644
index 0000000..bed1e35
--- /dev/null
+++ b/systests/jaxrs/src/test/resources/jaxrs_swagger2/WEB-INF/beans.xml
@@ -0,0 +1,52 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+                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.
+        -->
+<!-- START SNIPPET: beans -->
+<!--
+                beans xmlns="http://www.springframework.org/schema/beans";
+                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+                xmlns:simple="http://cxf.apache.org/simple"; 
xsi:schemaLocation="
+                http://www.springframework.org/schema/beans
+                
http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
+                http://cxf.apache.org/simple 
http://cxf.apache.org/schemas/simple.xsd";
+        -->
+<beans xmlns="http://www.springframework.org/schema/beans"; 
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
+    xmlns:jaxrs="http://cxf.apache.org/jaxrs"; 
+    xmlns:util="http://www.springframework.org/schema/util"; 
+    xsi:schemaLocation=" http://www.springframework.org/schema/beans  
http://www.springframework.org/schema/beans/spring-beans-4.2.xsd 
http://cxf.apache.org/jaxrs  http://cxf.apache.org/schemas/jaxrs.xsd 
http://www.springframework.org/schema/util  
http://www.springframework.org/schema/util/spring-util-4.2.xsd";>
+    <import resource="classpath:META-INF/cxf/cxf.xml"/>
+    <import resource="classpath:META-INF/cxf/cxf-servlet.xml"/>
+    
+    <bean id="basicAuth" class="io.swagger.models.auth.BasicAuthDefinition"/>
+    
+    <util:map id="securityDefs">
+        <entry key="basicAuth" value-ref="basicAuth"/>
+    </util:map>
+    
+    <jaxrs:server address="/">
+        <jaxrs:serviceBeans>
+            <bean 
class="org.apache.cxf.systest.jaxrs.description.BookStoreSwagger2"/>
+        </jaxrs:serviceBeans>
+        <jaxrs:features>
+            <bean class="org.apache.cxf.jaxrs.swagger.Swagger2Feature">
+               <property name="propertiesLocation" 
value="/files/swagger.properties"/>
+               <property name="securityDefinitions" ref="securityDefs"/>
+            </bean>
+        </jaxrs:features>
+    </jaxrs:server>
+</beans>
+<!-- END SNIPPET: beans -->

http://git-wip-us.apache.org/repos/asf/cxf/blob/66e5cca3/systests/jaxrs/src/test/resources/jaxrs_swagger2/WEB-INF/web.xml
----------------------------------------------------------------------
diff --git a/systests/jaxrs/src/test/resources/jaxrs_swagger2/WEB-INF/web.xml 
b/systests/jaxrs/src/test/resources/jaxrs_swagger2/WEB-INF/web.xml
new file mode 100644
index 0000000..25f77aa
--- /dev/null
+++ b/systests/jaxrs/src/test/resources/jaxrs_swagger2/WEB-INF/web.xml
@@ -0,0 +1,57 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 
2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd";>
+<!--
+        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.
+-->
+<!-- START SNIPPET: webxml -->
+<web-app>
+  <filter> 
+    <filter-name>xforwarded</filter-name>
+    
<filter-class>org.apache.cxf.systest.jaxrs.XForwardedServletFilter</filter-class>
 
+  </filter> 
+  <filter-mapping> 
+    <filter-name>xforwarded</filter-name>
+    <url-pattern>/*</url-pattern> 
+  </filter-mapping> 
+    <context-param>
+        <param-name>contextConfigLocation</param-name>
+        <param-value>WEB-INF/beans.xml</param-value>
+    </context-param>
+    <listener>
+        <listener-class>
+                        org.springframework.web.context.ContextLoaderListener
+                </listener-class>
+    </listener>
+    <servlet>
+        <servlet-name>CXFServlet</servlet-name>
+        <display-name>CXF Servlet</display-name>
+        <servlet-class>
+             org.apache.cxf.transport.servlet.CXFServlet
+        </servlet-class>
+        <init-param>
+            <param-name>use-x-forwarded-headers</param-name>
+            <param-value>true</param-value>
+        </init-param>
+        <load-on-startup>1</load-on-startup>
+    </servlet>
+    <servlet-mapping>
+        <servlet-name>CXFServlet</servlet-name>
+        <url-pattern>/*</url-pattern>
+    </servlet-mapping>
+</web-app>
+<!-- END SNIPPET: webxml -->

http://git-wip-us.apache.org/repos/asf/cxf/blob/66e5cca3/systests/jaxrs/src/test/resources/jaxrs_uriinfo/WEB-INF/web.xml
----------------------------------------------------------------------
diff --git a/systests/jaxrs/src/test/resources/jaxrs_uriinfo/WEB-INF/web.xml 
b/systests/jaxrs/src/test/resources/jaxrs_uriinfo/WEB-INF/web.xml
index 61deb6f..bf7edd8 100644
--- a/systests/jaxrs/src/test/resources/jaxrs_uriinfo/WEB-INF/web.xml
+++ b/systests/jaxrs/src/test/resources/jaxrs_uriinfo/WEB-INF/web.xml
@@ -20,6 +20,14 @@
 -->
 <!-- START SNIPPET: webxml -->
 <web-app>
+  <filter> 
+    <filter-name>xforwarded</filter-name>
+    
<filter-class>org.apache.cxf.systest.jaxrs.XForwardedServletFilter</filter-class>
 
+  </filter> 
+  <filter-mapping> 
+    <filter-name>xforwarded</filter-name>
+    <url-pattern>/v1/*</url-pattern> 
+  </filter-mapping> 
     <context-param>
         <param-name>contextConfigLocation</param-name>
         <param-value>WEB-INF/beans.xml</param-value>
@@ -33,8 +41,12 @@
         <servlet-name>CXFServlet</servlet-name>
         <display-name>CXF Servlet</display-name>
         <servlet-class>
-                        org.apache.cxf.transport.servlet.CXFServlet
-                </servlet-class>
+             org.apache.cxf.transport.servlet.CXFServlet
+        </servlet-class>
+        <init-param>
+            <param-name>use-x-forwarded-headers</param-name>
+            <param-value>true</param-value>
+        </init-param>
         <load-on-startup>1</load-on-startup>
     </servlet>
     <servlet-mapping>

Reply via email to