tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r894450 - in /tomcat/trunk/java/org/apache/catalina: deploy/SessionConfig.java startup/LocalStrings.properties startup/WebRuleSet.java startup/WebXml.java
Date Tue, 29 Dec 2009 17:33:23 GMT
Author: markt
Date: Tue Dec 29 17:33:22 2009
New Revision: 894450

URL: http://svn.apache.org/viewvc?rev=894450&view=rev
Log:
Add support for configuring session cookies and session tracking in web.xml

Added:
    tomcat/trunk/java/org/apache/catalina/deploy/SessionConfig.java
Modified:
    tomcat/trunk/java/org/apache/catalina/startup/LocalStrings.properties
    tomcat/trunk/java/org/apache/catalina/startup/WebRuleSet.java
    tomcat/trunk/java/org/apache/catalina/startup/WebXml.java

Added: tomcat/trunk/java/org/apache/catalina/deploy/SessionConfig.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/deploy/SessionConfig.java?rev=894450&view=auto
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/deploy/SessionConfig.java (added)
+++ tomcat/trunk/java/org/apache/catalina/deploy/SessionConfig.java Tue Dec 29 17:33:22 2009
@@ -0,0 +1,105 @@
+/*
+ * 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.catalina.deploy;
+
+import java.util.EnumSet;
+
+import javax.servlet.SessionTrackingMode;
+
+/**
+ * Representation of a session configuration element for a web application,
+ * as represented in a <code>&lt;session-config&gt;</code> element in
the
+ * deployment descriptor.
+ */
+public class SessionConfig {
+    private Integer sessionTimeout;
+    private String cookieName;
+    private String cookieDomain;
+    private String cookiePath;
+    private String cookieComment;
+    private Boolean cookieHttpOnly;
+    private Boolean cookieSecure;
+    private Integer cookieMaxAge;
+    private EnumSet<SessionTrackingMode> sessionTrackingModes =
+        EnumSet.noneOf(SessionTrackingMode.class);
+    
+    public Integer getSessionTimeout() {
+        return sessionTimeout;
+    }
+    public void setSessionTimeout(String sessionTimeout) {
+        this.sessionTimeout = Integer.valueOf(sessionTimeout);
+    }
+    
+    public String getCookieName() {
+        return cookieName;
+    }
+    public void setCookieName(String cookieName) {
+        this.cookieName = cookieName;
+    }
+    
+    public String getCookieDomain() {
+        return cookieDomain;
+    }
+    public void setCookieDomain(String cookieDomain) {
+        this.cookieDomain = cookieDomain;
+    }
+    
+    public String getCookiePath() {
+        return cookiePath;
+    }
+    public void setCookiePath(String cookiePath) {
+        this.cookiePath = cookiePath;
+    }
+    
+    public String getCookieComment() {
+        return cookieComment;
+    }
+    public void setCookieComment(String cookieComment) {
+        this.cookieComment = cookieComment;
+    }
+    
+    public Boolean getCookieHttpOnly() {
+        return cookieHttpOnly;
+    }
+    public void setCookieHttpOnly(String cookieHttpOnly) {
+        this.cookieHttpOnly = Boolean.valueOf(cookieHttpOnly);
+    }
+    
+    public Boolean getCookieSecure() {
+        return cookieSecure;
+    }
+    public void setCookieSecure(String cookieSecure) {
+        this.cookieSecure = Boolean.valueOf(cookieSecure);
+    }
+    
+    public Integer getCookieMaxAge() {
+        return cookieMaxAge;
+    }
+    public void setCookieMaxAge(String cookieMaxAge) {
+        this.cookieMaxAge = Integer.valueOf(cookieMaxAge);
+    }
+    
+    public EnumSet<SessionTrackingMode> getSessionTrackingModes() {
+        return sessionTrackingModes;
+    }
+    public void addSessionTrackingMode(String sessionTrackingMode) {
+        sessionTrackingModes.add(
+                SessionTrackingMode.valueOf(sessionTrackingMode));
+    }
+    
+}

Modified: tomcat/trunk/java/org/apache/catalina/startup/LocalStrings.properties
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/startup/LocalStrings.properties?rev=894450&r1=894449&r2=894450&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/startup/LocalStrings.properties (original)
+++ tomcat/trunk/java/org/apache/catalina/startup/LocalStrings.properties Tue Dec 29 17:33:22
2009
@@ -130,6 +130,14 @@
 webXml.mergeConflictOrder=Fragment relative ordering contains circular references. Thsi can
