[Checkins] SVN: zope.session/trunk/ Add an ability to set domain for identification cookies in CookieClientIdManager.

Dan Korostelev nadako at gmail.com
Tue Feb 17 13:00:25 EST 2009


Log message for revision 96645:
  Add an ability to set domain for identification cookies in CookieClientIdManager.

Changed:
  U   zope.session/trunk/CHANGES.txt
  U   zope.session/trunk/src/zope/session/http.py

-=-
Modified: zope.session/trunk/CHANGES.txt
===================================================================
--- zope.session/trunk/CHANGES.txt	2009-02-17 16:46:22 UTC (rev 96644)
+++ zope.session/trunk/CHANGES.txt	2009-02-17 18:00:24 UTC (rev 96645)
@@ -4,6 +4,10 @@
 3.8.1 (unreleased)
 ------------------
 
+- Add an ability to set cookie effective domain for CookieClientIdManager.
+  This is useful for simple cases when you have your application set up on
+  one domain and you want your identification cookie be active for subdomains.
+
 - Python 2.6 compatibility change. Encode strings before calling hmac.new()
   as the function no longer accepts the unicode() type.
 

Modified: zope.session/trunk/src/zope/session/http.py
===================================================================
--- zope.session/trunk/src/zope/session/http.py	2009-02-17 16:46:22 UTC (rev 96644)
+++ zope.session/trunk/src/zope/session/http.py	2009-02-17 18:00:24 UTC (rev 96645)
@@ -92,6 +92,23 @@
             default=False,
             )
 
+    domain = schema.TextLine(
+            title=_('Effective domain'),
+            description=_(
+                "An identification cookie can be restricted to a specific domain "
+                "using this option. This option sets the ``domain`` attribute "
+                "for the cookie header. It is useful for setting one "
+                "identification cookie for multiple subdomains. So if this "
+                "option is set to ``.example.org``, the cookie will be available "
+                "for subdomains like ``yourname.example.org``. "
+                "Note that if you set this option to some domain, the identification "
+                "cookie won't be available for other domains, so, for example "
+                "you won't be able to login using the SessionCredentials plugin "
+                "via another domain."
+                ),
+            required=False,
+            )
+
     secure = schema.Bool(
         title=_('Request Secure communication'),
         required=False,
@@ -113,6 +130,7 @@
     cookieLifetime = FieldProperty(ICookieClientIdManager['cookieLifetime'])
     secure = FieldProperty(ICookieClientIdManager['secure'])
     postOnly = FieldProperty(ICookieClientIdManager['postOnly'])
+    domain = FieldProperty(ICookieClientIdManager['domain'])
 
     def __init__(self):
         self.namespace = "zope3_cs_%x" % (int(time.time()) - 1000000000)
@@ -395,7 +413,13 @@
           >>> print request.response.getCookie(bim.namespace)
           {'path': '/', 'secure': True, 'value': '1234'}
 
+        If the domain is specified, it will be set as a cookie attribute.
 
+          >>> bim.domain = u'.example.org'
+          >>> bim.setRequestId(request, '1234')
+          >>> print request.response.getCookie(bim.namespace)
+          {'path': '/', 'domain': u'.example.org', 'secure': True, 'value': '1234'}
+
         When the cookie is set, cache headers are added to the
         response to try to prevent the cookie header from being cached:
 
@@ -434,6 +458,9 @@
         if self.secure:
             options['secure'] = True
 
+        if self.domain:
+            options['domain'] = self.domain
+
         response.setCookie(
             self.namespace, id,
             path=request.getApplicationURL(path_only=True),



More information about the Checkins mailing list