[CalendarServer-changes] [11551] CalendarServer/trunk/calendarserver

source_changes at macosforge.org source_changes at macosforge.org
Tue Jul 23 17:40:01 PDT 2013


Revision: 11551
          http://trac.calendarserver.org//changeset/11551
Author:   sagen at apple.com
Date:     2013-07-23 17:40:00 -0700 (Tue, 23 Jul 2013)
Log Message:
-----------
Use the GUID returned from wiki auth instead of the record name, because uniqueness.

Modified Paths:
--------------
    CalendarServer/trunk/calendarserver/platform/darwin/wiki.py
    CalendarServer/trunk/calendarserver/provision/root.py

Modified: CalendarServer/trunk/calendarserver/platform/darwin/wiki.py
===================================================================
--- CalendarServer/trunk/calendarserver/platform/darwin/wiki.py	2013-07-23 21:42:57 UTC (rev 11550)
+++ CalendarServer/trunk/calendarserver/platform/darwin/wiki.py	2013-07-24 00:40:00 UTC (rev 11551)
@@ -28,15 +28,15 @@
 log = Logger()
 
 @inlineCallbacks
-def usernameForAuthToken(token, host="localhost", port=80):
+def guidForAuthToken(token, host="localhost", port=80):
     """
     Send a GET request to the web auth service to retrieve the user record
-    name associated with the provided auth token.
+    guid associated with the provided auth token.
 
     @param token: An auth token, usually passed in via cookie when webcal
         makes a request.
     @type token: C{str}
-    @return: deferred returning a record name (C{str}) if successful, or
+    @return: deferred returning a guid (C{str}) if successful, or
         will raise WebAuthError otherwise.
     """
     url = "http://%s:%d/auth/verify?auth_token=%s" % (host, port, token,)
@@ -48,7 +48,7 @@
             (jsonResponse, str(e)))
         raise WebAuthError("Could not look up token: %s" % (token,))
     if response["succeeded"]:
-        returnValue(response["shortName"])
+        returnValue(response["generated_uid"])
     else:
         raise WebAuthError("Could not look up token: %s" % (token,))
 

Modified: CalendarServer/trunk/calendarserver/provision/root.py
===================================================================
--- CalendarServer/trunk/calendarserver/provision/root.py	2013-07-23 21:42:57 UTC (rev 11550)
+++ CalendarServer/trunk/calendarserver/provision/root.py	2013-07-24 00:40:00 UTC (rev 11551)
@@ -41,7 +41,7 @@
 from twistedcaldav.extensions import ReadOnlyResourceMixIn
 from twistedcaldav.resource import CalDAVComplianceMixIn
 from twistedcaldav.directory.principal import DirectoryPrincipalResource
-from calendarserver.platform.darwin.wiki import usernameForAuthToken
+from calendarserver.platform.darwin.wiki import guidForAuthToken
 
 log = Logger()
 
@@ -239,15 +239,23 @@
                 if token is not None and token != "unauthenticated":
                     log.debug("Wiki sessionID cookie value: %s" % (token,))
 
+                    record = None
                     try:
                         if wikiConfig.LionCompatibility:
+                            guid = None
                             proxy = Proxy(wikiConfig["URL"])
                             username = (yield proxy.callRemote(wikiConfig["UserMethod"], token))
+                            directory = request.site.resource.getDirectory()
+                            record = directory.recordWithShortName("users", username)
+                            if record is not None:
+                                guid = record.guid
                         else:
-                            username = (yield usernameForAuthToken(token))
+                            guid = (yield guidForAuthToken(token))
+                            if guid == "unauthenticated":
+                                guid = None
 
                     except WebError, w:
-                        username = None
+                        guid = None
                         # FORBIDDEN status means it's an unknown token
                         if int(w.status) == responsecode.NOT_FOUND:
                             log.debug("Unknown wiki token: %s" % (token,))
@@ -257,16 +265,16 @@
 
                     except Exception, e:
                         log.error("Failed to look up wiki token (%s)" % (e,))
-                        username = None
+                        guid = None
 
-                    if username is not None:
-                        log.debug("Wiki lookup returned user: %s" % (username,))
+                    if guid is not None:
+                        log.debug("Wiki lookup returned guid: %s" % (guid,))
                         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
+                        record = directory.recordWithGUID(guid)
+                        if record is not None:
+                            username = record.shortNames[0]
+                            log.debug("Wiki user record for user %s : %s" % (username, record))
                             for collection in self.principalCollections():
                                 principal = collection.principalForRecord(record)
                                 if principal is not None:
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20130723/7d229e56/attachment-0001.html>


More information about the calendarserver-changes mailing list