be resolved by using absolute ordering in web.xml.
 webXml.mergeConflictResource=The Resource [{0}] was defined inconsistently in multiple fragments
including fragment with name [{1}] located at [{2}]
 webXml.mergeConflictFilter=The Servlet [{0}] was defined inconsistently in multiple fragments
including fragment with name [{1}] located at [{2}]
+webXml.mergeConflictSessionCookieName=The session cookie name was defined inconsistently
in multiple fragments with different values including fragment with name [{0}] located at
[{1}]
+webXml.mergeConflictSessionCookieDomain=The session cookie domain was defined inconsistently
in multiple fragments with different values including fragment with name [{0}] located at
[{1}]
+webXml.mergeConflictSessionCookiePath=The session cookie path was defined inconsistently
in multiple fragments with different values including fragment with name [{0}] located at
[{1}]
+webXml.mergeConflictSessionCookieComment=The session cookie comment was defined inconsistently
in multiple fragments with different values including fragment with name [{0}] located at
[{1}]
+webXml.mergeConflictSessionCookieHttpOnly=The session cookie http-only flag was defined inconsistently
in multiple fragments with different values including fragment with name [{0}] located at
[{1}]
+webXml.mergeConflictSessionCookieSecure=The session cookie secure flag was defined inconsistently
in multiple fragments with different values including fragment with name [{0}] located at
[{1}]
+webXml.mergeConflictSessionCookieMaxAge=The session cookie max-age was defined inconsistently
in multiple fragments with different values including fragment with name [{0}] located at
[{1}]
 webXml.mergeConflictSessionTimeout=The session timeout was defined inconsistently in multiple
fragments with different values including fragment with name [{0}] located at [{1}]
+webXml.mergeConflictSessionTrackingMode=The session tracking modes were defined inconsistently
in multiple fragments including fragment with name [{0}] located at [{1}]
 webXml.mergeConflictString=The [{0}] with name [{1}] was defined inconsistently in multiple
fragments including fragment with name [{2}] located at [{3}]
 webXml.multipleOther=Multiple others entries in ordering

Modified: tomcat/trunk/java/org/apache/catalina/startup/WebRuleSet.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/startup/WebRuleSet.java?rev=894450&r1=894449&r2=894450&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/startup/WebRuleSet.java (original)
+++ tomcat/trunk/java/org/apache/catalina/startup/WebRuleSet.java Tue Dec 29 17:33:22 2009
@@ -400,11 +400,29 @@
         digester.addCallParam(fullPrefix + "/servlet-mapping/servlet-name", 1);
         digester.addRule(fullPrefix + "/servlet-mapping/url-pattern", new CallParamMultiRule(0));
 
-        digester.addRule(fullPrefix + "/session-config",
-                         sessionConfig);
-        
+        digester.addRule(fullPrefix + "/session-config", sessionConfig);
+        digester.addObjectCreate(fullPrefix + "/session-config",
+                                 "org.apache.catalina.deploy.SessionConfig");
+        digester.addSetNext(fullPrefix + "/session-config", "setSessionConfig",
+                            "org.apache.catalina.deploy.SessionConfig");
         digester.addCallMethod(fullPrefix + "/session-config/session-timeout",
                                "setSessionTimeout", 0);
+        digester.addCallMethod(fullPrefix + "/session-config/cookie-config/name",
+                               "setCookieName", 0);
+        digester.addCallMethod(fullPrefix + "/session-config/cookie-config/domain",
+                               "setCookieDomain", 0);
+        digester.addCallMethod(fullPrefix + "/session-config/cookie-config/path",
+                               "setCookiePath", 0);
+        digester.addCallMethod(fullPrefix + "/session-config/cookie-config/comment",
+                               "setCookieComment", 0);
+        digester.addCallMethod(fullPrefix + "/session-config/cookie-config/http-only",
+                               "setCookieHttpOnly", 0);
+        digester.addCallMethod(fullPrefix + "/session-config/cookie-config/secure",
+                               "setCookieSecure", 0);
+        digester.addCallMethod(fullPrefix + "/session-config/cookie-config/max-age",
+                               "setCookieMaxAge", 0);
+        digester.addCallMethod(fullPrefix + "/session-config/tracking-mode",
+                               "addSessionTrackingMode", 0);
 
         // Taglibs pre Servlet 2.4
         digester.addRule(fullPrefix + "/taglib", new TaglibLocationRule(false));

