[CalendarServer-changes] [12597] CalendarServer/trunk/txdav/dps

source_changes at macosforge.org source_changes at macosforge.org
Wed Mar 12 11:20:23 PDT 2014


Revision: 12597
          http://trac.calendarserver.org//changeset/12597
Author:   sagen at apple.com
Date:     2014-02-06 16:31:27 -0800 (Thu, 06 Feb 2014)
Log Message:
-----------
Adds verifyPlaintextPassword to DPS

Modified Paths:
--------------
    CalendarServer/trunk/txdav/dps/client.py
    CalendarServer/trunk/txdav/dps/commands.py
    CalendarServer/trunk/txdav/dps/server.py
    CalendarServer/trunk/txdav/dps/test/test_client.py

Modified: CalendarServer/trunk/txdav/dps/client.py
===================================================================
--- CalendarServer/trunk/txdav/dps/client.py	2014-02-06 23:36:27 UTC (rev 12596)
+++ CalendarServer/trunk/txdav/dps/client.py	2014-02-07 00:31:27 UTC (rev 12597)
@@ -27,9 +27,9 @@
 from twisted.internet.protocol import ClientCreator
 from twisted.protocols import amp
 from txdav.dps.commands import (
-    RecordWithShortNameCommand, RecordWithUIDCommand,
-    RecordWithGUIDCommand, RecordsWithRecordTypeCommand,
-    RecordsWithEmailAddressCommand
+    RecordWithShortNameCommand, RecordWithUIDCommand, RecordWithGUIDCommand,
+    RecordsWithRecordTypeCommand, RecordsWithEmailAddressCommand,
+    VerifyPlaintextPasswordCommand
 )
 import txdav.who.idirectory
 from zope.interface import implementer
@@ -169,10 +169,15 @@
 
 
 class DirectoryRecord(BaseDirectoryRecord):
-    pass
 
+    def verifyPlaintextPassword(self, password):
+        return self.service._call(
+            VerifyPlaintextPasswordCommand,
+            lambda x: x['authenticated'],
+            uid=self.uid.encode("utf-8"),
+            password=password.encode("utf-8")
+        )
 
-
 # Test client:
 
 
@@ -181,14 +186,16 @@
     ds = DirectoryService(None)
     record = (yield ds.recordWithShortName(RecordType.user, "wsanchez"))
     print("short name: {r}".format(r=record))
-    record = (yield ds.recordWithUID("__dre__"))
+    record = (yield ds.recordWithUID("sagen"))
     print("uid: {r}".format(r=record))
+    """
     record = (yield ds.recordWithGUID("A3B1158F-0564-4F5B-81E4-A89EA5FF81B0"))
     print("guid: {r}".format(r=record))
     records = (yield ds.recordsWithRecordType(RecordType.user))
     print("recordType: {r}".format(r=records))
     records = (yield ds.recordsWithEmailAddress("cdaboo at bitbucket.calendarserver.org"))
     print("emailAddress: {r}".format(r=records))
+    """
 
 
 def succeeded(result):

Modified: CalendarServer/trunk/txdav/dps/commands.py
===================================================================
--- CalendarServer/trunk/txdav/dps/commands.py	2014-02-06 23:36:27 UTC (rev 12596)
+++ CalendarServer/trunk/txdav/dps/commands.py	2014-02-07 00:31:27 UTC (rev 12597)
@@ -80,3 +80,13 @@
     response = [
         ('success', amp.Boolean()),
     ]
+
+
+class VerifyPlaintextPasswordCommand(amp.Command):
+    arguments = [
+        ('uid', amp.String()),
+        ('password', amp.String()),
+    ]
+    response = [
+        ('authenticated', amp.Boolean()),
+    ]

Modified: CalendarServer/trunk/txdav/dps/server.py
===================================================================
--- CalendarServer/trunk/txdav/dps/server.py	2014-02-06 23:36:27 UTC (rev 12596)
+++ CalendarServer/trunk/txdav/dps/server.py	2014-02-07 00:31:27 UTC (rev 12597)
@@ -33,6 +33,7 @@
 from txdav.dps.commands import (
     RecordWithShortNameCommand, RecordWithUIDCommand, RecordWithGUIDCommand,
     RecordsWithRecordTypeCommand, RecordsWithEmailAddressCommand,
+    VerifyPlaintextPasswordCommand
     # UpdateRecordsCommand, RemoveRecordsCommand
 )
 from txdav.who.xml import DirectoryService as XMLDirectoryService
@@ -155,8 +156,24 @@
         returnValue(response)
 
 
+    @VerifyPlaintextPasswordCommand.responder
+    @inlineCallbacks
+    def verifyPlaintextPassword(self, uid, password):
+        uid = uid.decode("utf-8")
+        log.debug("VerifyPlaintextPassword: {u}", u=uid)
+        record = (yield self._directory.recordWithUID(uid))
+        authenticated = False
+        if record is not None:
+            authenticated = (yield record.verifyPlaintextPassword(password))
+        response = {
+            "authenticated": authenticated,
+        }
+        log.debug("Responding with: {response}", response=response)
+        returnValue(response)
 
 
+
+
 class DirectoryProxyAMPFactory(Factory):
     """
     """

Modified: CalendarServer/trunk/txdav/dps/test/test_client.py
===================================================================
--- CalendarServer/trunk/txdav/dps/test/test_client.py	2014-02-06 23:36:27 UTC (rev 12596)
+++ CalendarServer/trunk/txdav/dps/test/test_client.py	2014-02-07 00:31:27 UTC (rev 12597)
@@ -99,3 +99,16 @@
         ))
         self.assertEquals(len(records), 1)
         self.assertEquals(records[0].shortNames, [u"cdaboo"])
+
+
+    @inlineCallbacks
+    def test_verifyPlaintextPassword(self):
+        record = (yield self.directory.recordWithUID("__dre__"))
+
+        # Correct password
+        authenticated = (yield record.verifyPlaintextPassword("erd"))
+        self.assertTrue(authenticated)
+
+        # Incorrect password
+        authenticated = (yield record.verifyPlaintextPassword("wrong"))
+        self.assertFalse(authenticated)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20140312/7fa38650/attachment.html>


More information about the calendarserver-changes mailing list