[CalendarServer-changes] [12140] twext/trunk/twext/who/opendirectory/service.py

source_changes at macosforge.org source_changes at macosforge.org
Wed Mar 12 11:16:18 PDT 2014


Revision: 12140
          http://trac.calendarserver.org//changeset/12140
Author:   wsanchez at apple.com
Date:     2013-12-18 18:27:55 -0800 (Wed, 18 Dec 2013)
Log Message:
-----------
cleanup

Modified Paths:
--------------
    twext/trunk/twext/who/opendirectory/service.py

Modified: twext/trunk/twext/who/opendirectory/service.py
===================================================================
--- twext/trunk/twext/who/opendirectory/service.py	2013-12-19 01:54:29 UTC (rev 12139)
+++ twext/trunk/twext/who/opendirectory/service.py	2013-12-19 02:27:55 UTC (rev 12140)
@@ -48,7 +48,7 @@
 from zope.interface import implements
 from twisted.internet.defer import succeed, fail
 from twisted.web.guard import DigestCredentialFactory
-from twisted.cred.credentials import UsernamePassword, DigestedCredentials
+from twisted.cred.credentials import DigestedCredentials
 
 
 
@@ -231,7 +231,7 @@
     """
 
     implements(ICredentialsChecker)
-    credentialInterfaces = (IUsernamePassword, IUsernameHashedPassword,)
+    credentialInterfaces = (IUsernamePassword, IUsernameHashedPassword)
 
     log = Logger()
 
@@ -609,31 +609,31 @@
     def requestAvatarId(self, credentials):
         """
         Authenticate the credentials against OpenDirectory and return the
-        corresponding DirectoryRecord or fail with UnauthorizedLogin if
-        the credentials are not valid.
+        corresponding directory record.
 
-        @param: credentials: the credentials to authenticate.
-        @type: credentials: either UsernamePassword or DigestedCredentials
+        @param: credentials: The credentials to authenticate.
+        @type: credentials: L{ICredentials}
 
-        @return: Deferred which fires with DirectoryRecord.
+        @return: The directory record for the given credentials.
+        @rtype: deferred L{DirectoryRecord}
+
+        @raises: L{UnauthorizedLogin} if the credentials are not valid.
         """
 
         record = self._getUserRecord(credentials.username)
 
         if record is not None:
 
-            if isinstance(credentials, UsernamePassword):
+            if IUsernamePassword.providedBy(credentials):
                 result, error = record.verifyPassword_error_(
                     credentials.password, None
                 )
                 if not error and result:
                     return succeed(self._adaptODRecord(record))
-                    # return succeed(credentials.username)
 
             elif isinstance(credentials, DigestedCredentials):
                 try:
-                    if "algorithm" not in credentials.fields:
-                        credentials.fields["algorithm"] = "md5"
+                    credentials.fields.setdefault("algorithm", "md5")
                     challenge = (
                         'Digest realm="{realm}", nonce="{nonce}", '
                         'algorithm={algorithm}'
@@ -642,9 +642,10 @@
                     response = credentials.fields["response"]
                 except KeyError as e:
                     self.log.error(
-                        "Error authenticating against OpenDirectory : "
-                        "missing digest response field: {field} "
-                        "in: {fields}", field=e, fields=credentials.fields
+                        "Error authenticating against OpenDirectory: "
+                        "missing digest response field {field!r} in "
+                        "{credentials.fields!r}",
+                        field=e.args[0], credentials=credentials
                     )
                     return fail(UnauthorizedLogin())
 
@@ -660,7 +661,6 @@
                 )
 
                 if not error and result:
-                    # return succeed(credentials.username)
                     return succeed(self._adaptODRecord(record))
 
         return fail(UnauthorizedLogin())
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20140312/80158d10/attachment.html>


More information about the calendarserver-changes mailing list