Modified: tomcat/trunk/java/org/apache/catalina/startup/WebXml.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/startup/WebXml.java?rev=894450&r1=894449&r2=894450&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/startup/WebXml.java (original)
+++ tomcat/trunk/java/org/apache/catalina/startup/WebXml.java Tue Dec 29 17:33:22 2009
@@ -19,6 +19,7 @@
 package org.apache.catalina.startup;
 
 import java.net.URL;
+import java.util.EnumSet;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
@@ -30,6 +31,8 @@
 import java.util.Set;
 
 import javax.servlet.MultipartConfigElement;
+import javax.servlet.SessionCookieConfig;
+import javax.servlet.SessionTrackingMode;
 
 import org.apache.catalina.Context;
 import org.apache.catalina.Wrapper;
@@ -54,6 +57,7 @@
 import org.apache.catalina.deploy.SecurityConstraint;
 import org.apache.catalina.deploy.SecurityRoleRef;
 import org.apache.catalina.deploy.ServletDef;
+import org.apache.catalina.deploy.SessionConfig;
 import org.apache.tomcat.util.res.StringManager;
 
 /**
@@ -232,13 +236,13 @@
     }
     public Map<String,String> getServletMappings() { return servletMappings; }
     
-    // session-config/session-timeout
+    // session-config
     // Digester will check there is only one of these
-    private Integer sessionTimeout = null;
-    public void setSessionTimeout(String timeout) {
-        sessionTimeout = Integer.valueOf(timeout);
+    private SessionConfig sessionConfig = new SessionConfig();
+    public void setSessionConfig(SessionConfig sessionConfig) {
+        this.sessionConfig = sessionConfig;
     }
-    public Integer getSessionTimeout() { return sessionTimeout; }
+    public SessionConfig getSessionConfig() { return sessionConfig; }
     
     // mime-mapping
     private Map<String,String> mimeMappings = new HashMap<String,String>();
@@ -620,12 +624,28 @@
         }
         sb.append('\n');
         
-        if (sessionTimeout != null) {
+        if (sessionConfig != null) {
             sb.append("  <session-config>\n");
             appendElement(sb, INDENT4, "session-timeout",
-                    sessionTimeout.toString());
-            // TODO cookie-config
-            // TODO tracking-mode
+                    sessionConfig.getSessionTimeout());
+            sb.append("    <cookie-config>\n");
+            appendElement(sb, INDENT6, "name", sessionConfig.getCookieName());
+            appendElement(sb, INDENT6, "domain",
+                    sessionConfig.getCookieDomain());
+            appendElement(sb, INDENT6, "path", sessionConfig.getCookiePath());
+            appendElement(sb, INDENT6, "comment",
+                    sessionConfig.getCookieComment());
+            appendElement(sb, INDENT6, "http-only",
+                    sessionConfig.getCookieHttpOnly());
+            appendElement(sb, INDENT6, "secure",
+                    sessionConfig.getCookieSecure());
+            appendElement(sb, INDENT6, "max-age",
+                    sessionConfig.getCookieMaxAge());
+            sb.append("    </cookie-config>\n");
+            for (SessionTrackingMode stm :
+                    sessionConfig.getSessionTrackingModes()) {
+                appendElement(sb, INDENT4, "tracking-mode", stm.name());
+            }
             sb.append("  </session-config>\n\n");
         }
         
@@ -1148,8 +1168,30 @@
         for (String pattern : servletMappings.keySet()) {
             context.addServletMapping(pattern, servletMappings.get(pattern));
         }
-        if (sessionTimeout != null) {
-            context.setSessionTimeout(sessionTimeout.intValue());
+        if (sessionConfig != null) {
+            if (sessionConfig.getSessionTimeout() != null) {
+                context.setSessionTimeout(
+                        sessionConfig.getSessionTimeout().intValue());
+            }
+            SessionCookieConfig scc =
+                context.getServletContext().getSessionCookieConfig();
+            scc.setName(sessionConfig.getCookieName());
+            scc.setDomain(sessionConfig.getCookieDomain());
+            scc.setPath(sessionConfig.getCookiePath());
+            scc.setComment(sessionConfig.getCookieComment());
+            if (sessionConfig.getCookieHttpOnly() != null) {
+                scc.setHttpOnly(sessionConfig.getCookieHttpOnly().booleanValue());
+            }
+            if (sessionConfig.getCookieSecure() != null) {
+                scc.setSecure(sessionConfig.getCookieSecure().booleanValue());
+            }
+            if (sessionConfig.getCookieMaxAge() != null) {
+                scc.setMaxAge(sessionConfig.getCookieMaxAge().intValue());
+            }
+            if (sessionConfig.getSessionTrackingModes().size() > 0) {
+                context.getServletContext().setSessionTrackingModes(
+                        sessionConfig.getSessionTrackingModes());
+            }
         }
         for (String uri : taglibs.keySet()) {
             context.addTaglib(uri, taglibs.get(uri));
@@ -1327,9 +1369,9 @@
                     }
                 }
             }
+            loginConfig = tempLoginConfig;
         }
 
-
         for (WebXml fragment : fragments) {
             if (!mergeResourceMap(fragment.getMessageDestinationRefs(), messageDestinationRefs,
                     temp.getMessageDestinationRefs(), mergeInjectionFlags, fragment)) {
@@ -1431,12 +1473,15 @@
         }
         servlets.putAll(temp.getServlets());
         
-        if (sessionTimeout == null) {
+        if (sessionConfig.getSessionTimeout() == null) {
             for (WebXml fragment : fragments) {
-                Integer value = fragment.getSessionTimeout(); 
+                Integer value = fragment.getSessionConfig().getSessionTimeout();
                 if (value != null) {
-                    if (temp.getSessionTimeout() == null) {
-                        temp.setSessionTimeout(value.toString());
+                    if (temp.getSessionConfig().getSessionTimeout() == null) {
+                        temp.getSessionConfig().setSessionTimeout(value.toString());
+                    } else if (value.equals(
+                            temp.getSessionConfig().getSessionTimeout())) {
+                        // Fragments use same value - no conflict
                     } else {
                         log.error(sm.getString(
                                 "webXml.mergeConflictSessionTimeout",
@@ -1446,9 +1491,181 @@
                     }
                 }
             }
-            sessionTimeout = temp.getSessionTimeout();
+            sessionConfig.setSessionTimeout(
+                    temp.getSessionConfig().getSessionTimeout().toString());
+        }
+        
+        if (sessionConfig.getCookieName() == null) {
+            for (WebXml fragment : fragments) {
+                String value = fragment.getSessionConfig().getCookieName();
+                if (value != null) {
+                    if (temp.getSessionConfig().getCookieName() == null) {
+                        temp.getSessionConfig().setCookieName(value);
+                    } else if (value.equals(
+                            temp.getSessionConfig().getCookieName())) {
+                        // Fragments use same value - no conflict
+                    } else {
+                        log.error(sm.getString(
+                                "webXml.mergeConflictSessionCookieName",
+                                fragment.getName(),
+                                fragment.getURL()));
+                        return false;
+                    }
+                }
+            }
+            sessionConfig.setCookieName(
+                    temp.getSessionConfig().getCookieName());
+        }
+        if (sessionConfig.getCookieDomain() == null) {
+            for (WebXml fragment : fragments) {
+                String value = fragment.getSessionConfig().getCookieDomain();
+                if (value != null) {
+                    if (temp.getSessionConfig().getCookieDomain() == null) {
+                        temp.getSessionConfig().setCookieDomain(value);
+                    } else if (value.equals(
+                            temp.getSessionConfig().getCookieDomain())) {
+                        // Fragments use same value - no conflict
+                    } else {
+                        log.error(sm.getString(
+                                "webXml.mergeConflictSessionCookieDomain",
+                                fragment.getName(),
+                                fragment.getURL()));
+                        return false;
+                    }
+                }
+            }
+            sessionConfig.setCookieDomain(
+                    temp.getSessionConfig().getCookieDomain());
+        }
+        if (sessionConfig.getCookiePath() == null) {
+            for (WebXml fragment : fragments) {
+                String value = fragment.getSessionConfig().getCookiePath();
+                if (value != null) {
+                    if (temp.getSessionConfig().getCookiePath() == null) {
+                        temp.getSessionConfig().setCookiePath(value);
+                    } else if (value.equals(
+                            temp.getSessionConfig().getCookiePath())) {
+                        // Fragments use same value - no conflict
+                    } else {
+                        log.error(sm.getString(
+                                "webXml.mergeConflictSessionCookiePath",
+                                fragment.getName(),
+                                fragment.getURL()));
+                        return false;
+                    }
+                }
+            }
+            sessionConfig.setCookiePath(
+                    temp.getSessionConfig().getCookiePath());
+        }
+        if (sessionConfig.getCookieComment() == null) {
+            for (WebXml fragment : fragments) {
+                String value = fragment.getSessionConfig().getCookieComment();
+                if (value != null) {
+                    if (temp.getSessionConfig().getCookieComment() == null) {
+                        temp.getSessionConfig().setCookieComment(value);
+                    } else if (value.equals(
+                            temp.getSessionConfig().getCookieComment())) {
+                        // Fragments use same value - no conflict
+                    } else {
+                        log.error(sm.getString(
+                                "webXml.mergeConflictSessionCookieComment",
+                                fragment.getName(),
+                                fragment.getURL()));
+                        return false;
+                    }
+                }
+            }
+            sessionConfig.setCookieComment(
+                    temp.getSessionConfig().getCookieComment());
+        }
+        if (sessionConfig.getCookieHttpOnly() == null) {
+            for (WebXml fragment : fragments) {
+                Boolean value = fragment.getSessionConfig().getCookieHttpOnly();
+                if (value != null) {
+                    if (temp.getSessionConfig().getCookieHttpOnly() == null) {
+                        temp.getSessionConfig().setCookieHttpOnly(value.toString());
+                    } else if (value.equals(
+                            temp.getSessionConfig().getCookieHttpOnly())) {
+                        // Fragments use same value - no conflict
+                    } else {
+                        log.error(sm.getString(
+                                "webXml.mergeConflictSessionCookieHttpOnly",
+                                fragment.getName(),
+                                fragment.getURL()));
+                        return false;
+                    }
+                }
+            }
+            sessionConfig.setCookieHttpOnly(
+                    temp.getSessionConfig().getCookieHttpOnly().toString());
+        }
+        if (sessionConfig.getCookieSecure() == null) {
+            for (WebXml fragment : fragments) {
+                Boolean value = fragment.getSessionConfig().getCookieSecure();
+                if (value != null) {
+                    if (temp.getSessionConfig().getCookieSecure() == null) {
+                        temp.getSessionConfig().setCookieSecure(value.toString());
+                    } else if (value.equals(
+                            temp.getSessionConfig().getCookieSecure())) {
+                        // Fragments use same value - no conflict
+                    } else {
+                        log.error(sm.getString(
+                                "webXml.mergeConflictSessionCookieSecure",
+                                fragment.getName(),
+                                fragment.getURL()));
+                        return false;
+                    }
+                }
+            }
+            sessionConfig.setCookieSecure(
+                    temp.getSessionConfig().getCookieSecure().toString());
+        }
+        if (sessionConfig.getCookieMaxAge() == null) {
+            for (WebXml fragment : fragments) {
+                Integer value = fragment.getSessionConfig().getCookieMaxAge();
+                if (value != null) {
+                    if (temp.getSessionConfig().getCookieMaxAge() == null) {
+                        temp.getSessionConfig().setCookieMaxAge(value.toString());
+                    } else if (value.equals(
+                            temp.getSessionConfig().getCookieMaxAge())) {
+                        // Fragments use same value - no conflict
+                    } else {
+                        log.error(sm.getString(
+                                "webXml.mergeConflictSessionCookieMaxAge",
+                                fragment.getName(),
+                                fragment.getURL()));
+                        return false;
+                    }
+                }
+            }
+            sessionConfig.setCookieMaxAge(
+                    temp.getSessionConfig().getCookieMaxAge().toString());
         }
 
+        if (sessionConfig.getSessionTrackingModes().size() == 0) {
+            for (WebXml fragment : fragments) {
+                EnumSet<SessionTrackingMode> value =
+                    fragment.getSessionConfig().getSessionTrackingModes();
+                if (value.size() > 0) {
+                    if (temp.getSessionConfig().getSessionTrackingModes().size() == 0) {
+                        temp.getSessionConfig().getSessionTrackingModes().addAll(value);
+                    } else if (value.equals(
+                            temp.getSessionConfig().getSessionTrackingModes())) {
+                        // Fragments use same value - no conflict
+                    } else {
+                        log.error(sm.getString(
+                                "webXml.mergeConflictSessionTrackingMode",
+                                fragment.getName(),
+                                fragment.getURL()));
+                        return false;
+                    }
+                }
+            }
+            sessionConfig.setSessionTimeout(
+                    temp.getSessionConfig().getSessionTimeout().toString());
+        }
+        
         for (WebXml fragment : fragments) {
             if (!mergeMap(fragment.getTaglibs(), taglibs,
                     temp.getTaglibs(), fragment, "Taglibs")) {



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


Mime
View raw message