Author: violetagg Date: Wed May 15 12:15:43 2013 New Revision: 1482782 URL: http://svn.apache.org/r1482782 Log: Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=54974 Merged revision 1482720 from tomcat/trunk: SessionCookieConfig.setXXX methods will throw IllegalStateException if the ServletContext from which this SessionCookieConfig was acquired has already been initialized.
Added: tomcat/tc7.0.x/trunk/test/org/apache/catalina/core/TestApplicationSessionCookieConfig.java - copied unchanged from r1482720, tomcat/trunk/test/org/apache/catalina/core/TestApplicationSessionCookieConfig.java Modified: tomcat/tc7.0.x/trunk/ (props changed) tomcat/tc7.0.x/trunk/java/org/apache/catalina/core/ApplicationContext.java tomcat/tc7.0.x/trunk/java/org/apache/catalina/core/ApplicationSessionCookieConfig.java tomcat/tc7.0.x/trunk/java/org/apache/catalina/core/LocalStrings.properties tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml Propchange: tomcat/tc7.0.x/trunk/ ------------------------------------------------------------------------------ Merged /tomcat/trunk:r1482720 Modified: tomcat/tc7.0.x/trunk/java/org/apache/catalina/core/ApplicationContext.java URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/catalina/core/ApplicationContext.java?rev=1482782&r1=1482781&r2=1482782&view=diff ============================================================================== --- tomcat/tc7.0.x/trunk/java/org/apache/catalina/core/ApplicationContext.java (original) +++ tomcat/tc7.0.x/trunk/java/org/apache/catalina/core/ApplicationContext.java Wed May 15 12:15:43 2013 @@ -120,7 +120,8 @@ public class ApplicationContext public ApplicationContext(StandardContext context) { super(); this.context = context; - + this.sessionCookieConfig = new ApplicationSessionCookieConfig(context); + // Populate session tracking modes populateSessionTrackingModes(); } @@ -190,9 +191,8 @@ public class ApplicationContext /** * Session Cookie config */ - private SessionCookieConfig sessionCookieConfig = - new ApplicationSessionCookieConfig(); - + private SessionCookieConfig sessionCookieConfig; + /** * Session tracking modes */ Modified: tomcat/tc7.0.x/trunk/java/org/apache/catalina/core/ApplicationSessionCookieConfig.java URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/catalina/core/ApplicationSessionCookieConfig.java?rev=1482782&r1=1482781&r2=1482782&view=diff ============================================================================== --- tomcat/tc7.0.x/trunk/java/org/apache/catalina/core/ApplicationSessionCookieConfig.java (original) +++ tomcat/tc7.0.x/trunk/java/org/apache/catalina/core/ApplicationSessionCookieConfig.java Wed May 15 12:15:43 2013 @@ -21,10 +21,18 @@ import javax.servlet.SessionCookieConfig import javax.servlet.http.Cookie; import org.apache.catalina.Context; +import org.apache.catalina.LifecycleState; import org.apache.catalina.util.SessionConfig; +import org.apache.tomcat.util.res.StringManager; public class ApplicationSessionCookieConfig implements SessionCookieConfig { + /** + * The string manager for this package. + */ + private static final StringManager sm = StringManager + .getManager(Constants.Package); + private boolean httpOnly; private boolean secure; private int maxAge = -1; @@ -32,7 +40,12 @@ public class ApplicationSessionCookieCon private String domain; private String name; private String path; - + private StandardContext context; + + public ApplicationSessionCookieConfig(StandardContext context) { + this.context = context; + } + @Override public String getComment() { return comment; @@ -70,36 +83,71 @@ public class ApplicationSessionCookieCon @Override public void setComment(String comment) { + if (!context.getState().equals(LifecycleState.STARTING_PREP)) { + throw new IllegalStateException(sm.getString( + "applicationSessionCookieConfig.ise", "comment", + context.getPath())); + } this.comment = comment; } @Override public void setDomain(String domain) { + if (!context.getState().equals(LifecycleState.STARTING_PREP)) { + throw new IllegalStateException(sm.getString( + "applicationSessionCookieConfig.ise", "domain name", + context.getPath())); + } this.domain = domain; } @Override public void setHttpOnly(boolean httpOnly) { + if (!context.getState().equals(LifecycleState.STARTING_PREP)) { + throw new IllegalStateException(sm.getString( + "applicationSessionCookieConfig.ise", "HttpOnly", + context.getPath())); + } this.httpOnly = httpOnly; } @Override public void setMaxAge(int maxAge) { + if (!context.getState().equals(LifecycleState.STARTING_PREP)) { + throw new IllegalStateException(sm.getString( + "applicationSessionCookieConfig.ise", "max age", + context.getPath())); + } this.maxAge = maxAge; } @Override public void setName(String name) { + if (!context.getState().equals(LifecycleState.STARTING_PREP)) { + throw new IllegalStateException(sm.getString( + "applicationSessionCookieConfig.ise", "name", + context.getPath())); + } this.name = name; } @Override public void setPath(String path) { + if (!context.getState().equals(LifecycleState.STARTING_PREP)) { + throw new IllegalStateException(sm.getString( + "applicationSessionCookieConfig.ise", "path", + context.getPath())); + } this.path = path; } @Override public void setSecure(boolean secure) { + if (!context.getState().equals(LifecycleState.STARTING_PREP)) { + throw new IllegalStateException(sm.getString( + "applicationSessionCookieConfig.ise", "secure", + context.getPath())); + } this.secure = secure; } Modified: tomcat/tc7.0.x/trunk/java/org/apache/catalina/core/LocalStrings.properties URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/catalina/core/LocalStrings.properties?rev=1482782&r1=1482781&r2=1482782&view=diff ============================================================================== --- tomcat/tc7.0.x/trunk/java/org/apache/catalina/core/LocalStrings.properties (original) +++ tomcat/tc7.0.x/trunk/java/org/apache/catalina/core/LocalStrings.properties Wed May 15 12:15:43 2013 @@ -55,6 +55,7 @@ applicationResponse.badParent=Cannot loc applicationResponse.badResponse=Response is not a javax.servlet.ServletResponseWrapper applicationServletRegistration.setServletSecurity.iae=Null constraint specified for servlet [{0}] deployed to context with name [{1}] applicationServletRegistration.setServletSecurity.ise=Security constraints can't be added to servlet [{0}] deployed to context with name [{1}] as the context has already been initialised +applicationSessionCookieConfig.ise=Property {0} can not be added to SessionCookieConfig for context {1} as the context has been initialised aprListener.aprInit=The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: {0} aprListener.tcnInvalid=An incompatible version {0} of the APR based Apache Tomcat Native library is installed, while Tomcat requires version {1} aprListener.tcnVersion=An older version {0} of the APR based Apache Tomcat Native library is installed, while Tomcat recommends a minimum version of {1} Modified: tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml?rev=1482782&r1=1482781&r2=1482782&view=diff ============================================================================== --- tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml (original) +++ tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml Wed May 15 12:15:43 2013 @@ -74,6 +74,14 @@ Ensure that when auto deployment runs for a Host, it uses the latest values for copyXML, deployXML and unpackWARs. (markt) </fix> + <fix> + <bug>54974</bug>: Ensure that + <code>SessionCookieConfig#set<methods></code> + will throw <code>IllegalStateException</code> if the + <code>ServletContext</code> from which this + <code>SessionCookieConfig</code> was acquired has already been + initialized. (violetagg) + </fix> </changelog> </subsection> <subsection name="Jasper"> @@ -81,8 +89,8 @@ <fix> <bug>54968</bug>: Return the correct version number (2.2) of the JSP specification that is supported by the JSP engine when - javax.servlet.jsp.JspEngineInfo#getSpecificationVersion() is invoked. - (violetagg) + <code>javax.servlet.jsp.JspEngineInfo#getSpecificationVersion()</code> + is invoked. (violetagg) </fix> </changelog> </subsection> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org