[CalendarServer-changes] [9424] CalendarServer/trunk

source_changes at macosforge.org source_changes at macosforge.org
Tue Jul 10 17:02:30 PDT 2012


Revision: 9424
          http://trac.macosforge.org/projects/calendarserver/changeset/9424
Author:   sagen at apple.com
Date:     2012-07-10 17:02:29 -0700 (Tue, 10 Jul 2012)
Log Message:
-----------
Allow LDAP config to use multiple LDAP attributes for emailAddresses (so that both primary address and email aliases may be used for principal-property-search and faulting in individual records).

Modified Paths:
--------------
    CalendarServer/trunk/conf/caldavd-test.plist
    CalendarServer/trunk/twistedcaldav/directory/ldapdirectory.py
    CalendarServer/trunk/twistedcaldav/directory/principal.py
    CalendarServer/trunk/twistedcaldav/directory/test/test_ldapdirectory.py
    CalendarServer/trunk/twistedcaldav/resource.py
    CalendarServer/trunk/twistedcaldav/stdconfig.py

Modified: CalendarServer/trunk/conf/caldavd-test.plist
===================================================================
--- CalendarServer/trunk/conf/caldavd-test.plist	2012-07-10 22:57:46 UTC (rev 9423)
+++ CalendarServer/trunk/conf/caldavd-test.plist	2012-07-11 00:02:29 UTC (rev 9424)
@@ -267,7 +267,9 @@
               <key>fullName</key>
               <string>cn</string>
               <key>emailAddresses</key>
-              <string>mail</string>
+              <array>
+                  <string>mail</string>
+              </array>
               <key>firstName</key>
               <string>givenName</string>
               <key>lastName</key>
@@ -291,7 +293,9 @@
               <key>fullName</key>
               <string>cn</string>
               <key>emailAddresses</key>
-              <string>mail</string>
+              <array>
+                  <string>mail</string>
+              </array>
               <key>firstName</key>
               <string>givenName</string>
               <key>lastName</key>

Modified: CalendarServer/trunk/twistedcaldav/directory/ldapdirectory.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/directory/ldapdirectory.py	2012-07-10 22:57:46 UTC (rev 9423)
+++ CalendarServer/trunk/twistedcaldav/directory/ldapdirectory.py	2012-07-11 00:02:29 UTC (rev 9424)
@@ -118,7 +118,7 @@
                     "mapping" : { # maps internal record names to LDAP
                         "recordName": "uid",
                         "fullName" : "cn",
-                        "emailAddresses" : "mail",
+                        "emailAddresses" : ["mail"], # multiple LDAP fields supported
                         "firstName" : "givenName",
                         "lastName" : "sn",
                     },
@@ -131,7 +131,7 @@
                     "mapping" : { # maps internal record names to LDAP
                         "recordName": "cn",
                         "fullName" : "cn",
-                        "emailAddresses" : "mail",
+                        "emailAddresses" : ["mail"], # multiple LDAP fields supported
                         "firstName" : "givenName",
                         "lastName" : "sn",
                     },
@@ -146,7 +146,7 @@
                     "mapping" : { # maps internal record names to LDAP
                         "recordName": "cn",
                         "fullName" : "cn",
-                        "emailAddresses" : "mail",
+                        "emailAddresses" : ["mail"], # multiple LDAP fields supported
                         "firstName" : "givenName",
                         "lastName" : "sn",
                     },
@@ -161,7 +161,7 @@
                     "mapping" : { # maps internal record names to LDAP
                         "recordName": "cn",
                         "fullName" : "cn",
-                        "emailAddresses" : "mail",
+                        "emailAddresses" : ["mail"], # multiple LDAP fields supported
                         "firstName" : "givenName",
                         "lastName" : "sn",
                     },
@@ -235,9 +235,14 @@
                 attrSet.add(self.rdnSchema[recordType]["attr"])
             if self.rdnSchema[recordType].get("calendarEnabledAttr", False):
                 attrSet.add(self.rdnSchema[recordType]["calendarEnabledAttr"])
