]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-7714 Remove JSESSIONID generation from Tomcat
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Tue, 6 Sep 2016 10:23:50 +0000 (12:23 +0200)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Fri, 9 Sep 2016 08:10:51 +0000 (10:10 +0200)
server/sonar-server/src/main/java/org/sonar/server/app/TomcatContexts.java
server/sonar-server/src/main/java/org/sonar/server/platform/web/MasterServletFilter.java
server/sonar-server/src/main/java/org/sonar/server/platform/web/ProfilingFilter.java [deleted file]
server/sonar-server/src/main/java/org/sonar/server/platform/web/RootFilter.java [new file with mode: 0644]
server/sonar-server/src/test/java/org/sonar/server/platform/web/MasterServletFilterTest.java
server/sonar-server/src/test/java/org/sonar/server/platform/web/ProfilingFilterTest.java [deleted file]
server/sonar-server/src/test/java/org/sonar/server/platform/web/RootFilterTest.java [new file with mode: 0644]
server/sonar-web/src/main/webapp/WEB-INF/web.xml

index 56dcf66f5ff7d1107bfc019cb8a5be00b1b20522..b15d76e08545cb0d8195903ab97c1cc40988c1c9 100644 (file)
@@ -112,6 +112,7 @@ public class TomcatContexts {
       context.setDelegate(true);
       context.setJarScanner(new NullJarScanner());
       context.setAllowCasualMultipartParsing(true);
+      context.setCookies(false);
       return context;
     } catch (ServletException e) {
       throw new IllegalStateException("Fail to configure webapp from " + dir, e);
index 76f3abd08229fc63091541dd6100c73491200035..230bddd3cd688e4bcfcf3ca17b79e3115d6c3445 100644 (file)
@@ -82,7 +82,7 @@ public class MasterServletFilter implements Filter {
   public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws ServletException, IOException {
     HttpServletRequest hsr = (HttpServletRequest) request;
     if (filters.length == 0) {
-      chain.doFilter(request, response);
+      chain.doFilter(hsr, response);
     } else {
       String path = hsr.getRequestURI().replaceFirst(hsr.getContextPath(), "");
       GodFilterChain godChain = new GodFilterChain(chain);
@@ -92,7 +92,7 @@ public class MasterServletFilter implements Filter {
           godChain.addFilter(filter);
         }
       }
-      godChain.doFilter(request, response);
+      godChain.doFilter(hsr, response);
     }
   }
 
@@ -134,4 +134,5 @@ public class MasterServletFilter implements Filter {
       filters.add(filter);
     }
   }
+
 }
diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/web/ProfilingFilter.java b/server/sonar-server/src/main/java/org/sonar/server/platform/web/ProfilingFilter.java
deleted file mode 100644 (file)
index 8728a7b..0000000
+++ /dev/null
@@ -1,115 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.server.platform.web;
-
-import com.google.common.collect.ImmutableSet;
-import org.apache.commons.lang.StringUtils;
-import org.sonar.api.utils.log.Loggers;
-import org.sonar.api.utils.log.Profiler;
-
-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 java.io.IOException;
-import java.util.Set;
-
-/**
- * <p>Profile HTTP requests using platform profiling utility.</p>
- * <p>To avoid profiling of requests for static resources, the <code>staticDirs</code>
- * filter parameter can be set in the servlet context descriptor. This parameter should
- * contain a comma-separated list of paths, starting at the context root;
- * requests on subpaths of these paths will not be profiled.</p>
- *
- * @since 4.1
- */
-public class ProfilingFilter implements Filter {
-
-  private static final String CONFIG_SEPARATOR = ",";
-  private static final String URL_SEPARATOR = "/";
-
-  private static final String MESSAGE_WITH_QUERY = "%s %s?%s";
-  private static final String MESSAGE_WITHOUT_QUERY = "%s %s";
-  public static final org.sonar.api.utils.log.Logger Logger = Loggers.get("http");
-
-  private String contextRoot;
-  private Set<String> staticResourceDirs;
-
-  @Override
-  public void init(FilterConfig filterConfig) throws ServletException {
-    contextRoot = filterConfig.getServletContext().getContextPath();
-
-    String staticResourcesConfig = filterConfig.getInitParameter("staticDirs");
-    if (StringUtils.isNotBlank(staticResourcesConfig)) {
-      staticResourceDirs = ImmutableSet.copyOf(staticResourcesConfig.split(CONFIG_SEPARATOR));
-    } else {
-      staticResourceDirs = ImmutableSet.of();
-    }
-  }
-
-  @Override
-  public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
-    if (request instanceof HttpServletRequest) {
-      HttpServletRequest httpRequest = (HttpServletRequest) request;
-      String requestUri = httpRequest.getRequestURI();
-      String rootDir = getRootDir(requestUri);
-
-      if (staticResourceDirs.contains(rootDir)) {
-        // Static resource, not profiled
-        chain.doFilter(request, response);
-      } else {
-        Profiler profiler = Profiler.createIfDebug(Logger).start();
-        try {
-          chain.doFilter(request, response);
-        } finally {
-          if (profiler.isDebugEnabled()) {
-            String queryString = httpRequest.getQueryString();
-            String message = String.format(queryString == null ? MESSAGE_WITHOUT_QUERY : MESSAGE_WITH_QUERY, httpRequest.getMethod(), requestUri, queryString);
-            profiler.stopDebug(message);
-          }
-        }
-      }
-    } else {
-      // Not an HTTP request, not profiled
-      chain.doFilter(request, response);
-    }
-  }
-
-  private String getRootDir(String requestUri) {
-    String rootPath = "";
-    String localPath = StringUtils.substringAfter(requestUri, contextRoot);
-    if (localPath.startsWith(URL_SEPARATOR)) {
-      int secondSlash = localPath.indexOf(URL_SEPARATOR, 1);
-      if (secondSlash > 0) {
-        rootPath = URL_SEPARATOR + localPath.substring(1, secondSlash);
-      }
-    }
-    return rootPath;
-  }
-
-  @Override
-  public void destroy() {
-    // Nothing
-  }
-}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/web/RootFilter.java b/server/sonar-server/src/main/java/org/sonar/server/platform/web/RootFilter.java
new file mode 100644 (file)
index 0000000..dec5a8d
--- /dev/null
@@ -0,0 +1,138 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.server.platform.web;
+
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.collect.ImmutableSet;
+import java.io.IOException;
+import java.util.Set;
+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;
+import javax.servlet.http.HttpSession;
+import org.apache.commons.lang.StringUtils;
+import org.sonar.api.utils.log.Loggers;
+import org.sonar.api.utils.log.Profiler;
+
+/**
+ * <p>Profile HTTP requests using platform profiling utility.</p>
+ * <p>To avoid profiling of requests for static resources, the <code>staticDirs</code>
+ * filter parameter can be set in the servlet context descriptor. This parameter should
+ * contain a comma-separated list of paths, starting at the context root;
+ * requests on subpaths of these paths will not be profiled.</p>
+ *
+ * @since 4.1
+ */
+public class RootFilter implements Filter {
+
+  private static final String CONFIG_SEPARATOR = ",";
+  private static final String URL_SEPARATOR = "/";
+
+  private static final String MESSAGE_WITH_QUERY = "%s %s?%s";
+  private static final String MESSAGE_WITHOUT_QUERY = "%s %s";
+  public static final org.sonar.api.utils.log.Logger Logger = Loggers.get("http");
+
+  private String contextRoot;
+  private Set<String> staticResourceDirs;
+
+  @Override
+  public void init(FilterConfig filterConfig) throws ServletException {
+    contextRoot = filterConfig.getServletContext().getContextPath();
+
+    String staticResourcesConfig = filterConfig.getInitParameter("staticDirs");
+    if (StringUtils.isNotBlank(staticResourcesConfig)) {
+      staticResourceDirs = ImmutableSet.copyOf(staticResourcesConfig.split(CONFIG_SEPARATOR));
+    } else {
+      staticResourceDirs = ImmutableSet.of();
+    }
+  }
+
+  @Override
+  public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
+    if (request instanceof HttpServletRequest) {
+      HttpServletRequest httpRequest = new ServletRequestWrapper((HttpServletRequest) request);
+      String requestUri = httpRequest.getRequestURI();
+      String rootDir = getRootDir(requestUri);
+
+      if (staticResourceDirs.contains(rootDir)) {
+        // Static resource, not profiled
+        chain.doFilter(httpRequest, response);
+      } else {
+        Profiler profiler = Profiler.createIfDebug(Logger).start();
+        try {
+          chain.doFilter(httpRequest, response);
+        } finally {
+          if (profiler.isDebugEnabled()) {
+            String queryString = httpRequest.getQueryString();
+            String message = String.format(queryString == null ? MESSAGE_WITHOUT_QUERY : MESSAGE_WITH_QUERY, httpRequest.getMethod(), requestUri, queryString);
+            profiler.stopDebug(message);
+          }
+        }
+      }
+    } else {
+      // Not an HTTP request, not profiled
+      chain.doFilter(request, response);
+    }
+  }
+
+  private String getRootDir(String requestUri) {
+    String rootPath = "";
+    String localPath = StringUtils.substringAfter(requestUri, contextRoot);
+    if (localPath.startsWith(URL_SEPARATOR)) {
+      int secondSlash = localPath.indexOf(URL_SEPARATOR, 1);
+      if (secondSlash > 0) {
+        rootPath = URL_SEPARATOR + localPath.substring(1, secondSlash);
+      }
+    }
+    return rootPath;
+  }
+
+  @Override
+  public void destroy() {
+    // Nothing
+  }
+
+  @VisibleForTesting
+  static class ServletRequestWrapper extends HttpServletRequestWrapper {
+
+    ServletRequestWrapper(HttpServletRequest request) {
+      super(request);
+    }
+
+    @Override
+    public HttpSession getSession(boolean create) {
+      throw notSupported();
+    }
+
+    @Override
+    public HttpSession getSession() {
+      throw notSupported();
+    }
+
+    private static UnsupportedOperationException notSupported() {
+      return new UnsupportedOperationException("Sessions are disabled so that web server is stateless");
+    }
+  }
+}
index 255dab8f8e32ba32e61384eef6497cb2ad32120d..3ac703c5819a133c26c0d338c8b75a930e8eedc3 100644 (file)
@@ -46,7 +46,7 @@ import static org.mockito.Mockito.when;
 public class MasterServletFilterTest {
 
   @Rule
-  public ExpectedException thrown = ExpectedException.none();
+  public ExpectedException expectedException = ExpectedException.none();
 
   @Before
   public void resetSingleton() {
@@ -71,15 +71,15 @@ public class MasterServletFilterTest {
   public void servlet_container_should_instantiate_only_a_single_master_instance() {
     new MasterServletFilter();
 
-    thrown.expect(IllegalStateException.class);
-    thrown.expectMessage("Servlet filter org.sonar.server.platform.web.MasterServletFilter is already instantiated");
+    expectedException.expect(IllegalStateException.class);
+    expectedException.expectMessage("Servlet filter org.sonar.server.platform.web.MasterServletFilter is already instantiated");
     new MasterServletFilter();
   }
 
   @Test
   public void should_propagate_initialization_failure() throws Exception {
-    thrown.expect(IllegalStateException.class);
-    thrown.expectMessage("foo");
+    expectedException.expect(IllegalStateException.class);
+    expectedException.expectMessage("foo");
 
     ServletFilter filter = mock(ServletFilter.class);
     doThrow(new IllegalStateException("foo")).when(filter).init(any(FilterConfig.class));
@@ -126,17 +126,20 @@ public class MasterServletFilterTest {
     private static int globalCount = 0;
     private int count = 0;
 
+    @Override
     public void init(FilterConfig filterConfig) throws ServletException {
     }
 
+    @Override
     public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
       globalCount++;
       count = globalCount;
       filterChain.doFilter(servletRequest, servletResponse);
     }
 
+    @Override
     public void destroy() {
     }
-
   }
+
 }
diff --git a/server/sonar-server/src/test/java/org/sonar/server/platform/web/ProfilingFilterTest.java b/server/sonar-server/src/test/java/org/sonar/server/platform/web/ProfilingFilterTest.java
deleted file mode 100644 (file)
index 93c339c..0000000
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.server.platform.web;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.mockito.Mockito;
-
-import javax.servlet.FilterChain;
-import javax.servlet.FilterConfig;
-import javax.servlet.ServletContext;
-import javax.servlet.ServletException;
-import javax.servlet.ServletRequest;
-import javax.servlet.ServletResponse;
-import javax.servlet.http.HttpServletRequest;
-import org.sonar.server.platform.web.ProfilingFilter;
-
-import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-public class ProfilingFilterTest {
-
-  private ProfilingFilter filter;
-  private FilterChain chain;
-
-  @Before
-  public void initialize() throws Exception {
-    FilterConfig filterConfig = mock(FilterConfig.class);
-    when(filterConfig.getInitParameter("staticDirs")).thenReturn("/static,/assets");
-    ServletContext context = mock(ServletContext.class);
-    when(context.getContextPath()).thenReturn("/context");
-    when(filterConfig.getServletContext()).thenReturn(context);
-    chain = mock(FilterChain.class);
-
-    filter = new ProfilingFilter();
-    filter.init(filterConfig);
-  }
-
-  @Test
-  public void should_profile_service_call() throws Exception {
-    filter.doFilter(request("POST", "/context/service/call", "param=value"), null, chain);
-  }
-
-  @Test
-  public void should_profile_service() throws Exception {
-    filter.doFilter(request("POST", "/context/service", null), null, chain);
-  }
-
-  @Test
-  public void should_profile_context_root_as_slash2() throws Exception {
-    filter.doFilter(request("POST", "/context", null), null, chain);
-  }
-
-  @Test(expected = ServletException.class)
-  public void should_profile_even_when_exception() throws Exception {
-    Mockito.doThrow(new ServletException()).when(chain).doFilter(any(ServletRequest.class), any(ServletResponse.class));
-    filter.doFilter(request("POST", "/context/service/call", "param=value"), null, chain);
-  }
-
-  @Test
-  public void should_not_profile_non_http_request() throws Exception {
-    filter.doFilter(mock(ServletRequest.class), null, chain);
-  }
-
-  @Test
-  public void should_not_profile_static_resource() throws Exception {
-    filter.doFilter(request("GET", "/context/static/image.png", null), null, chain);
-  }
-
-  @Test
-  public void should_profile_static_resource_if_no_config() throws Exception {
-    FilterConfig filterConfig = mock(FilterConfig.class);
-    ServletContext context = mock(ServletContext.class);
-    when(context.getContextPath()).thenReturn("/context");
-    when(filterConfig.getServletContext()).thenReturn(context);
-
-    filter.init(filterConfig);
-    filter.doFilter(request("GET", "/context/static/image.png", null), null, chain);
-  }
-
-  private HttpServletRequest request(String method, String path, String query) {
-    HttpServletRequest request = mock(HttpServletRequest.class);
-    when(request.getMethod()).thenReturn(method);
-    when(request.getRequestURI()).thenReturn(path);
-    when(request.getQueryString()).thenReturn(query);
-    return request;
-  }
-}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/platform/web/RootFilterTest.java b/server/sonar-server/src/test/java/org/sonar/server/platform/web/RootFilterTest.java
new file mode 100644 (file)
index 0000000..aff2ff1
--- /dev/null
@@ -0,0 +1,152 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.server.platform.web;
+
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Mockito;
+
+import static org.assertj.core.api.Java6Assertions.assertThat;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+public class RootFilterTest {
+
+  @Rule
+  public ExpectedException expectedException = ExpectedException.none();
+
+  private RootFilter filter;
+  private FilterChain chain;
+
+  @Before
+  public void initialize() throws Exception {
+    FilterConfig filterConfig = mock(FilterConfig.class);
+    when(filterConfig.getInitParameter("staticDirs")).thenReturn("/static,/assets");
+    ServletContext context = mock(ServletContext.class);
+    when(context.getContextPath()).thenReturn("/context");
+    when(filterConfig.getServletContext()).thenReturn(context);
+    chain = mock(FilterChain.class);
+
+    filter = new RootFilter();
+    filter.init(filterConfig);
+  }
+
+  @Test
+  public void should_profile_service_call() throws Exception {
+    filter.doFilter(request("POST", "/context/service/call", "param=value"), null, chain);
+  }
+
+  @Test
+  public void should_profile_service() throws Exception {
+    filter.doFilter(request("POST", "/context/service", null), null, chain);
+  }
+
+  @Test
+  public void should_profile_context_root_as_slash2() throws Exception {
+    filter.doFilter(request("POST", "/context", null), null, chain);
+  }
+
+  @Test(expected = ServletException.class)
+  public void should_profile_even_when_exception() throws Exception {
+    Mockito.doThrow(new ServletException()).when(chain).doFilter(any(ServletRequest.class), any(ServletResponse.class));
+    filter.doFilter(request("POST", "/context/service/call", "param=value"), null, chain);
+  }
+
+  @Test
+  public void should_not_profile_non_http_request() throws Exception {
+    filter.doFilter(mock(ServletRequest.class), null, chain);
+  }
+
+  @Test
+  public void should_not_profile_static_resource() throws Exception {
+    filter.doFilter(request("GET", "/context/static/image.png", null), null, chain);
+  }
+
+  @Test
+  public void should_profile_static_resource_if_no_config() throws Exception {
+    FilterConfig filterConfig = mock(FilterConfig.class);
+    ServletContext context = mock(ServletContext.class);
+    when(context.getContextPath()).thenReturn("/context");
+    when(filterConfig.getServletContext()).thenReturn(context);
+
+    filter.init(filterConfig);
+    filter.doFilter(request("GET", "/context/static/image.png", null), null, chain);
+  }
+
+  @Test
+  public void request_used_in_chain_do_filter_is_a_servlet_wrapper_when_static_resource() throws Exception {
+    filter.doFilter(request("GET", "/context/static/image.png", null), null, chain);
+    ArgumentCaptor<ServletRequest> requestArgumentCaptor = ArgumentCaptor.forClass(ServletRequest.class);
+
+    verify(chain).doFilter(requestArgumentCaptor.capture(), any(ServletResponse.class));
+
+    assertThat(requestArgumentCaptor.getValue()).isInstanceOf(RootFilter.ServletRequestWrapper.class);
+  }
+
+  @Test
+  public void request_used_in_chain_do_filter_is_a_servlet_wrapper_when_service_call() throws Exception {
+    filter.doFilter(request("POST", "/context/service/call", "param=value"), null, chain);
+    ArgumentCaptor<ServletRequest> requestArgumentCaptor = ArgumentCaptor.forClass(ServletRequest.class);
+
+    verify(chain).doFilter(requestArgumentCaptor.capture(), any(ServletResponse.class));
+
+    assertThat(requestArgumentCaptor.getValue()).isInstanceOf(RootFilter.ServletRequestWrapper.class);
+  }
+
+  @Test
+  public void fail_to_get_session_from_request() throws Exception {
+    filter.doFilter(request("GET", "/context/static/image.png", null), null, chain);
+    ArgumentCaptor<ServletRequest> requestArgumentCaptor = ArgumentCaptor.forClass(ServletRequest.class);
+    verify(chain).doFilter(requestArgumentCaptor.capture(), any(ServletResponse.class));
+
+    expectedException.expect(UnsupportedOperationException.class);
+    ((HttpServletRequest) requestArgumentCaptor.getValue()).getSession();
+  }
+
+  @Test
+  public void fail_to_get_session_with_create_from_request() throws Exception {
+    filter.doFilter(request("GET", "/context/static/image.png", null), null, chain);
+    ArgumentCaptor<ServletRequest> requestArgumentCaptor = ArgumentCaptor.forClass(ServletRequest.class);
+    verify(chain).doFilter(requestArgumentCaptor.capture(), any(ServletResponse.class));
+
+    expectedException.expect(UnsupportedOperationException.class);
+    ((HttpServletRequest) requestArgumentCaptor.getValue()).getSession(true);
+  }
+
+  private HttpServletRequest request(String method, String path, String query) {
+    HttpServletRequest request = mock(HttpServletRequest.class);
+    when(request.getMethod()).thenReturn(method);
+    when(request.getRequestURI()).thenReturn(path);
+    when(request.getQueryString()).thenReturn(query);
+    return request;
+  }
+}
index b86c1a99b9b6b382691612d904dba0a3fca3726d..e0bd48e3257b71dbaec84414491addfcc1313db3 100644 (file)
@@ -53,8 +53,8 @@
     <filter-class>org.sonar.server.platform.web.SecurityServletFilter</filter-class>
   </filter>
   <filter>
-    <filter-name>ProfilingFilter</filter-name>
-    <filter-class>org.sonar.server.platform.web.ProfilingFilter</filter-class>
+    <filter-name>RootFilter</filter-name>
+    <filter-class>org.sonar.server.platform.web.RootFilter</filter-class>
     <init-param>
       <param-name>staticDirs</param-name>
       <param-value>/images,/javascripts,/stylesheets</param-value>
@@ -67,7 +67,7 @@
 
   <!-- order of execution is important -->
   <filter-mapping>
-    <filter-name>ProfilingFilter</filter-name>
+    <filter-name>RootFilter</filter-name>
     <url-pattern>/*</url-pattern>
   </filter-mapping>
   <filter-mapping>
     <url-pattern>/static/*</url-pattern>
   </servlet-mapping>
 
-  <session-config>
-    <!-- in minutes -->
-    <session-timeout>20</session-timeout>
-    <cookie-config>
-      <http-only>true</http-only>
-    </cookie-config>
-  </session-config>
-
   <listener>
     <listener-class>org.sonar.server.platform.web.PlatformServletContextListener</listener-class>
   </listener>