Revision
2079
Author
wsanchez@apple.com
Date
2007-12-19 12:35:59 -0800 (Wed, 19 Dec 2007)

Log Message

Cache Basic auth password for the lifetime of each OD DirectoryRecord object.  No need to time them out bcause they are all flushed with the record cache periodically.

Modified Paths

Diff

Modified: CalendarServer/trunk/twistedcaldav/directory/appleopendirectory.py (2078 => 2079)


--- CalendarServer/trunk/twistedcaldav/directory/appleopendirectory.py	2007-12-15 00:19:09 UTC (rev 2078)
+++ CalendarServer/trunk/twistedcaldav/directory/appleopendirectory.py	2007-12-19 20:35:59 UTC (rev 2079)
@@ -762,12 +762,25 @@
 
     def verifyCredentials(self, credentials):
         if isinstance(credentials, UsernamePassword):
+            # Check cached password
             try:
-                return opendirectory.authenticateUserBasic(self.service.directory, self._nodename, self.shortName, credentials.password)
+                if credentials.password == self.password:
+                    return True
+            except AttributeError:
+                pass
+
+            # Check with directory services
+            try:
+                if opendirectory.authenticateUserBasic(self.service.directory, self._nodename, self.shortName, credentials.password):
+                    # Cache the password to avoid future DS queries
+                    self.password = credentials.password
+                    return True
             except opendirectory.ODError, e:
                 logging.err("Open Directory (node=%s) error while performing basic authentication for user %s: %s"
-                        % (self.service.realmName, self.shortName, e), system="OpenDirectoryService")
-                return False
+                            % (self.service.realmName, self.shortName, e), system="OpenDirectoryService")
+
+            return False
+
         elif isinstance(credentials, DigestedCredentials):
             try:
                 # We need a special format for the "challenge" and "response" strings passed into open directory, as it is