You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2010/03/10 17:18:10 UTC
svn commit: r921426 - in /tomcat/trunk: java/org/apache/catalina/
java/org/apache/catalina/connector/ java/org/apache/catalina/core/
webapps/docs/config/
Author: markt
Date: Wed Mar 10 16:18:10 2010
New Revision: 921426
URL: http://svn.apache.org/viewvc?rev=921426&view=rev
Log:
Remainder of fix for https://issues.apache.org/bugzilla/show_bug.cgi?id=48379
Allow session cookie name to be configured per context
With this option, the servlet 3 options and system property there were just too many places this was being configured so the system property option has been removed for Tomcat 7.
Modified:
tomcat/trunk/java/org/apache/catalina/Context.java
tomcat/trunk/java/org/apache/catalina/Globals.java
tomcat/trunk/java/org/apache/catalina/connector/CoyoteAdapter.java
tomcat/trunk/java/org/apache/catalina/core/ApplicationSessionCookieConfig.java
tomcat/trunk/java/org/apache/catalina/core/StandardContext.java
tomcat/trunk/webapps/docs/config/systemprops.xml
Modified: tomcat/trunk/java/org/apache/catalina/Context.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/Context.java?rev=921426&r1=921425&r2=921426&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/Context.java (original)
+++ tomcat/trunk/java/org/apache/catalina/Context.java Wed Mar 10 16:18:10 2010
@@ -177,6 +177,25 @@ public interface Context extends Contain
/**
+ * Gets the name to use for session cookies. Overrides any setting that
+ * may be specified by the application.
+ *
+ * @return The value of the default session cookie name or null if not
+ * specified
+ */
+ public String getSessionCookieName();
+
+
+ /**
+ * Sets the name to use for session cookies. Overrides any setting that
+ * may be specified by the application.
+ *
+ * @param sessionCookieName The name to use
+ */
+ public void setSessionCookieName(String sessionCookieName);
+
+
+ /**
* Gets the value of the use HttpOnly cookies for session cookies flag.
*
* @return <code>true</code> if the HttpOnly flag should be set on session
Modified: tomcat/trunk/java/org/apache/catalina/Globals.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/Globals.java?rev=921426&r1=921425&r2=921426&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/Globals.java (original)
+++ tomcat/trunk/java/org/apache/catalina/Globals.java Wed Mar 10 16:18:10 2010
@@ -268,9 +268,7 @@ public final class Globals {
* The name of the cookie used to pass the session identifier back
* and forth with the client.
*/
- public static final String SESSION_COOKIE_NAME =
- System.getProperty("org.apache.catalina.SESSION_COOKIE_NAME",
- "JSESSIONID");
+ public static final String SESSION_COOKIE_NAME = "JSESSIONID";
/**
Modified: tomcat/trunk/java/org/apache/catalina/connector/CoyoteAdapter.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/connector/CoyoteAdapter.java?rev=921426&r1=921425&r2=921426&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/connector/CoyoteAdapter.java (original)
+++ tomcat/trunk/java/org/apache/catalina/connector/CoyoteAdapter.java Wed Mar 10 16:18:10 2010
@@ -29,6 +29,7 @@ import org.apache.catalina.Globals;
import org.apache.catalina.Wrapper;
import org.apache.tomcat.util.res.StringManager;
import org.apache.catalina.comet.CometEvent;
+import org.apache.catalina.core.ApplicationSessionCookieConfig;
import org.apache.catalina.core.AsyncContextImpl;
import org.apache.catalina.util.ServerInfo;
import org.apache.catalina.util.URLEncoder;
@@ -722,9 +723,12 @@ public class CoyoteAdapter implements Ad
if (count <= 0)
return;
+ String sessionCookieName =
+ ApplicationSessionCookieConfig.getSessionCookieName(context);
+
for (int i = 0; i < count; i++) {
ServerCookie scookie = serverCookies.getCookie(i);
- if (scookie.getName().equals(Globals.SESSION_COOKIE_NAME)) {
+ if (scookie.getName().equals(sessionCookieName)) {
// Override anything requested in the URL
if (!request.isRequestedSessionIdFromCookie()) {
// Accept only the first session id cookie
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=921426&r1=921425&r2=921426&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/core/ApplicationSessionCookieConfig.java (original)
+++ tomcat/trunk/java/org/apache/catalina/core/ApplicationSessionCookieConfig.java Wed Mar 10 16:18:10 2010
@@ -122,11 +122,7 @@ public class ApplicationSessionCookieCon
// 2. Values from SessionCookieConfig
// 3. Defaults
- String cookieName = scc.getName();
- if (cookieName == null) {
- cookieName = Globals.SESSION_COOKIE_NAME;
- }
- Cookie cookie = new Cookie(cookieName, sessionId);
+ Cookie cookie = new Cookie(getSessionCookieName(context), sessionId);
// Just apply the defaults.
cookie.setMaxAge(scc.getMaxAge());
@@ -162,4 +158,33 @@ public class ApplicationSessionCookieCon
return cookie;
}
+
+
+ /**
+ * Determine the name to use for the session cookie for the provided
+ * context.
+ * @param context
+ */
+ public static String getSessionCookieName(Context context) {
+
+ // Priority is:
+ // 1. Cookie name defined in context
+ // 2. Cookie name configured for app
+ // 3. Default defined by spec
+ if (context != null) {
+ String cookieName = context.getSessionCookieName();
+ if (cookieName != null && cookieName.length() > 0) {
+ return cookieName;
+ }
+
+ SessionCookieConfig scc =
+ context.getServletContext().getSessionCookieConfig();
+ cookieName = scc.getName();
+ if (cookieName != null && cookieName.length() > 0) {
+ return cookieName;
+ }
+ }
+
+ return Globals.SESSION_COOKIE_NAME;
+ }
}
Modified: tomcat/trunk/java/org/apache/catalina/core/StandardContext.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/StandardContext.java?rev=921426&r1=921425&r2=921426&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/core/StandardContext.java (original)
+++ tomcat/trunk/java/org/apache/catalina/core/StandardContext.java Wed Mar 10 16:18:10 2010
@@ -718,6 +718,13 @@ public class StandardContext
/**
+ * The name to use for session cookies. <code>null</code> indicates that
+ * the name is controlled by the application.
+ */
+ private String sessionCookieName;
+
+
+ /**
* The flag that indicates that session cookies should use HttpOnly
*/
private boolean useHttpOnly = true;
@@ -1262,6 +1269,33 @@ public class StandardContext
}
+
+ /**
+ * Gets the name to use for session cookies. Overrides any setting that
+ * may be specified by the application.
+ *
+ * @return The value of the default session cookie name or null if not
+ * specified
+ */
+ public String getSessionCookieName() {
+ return sessionCookieName;
+ }
+
+
+ /**
+ * Sets the name to use for session cookies. Overrides any setting that
+ * may be specified by the application.
+ *
+ * @param sessionCookieName The name to use
+ */
+ public void setSessionCookieName(String sessionCookieName) {
+ String oldSessionCookieName = this.sessionCookieName;
+ this.sessionCookieName = sessionCookieName;
+ support.firePropertyChange("sessionCookieName",
+ oldSessionCookieName, sessionCookieName);
+ }
+
+
/**
* Gets the value of the use HttpOnly cookies for session cookies flag.
*
Modified: tomcat/trunk/webapps/docs/config/systemprops.xml
URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/config/systemprops.xml?rev=921426&r1=921425&r2=921426&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/config/systemprops.xml (original)
+++ tomcat/trunk/webapps/docs/config/systemprops.xml Wed Mar 10 16:18:10 2010
@@ -336,13 +336,6 @@
<properties>
- <property name="org.apache.catalina.SESSION_COOKIE_NAME">
- <p>An alternative name for the session cookie. Defaults to
- <code>JSESSIONID</code>. Note that the Servlet specification requires
- this to be <code>JSESSIONID</code>. You should not rely on being able to
- change this.</p>
- </property>
-
<property name="org.apache.catalina.SESSION_PARAMETER_NAME">
<p>An alternative name for the session path parameter. Defaults to
<code>jsessionid</code>. Note that the Servlet specification requires
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org