tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1848347 - in /tomcat/trunk/java/org/apache/catalina: core/ApplicationSessionCookieConfig.java util/SessionConfig.java
Date Thu, 06 Dec 2018 18:55:23 GMT
Author: markt
Date: Thu Dec  6 18:55:23 2018
New Revision: 1848347

URL: http://svn.apache.org/viewvc?rev=1848347&view=rev
Log:
Refactor with an eye to fixing BZ 62988 that also needs to determine the session cookie path
from the Context.

Modified:
    tomcat/trunk/java/org/apache/catalina/core/ApplicationSessionCookieConfig.java
    tomcat/trunk/java/org/apache/catalina/util/SessionConfig.java

Modified: tomcat/trunk/java/org/apache/catalina/core/ApplicationSessionCookieConfig.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/ApplicationSessionCookieConfig.java?rev=1848347&r1=1848346&r2=1848347&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/core/ApplicationSessionCookieConfig.java (original)
+++ tomcat/trunk/java/org/apache/catalina/core/ApplicationSessionCookieConfig.java Thu Dec
 6 18:55:23 2018
@@ -197,29 +197,7 @@ public class ApplicationSessionCookieCon
             cookie.setHttpOnly(true);
         }
 
-        String contextPath = context.getSessionCookiePath();
-        if (contextPath == null || contextPath.length() == 0) {
-            contextPath = scc.getPath();
-        }
-        if (contextPath == null || contextPath.length() == 0) {
-            contextPath = context.getEncodedPath();
-        }
-        if (context.getSessionCookiePathUsesTrailingSlash()) {
-            // Handle special case of ROOT context where cookies require a path of
-            // '/' but the servlet spec uses an empty string
-            // Also ensure the cookies for a context with a path of /foo don't get
-            // sent for requests with a path of /foobar
-            if (!contextPath.endsWith("/")) {
-                contextPath = contextPath + "/";
-            }
-        } else {
-            // Only handle special case of ROOT context where cookies require a
-            // path of '/' but the servlet spec uses an empty string
-            if (contextPath.length() == 0) {
-                contextPath = "/";
-            }
-        }
-        cookie.setPath(contextPath);
+        cookie.setPath(SessionConfig.getSessionCookiePath(context));
 
         return cookie;
     }

Modified: tomcat/trunk/java/org/apache/catalina/util/SessionConfig.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/util/SessionConfig.java?rev=1848347&r1=1848346&r2=1848347&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/util/SessionConfig.java (original)
+++ tomcat/trunk/java/org/apache/catalina/util/SessionConfig.java Thu Dec  6 18:55:23 2018
@@ -84,6 +84,44 @@ public class SessionConfig {
     }
 
 
+    /**
+     * Determine the value to use for the session cookie path for the provided
+     * context.
+     *
+     * @param context The context
+     * @return the parameter name for the session
+     */
+    public static String getSessionCookiePath(Context context) {
+
+        SessionCookieConfig scc = context.getServletContext().getSessionCookieConfig();
+
+        String contextPath = context.getSessionCookiePath();
+        if (contextPath == null || contextPath.length() == 0) {
+            contextPath = scc.getPath();
+        }
+        if (contextPath == null || contextPath.length() == 0) {
+            contextPath = context.getEncodedPath();
+        }
+        if (context.getSessionCookiePathUsesTrailingSlash()) {
+            // Handle special case of ROOT context where cookies require a path of
+            // '/' but the servlet spec uses an empty string
+            // Also ensure the cookies for a context with a path of /foo don't get
+            // sent for requests with a path of /foobar
+            if (!contextPath.endsWith("/")) {
+                contextPath = contextPath + "/";
+            }
+        } else {
+            // Only handle special case of ROOT context where cookies require a
+            // path of '/' but the servlet spec uses an empty string
+            if (contextPath.length() == 0) {
+                contextPath = "/";
+            }
+        }
+
+        return contextPath;
+    }
+
+
     private SessionConfig() {
         // Utility class. Hide default constructor.
     }



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Mime
View raw message