-            for attr in self.rdnSchema[recordType]["mapping"].values():
-                if attr:
-                    attrSet.add(attr)
+            for attrList in self.rdnSchema[recordType]["mapping"].values():
+                if attrList:
+                    # Since emailAddresses can map to multiple LDAP fields,
+                    # support either string or list
+                    if isinstance(attrList, str):
+                        attrList = [attrList]
+                    for attr in attrList:
+                        attrSet.add(attr)
             # Also put the guidAttr attribute into the mappings for each type
             # so recordsMatchingFields can query on guid
             self.rdnSchema[recordType]["mapping"]["guid"] = self.rdnSchema["guidAttr"]
@@ -646,9 +651,10 @@
         """
         results = []
         for key in keys:
-            values = attrs.get(key)
-            if values is not None:
-                results += values
+            if key:
+                values = attrs.get(key)
+                if values is not None:
+                    results += values
         return results
 
 
@@ -686,7 +692,13 @@
                 raise MissingGuidException()
 
         # Find or build email
-        emailAddresses = set(self._getMultipleLdapAttributes(attrs, self.rdnSchema[recordType]["mapping"]["emailAddresses"]))
+        # (The emailAddresses mapping is a list of ldap fields)
+        emailAddressesMappedTo = self.rdnSchema[recordType]["mapping"]["emailAddresses"]
+        # Supporting either string or list for emailAddresses:
+        if isinstance(emailAddressesMappedTo, str):
+            emailAddresses = set(self._getMultipleLdapAttributes(attrs, self.rdnSchema[recordType]["mapping"]["emailAddresses"]))
+        else:
+            emailAddresses = set(self._getMultipleLdapAttributes(attrs, *self.rdnSchema[recordType]["mapping"]["emailAddresses"]))
         emailSuffix = self.rdnSchema[recordType]["emailSuffix"]
 
         if len(emailAddresses) == 0 and emailSuffix:
@@ -885,7 +897,16 @@
                         ldapEsc(email)
                     )
                 else:
-                    filterstr = "(&%s(mail=%s))" % (filterstr, ldapEsc(email))
+                    # emailAddresses can map to multiple LDAP fields
+                    ldapFields = self.rdnSchema[recordType]["mapping"]["emailAddresses"]
+                    if isinstance(ldapFields, str):
+                        subfilter = "(%s=%s)" % (ldapFields, ldapEsc(email))
+                    else:
+                        subfilter = []
+                        for ldapField in ldapFields:
+                            subfilter.append("(%s=%s)" % (ldapField, ldapEsc(email)))
+                        subfilter = "(|%s)" % ("".join(subfilter))
+                    filterstr = "(&%s%s)" % (filterstr, subfilter)
 
             elif indexType == self.INDEX_TYPE_AUTHID:
                 return
@@ -1157,7 +1178,13 @@
         if ldapField:
             combined.setdefault(field, []).append((value, caseless, matchType))
             value = _convertValue(value, matchType)
-            converted.append("(%s=%s)" % (ldapField, value))
+            if isinstance(ldapField, str):
+                converted.append("(%s=%s)" % (ldapField, value))
+            else:
+                subConverted = []
+                for lf in ldapField:
+                    subConverted.append("(%s=%s)" % (lf, value))
+                converted.append("(|%s)" % "".join(subConverted))
 
     if len(converted) == 0:
         return None

Modified: CalendarServer/trunk/twistedcaldav/directory/principal.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/directory/principal.py	2012-07-10 22:57:46 UTC (rev 9423)
+++ CalendarServer/trunk/twistedcaldav/directory/principal.py	2012-07-11 00:02:29 UTC (rev 9424)
@@ -631,7 +631,7 @@
         if record.enabledForCalendaring:
             return tag.fillSlots(
                 calendarUserAddresses=formatLinks(
-                    resource.calendarUserAddresses()
+                    sorted(resource.calendarUserAddresses())
                 ),
                 calendarHomes=formatLinks(resource.calendarHomeURLs())
             )
@@ -755,7 +755,7 @@
 
             elif name == "email-address-set":
                 returnValue(customxml.EmailAddressSet(
-                    *[customxml.EmailAddressProperty(addr) for addr in self.record.emailAddresses]
+                    *[customxml.EmailAddressProperty(addr) for addr in sorted(self.record.emailAddresses)]
                 ))
 
         result = (yield super(DirectoryPrincipalResource, self).readProperty(property, request))

Modified: CalendarServer/trunk/twistedcaldav/directory/test/test_ldapdirectory.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/directory/test/test_ldapdirectory.py	2012-07-10 22:57:46 UTC (rev 9423)
+++ CalendarServer/trunk/twistedcaldav/directory/test/test_ldapdirectory.py	2012-07-11 00:02:29 UTC (rev 9424)
@@ -410,7 +410,7 @@
                         "mapping": { # maps internal record names to LDAP
                             "recordName": "uid",
                             "fullName" : "cn",
-                            "emailAddresses" : "mail",
+                            "emailAddresses" : ["mail", "emailAliases"],
                             "firstName" : "givenName",
                             "lastName" : "sn",
                         },
@@ -423,7 +423,7 @@
                         "mapping": { # maps internal record names to LDAP
                             "recordName": "cn",
                             "fullName" : "cn",
-                            "emailAddresses" : "mail",
+                            "emailAddresses" : ["mail", "emailAliases"],
                             "firstName" : "givenName",
                             "lastName" : "sn",
                         },
@@ -438,7 +438,7 @@
                         "mapping": { # maps internal record names to LDAP
                             "recordName": "cn",
                             "fullName" : "cn",
-                            "emailAddresses" : "mail",
+                            "emailAddresses" : ["mail", "emailAliases"],
                             "firstName" : "givenName",
                             "lastName" : "sn",
                         },
@@ -453,7 +453,7 @@
                         "mapping": { # maps internal record names to LDAP
                             "recordName": "cn",
                             "fullName" : "cn",
-                            "emailAddresses" : "mail",
+                            "emailAddresses" : ["mail", "emailAliases"],
                             "firstName" : "givenName",
                             "lastName" : "sn",
                         },

Modified: CalendarServer/trunk/twistedcaldav/resource.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/resource.py	2012-07-10 22:57:46 UTC (rev 9423)
+++ CalendarServer/trunk/twistedcaldav/resource.py	2012-07-11 00:02:29 UTC (rev 9424)
@@ -1908,7 +1908,7 @@
 
             elif name == "calendar-user-address-set":
                 returnValue(caldavxml.CalendarUserAddressSet(
-                    *[element.HRef(uri) for uri in self.calendarUserAddresses()]
+                    *[element.HRef(uri) for uri in sorted(self.calendarUserAddresses())]
                 ))
 
             elif name == "schedule-inbox-URL":

Modified: CalendarServer/trunk/twistedcaldav/stdconfig.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/stdconfig.py	2012-07-10 22:57:46 UTC (rev 9423)
+++ CalendarServer/trunk/twistedcaldav/stdconfig.py	2012-07-11 00:02:29 UTC (rev 9424)
@@ -97,7 +97,7 @@
                 "mapping" : { # maps internal record names to LDAP
                     "recordName": "uid",
                     "fullName" : "cn",
-                    "emailAddresses" : "mail",
+                    "emailAddresses" : ["mail"],
                     "firstName" : "givenName",
                     "lastName" : "sn",
                 },
@@ -110,7 +110,7 @@
                 "mapping" : { # maps internal record names to LDAP
                     "recordName": "cn",
                     "fullName" : "cn",
-                    "emailAddresses" : "mail",
+                    "emailAddresses" : ["mail"],
                     "firstName" : "givenName",
                     "lastName" : "sn",
                 },
@@ -125,7 +125,7 @@
                 "mapping" : { # maps internal record names to LDAP
                     "recordName": "cn",
                     "fullName" : "cn",
-                    "emailAddresses" : "mail",
+                    "emailAddresses" : ["mail"],
                     "firstName" : "givenName",
                     "lastName" : "sn",
                 },
@@ -140,7 +140,7 @@
                 "mapping" : { # maps internal record names to LDAP
                     "recordName": "cn",
                     "fullName" : "cn",
-                    "emailAddresses" : "mail",
+                    "emailAddresses" : ["mail"],
                     "firstName" : "givenName",
                     "lastName" : "sn",
                 },
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20120710/53419fb4/attachment-0001.html>


More information about the calendarserver-changes mailing list