[CalendarServer-changes] [5222] CalendarServer/trunk/calendarserver/provision
source_changes at macosforge.org
source_changes at macosforge.org
Fri Feb 26 17:24:05 PST 2010
Revision: 5222
http://trac.macosforge.org/projects/calendarserver/changeset/5222
Author: sagen at apple.com
Date: 2010-02-26 17:24:03 -0800 (Fri, 26 Feb 2010)
Log Message:
-----------
Only do wiki auth lookup once per request; locateChild( ) gets called multiple times per request, so we're needlessly contacting the wiki server.
Modified Paths:
--------------
CalendarServer/trunk/calendarserver/provision/root.py
CalendarServer/trunk/calendarserver/provision/test/test_root.py
Modified: CalendarServer/trunk/calendarserver/provision/root.py
===================================================================
--- CalendarServer/trunk/calendarserver/provision/root.py 2010-02-26 20:06:22 UTC (rev 5221)
+++ CalendarServer/trunk/calendarserver/provision/root.py 2010-02-27 01:24:03 UTC (rev 5222)
@@ -167,44 +167,48 @@
# server for the corresponding record name. If that maps to a
# principal, assign that to authnuser.
- wikiConfig = config.Authentication.Wiki
- cookies = request.headers.getHeader("cookie")
- if wikiConfig["Enabled"] and cookies is not None:
- for cookie in cookies:
- if cookie.name == wikiConfig["Cookie"]:
- token = cookie.value
- break
- else:
- token = None
+ if not hasattr(request, "checkedWiki"):
+ # Only do this once per request
+ request.checkedWiki = True
- if token is not None and token != "unauthenticated":
- log.debug("Wiki sessionID cookie value: %s" % (token,))
- proxy = Proxy(wikiConfig["URL"])
- try:
- username = (yield proxy.callRemote(wikiConfig["UserMethod"], token))
- except Exception, e:
- log.error("Failed to look up wiki token (%s)" % (e,))
- username = None
+ wikiConfig = config.Authentication.Wiki
+ cookies = request.headers.getHeader("cookie")
+ if wikiConfig["Enabled"] and cookies is not None:
+ for cookie in cookies:
+ if cookie.name == wikiConfig["Cookie"]:
+ token = cookie.value
+ break
+ else:
+ token = None
- if username is not None:
- log.debug("Wiki lookup returned user: %s" % (username,))
- principal = None
- directory = request.site.resource.getDirectory()
- record = directory.recordWithShortName("users", username)
- log.debug("Wiki user record for user %s : %s" % (username, record))
- if record:
- # Note: record will be None if it's a /Local/Default user
- for collection in self.principalCollections():
- principal = collection.principalForRecord(record)
- if principal is not None:
- break
+ if token is not None and token != "unauthenticated":
+ log.debug("Wiki sessionID cookie value: %s" % (token,))
+ proxy = Proxy(wikiConfig["URL"])
+ try:
+ username = (yield proxy.callRemote(wikiConfig["UserMethod"], token))
+ except Exception, e:
+ log.error("Failed to look up wiki token (%s)" % (e,))
+ username = None
- if principal:
- log.debug("Found wiki principal and setting authnuser and authzuser")
- request.authzUser = request.authnUser = davxml.Principal(
- davxml.HRef.fromString("/principals/__uids__/%s/" % (record.guid,))
- )
+ if username is not None:
+ log.debug("Wiki lookup returned user: %s" % (username,))
+ principal = None
+ directory = request.site.resource.getDirectory()
+ record = directory.recordWithShortName("users", username)
+ log.debug("Wiki user record for user %s : %s" % (username, record))
+ if record:
+ # Note: record will be None if it's a /Local/Default user
+ for collection in self.principalCollections():
+ principal = collection.principalForRecord(record)
+ if principal is not None:
+ break
+ if principal:
+ log.debug("Wiki-authenticated principal %s being assigned to authnUser" % (record.guid,))
+ request.authnUser = davxml.Principal(
+ davxml.HRef.fromString("/principals/__uids__/%s/" % (record.guid,))
+ )
+
# We don't want the /inbox resource to pay attention to SACLs because
# we just want it to use the hard-coded ACL for the imip reply user.
# The /timezones resource is used by the wiki web calendar, so open
@@ -225,6 +229,7 @@
else:
wikiName = segments[2][5:]
if wikiName:
+ log.debug("Wiki principal %s being assigned to authzUser" % (wikiName,))
request.authzUser = davxml.Principal(
davxml.HRef.fromString("/principals/wikis/%s/" % (wikiName,))
)
Modified: CalendarServer/trunk/calendarserver/provision/test/test_root.py
===================================================================
--- CalendarServer/trunk/calendarserver/provision/test/test_root.py 2010-02-26 20:06:22 UTC (rev 5221)
+++ CalendarServer/trunk/calendarserver/provision/test/test_root.py 2010-02-27 01:24:03 UTC (rev 5222)
@@ -367,3 +367,18 @@
d = self.send(request, gotResponse1)
return d
+
+class WikiTests(RootTests):
+
+ @inlineCallbacks
+ def test_oneTime(self):
+ """
+ Make sure wiki auth lookup is only done once per request;
+ request.checkedWiki will be set to True
+ """
+
+ request = SimpleRequest(self.site, "GET", "/principals/")
+
+ resrc, segments = (yield maybeDeferred(self.root.locateChild, request, ['principals']))
+ resrc, segments = (yield maybeDeferred(resrc.locateChild, request, ['principals']))
+ self.assertTrue(request.checkedWiki)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20100226/e7a58bf1/attachment.html>
More information about the calendarserver-changes
mailing list