[CalendarServer-changes] [984] CalendarServer/branches/users/dreid/sudoers-3/twistedcaldav

source_changes at macosforge.org source_changes at macosforge.org
Mon Jan 8 16:58:53 PST 2007


Revision: 984
          http://trac.macosforge.org/projects/calendarserver/changeset/984
Author:   dreid at apple.com
Date:     2007-01-08 16:58:52 -0800 (Mon, 08 Jan 2007)

Log Message:
-----------
use a class attribute for the sudoers record type

Modified Paths:
--------------
    CalendarServer/branches/users/dreid/sudoers-3/twistedcaldav/directory/aggregate.py
    CalendarServer/branches/users/dreid/sudoers-3/twistedcaldav/directory/sudo.py
    CalendarServer/branches/users/dreid/sudoers-3/twistedcaldav/extensions.py
    CalendarServer/branches/users/dreid/sudoers-3/twistedcaldav/resource.py
    CalendarServer/branches/users/dreid/sudoers-3/twistedcaldav/tap.py

Modified: CalendarServer/branches/users/dreid/sudoers-3/twistedcaldav/directory/aggregate.py
===================================================================
--- CalendarServer/branches/users/dreid/sudoers-3/twistedcaldav/directory/aggregate.py	2007-01-09 00:33:04 UTC (rev 983)
+++ CalendarServer/branches/users/dreid/sudoers-3/twistedcaldav/directory/aggregate.py	2007-01-09 00:58:52 UTC (rev 984)
@@ -103,7 +103,7 @@
         else:
             return None
 
-    userRecordTypes = ['user', 'sudoer']
+    userRecordTypes = [DirectoryService.recordType_users]
 
     def requestAvatarId(self, credentials):
         for type in self.userRecordTypes:

Modified: CalendarServer/branches/users/dreid/sudoers-3/twistedcaldav/directory/sudo.py
===================================================================
--- CalendarServer/branches/users/dreid/sudoers-3/twistedcaldav/directory/sudo.py	2007-01-09 00:33:04 UTC (rev 983)
+++ CalendarServer/branches/users/dreid/sudoers-3/twistedcaldav/directory/sudo.py	2007-01-09 00:58:52 UTC (rev 984)
@@ -47,7 +47,7 @@
 
     plistFile = None
 
-    recordType = "sudoer"
+    recordType_sudoers = "sudoers"
 
     def __repr__(self):
         return "<%s %r: %r>" % (self.__class__.__name__, self.realmName,
@@ -71,25 +71,25 @@
         return self._plist
 
     def recordTypes(self):
-        return (self.recordType,)
+        return (SudoDirectoryService.recordType_sudoers,)
 
     def _recordForEntry(self, entry):
         return SudoDirectoryRecord(
             service=self,
-            recordType=self.recordType,
+            recordType=SudoDirectoryService.recordType_sudoers,
             shortName=entry['username'],
             entry=entry)
 
 
     def listRecords(self, recordType):
-        if recordType != self.recordType:
+        if recordType != SudoDirectoryService.recordType_sudoers:
             raise UnknownRecordTypeError(recordType)
 
         for entry in self._accounts()['users']:
             yield self._recordForEntry(entry)
 
     def recordWithShortName(self, recordType, shortName):
-        if recordType != self.recordType:
+        if recordType != SudoDirectoryService.recordType_sudoers:
             raise UnknownRecordTypeError(recordType)
 
         for entry in self._accounts()['users']:
@@ -101,8 +101,10 @@
         # We were checking if principal is enabled; seems unnecessary in current
         # implementation because you shouldn't have a principal object for a
         # disabled directory principal.
-        sudouser = self.recordWithShortName("sudoer", 
-                                            credentials.credentials.username)
+        sudouser = self.recordWithShortName(
+            SudoDirectoryService.recordType_sudoers, 
+            credentials.credentials.username)
+
         if sudouser is None:
             raise UnauthorizedLogin("No such user: %s" % (sudouser,))
         

Modified: CalendarServer/branches/users/dreid/sudoers-3/twistedcaldav/extensions.py
===================================================================
--- CalendarServer/branches/users/dreid/sudoers-3/twistedcaldav/extensions.py	2007-01-09 00:33:04 UTC (rev 983)
+++ CalendarServer/branches/users/dreid/sudoers-3/twistedcaldav/extensions.py	2007-01-09 00:58:52 UTC (rev 984)
@@ -42,6 +42,7 @@
 from twisted.web2.dav.static import DAVFile as SuperDAVFile
 from twisted.web2.dav.resource import DAVResource as SuperDAVResource
 from twisted.web2.dav.resource import DAVPrincipalResource as SuperDAVPrincipalResource
+from twistedcaldav.directory.sudo import SudoDirectoryService
 
 
 class SudoAuthIDMixin(object):
@@ -57,7 +58,9 @@
         regular users.
         """
         for collection in self.principalCollections():
-            principal = collection.principalForShortName('sudoer', authid)
+            principal = collection.principalForShortName(
+                SudoDirectoryService.recordType_sudoers, 
+                authid)
             if principal is not None:
                 return principal
 

Modified: CalendarServer/branches/users/dreid/sudoers-3/twistedcaldav/resource.py
===================================================================
--- CalendarServer/branches/users/dreid/sudoers-3/twistedcaldav/resource.py	2007-01-09 00:33:04 UTC (rev 983)
+++ CalendarServer/branches/users/dreid/sudoers-3/twistedcaldav/resource.py	2007-01-09 00:58:52 UTC (rev 984)
@@ -56,6 +56,9 @@
 from twistedcaldav.customxml import calendarserver_namespace
 from twistedcaldav.ical import Component as iComponent
 
+from twistedcaldav.directory.directory import DirectoryService
+from twistedcaldav.directory.sudo import SudoDirectoryService
+
 if twistedcaldav.__version__:
     serverVersion = twisted.web2.server.VERSION + " TwistedCalDAV/" + twistedcaldav.__version__
 else:
@@ -249,6 +252,7 @@
 
         # Look for X-Authorize-As Header
         authz = request.headers.getRawHeaders("x-authorize-as")
+
         if authz is not None and (len(authz) == 1):
             # Substitute the authz value for principal look up
             authz = authz[0]
@@ -260,7 +264,8 @@
                     return principal
 
         def isSudoPrincipal(authid):
-            if getPrincipalForType('sudoer', authid):
+            if getPrincipalForType(SudoDirectoryService.recordType_sudoers, 
+                                   authid):
                 return True
             return False
 
@@ -270,7 +275,8 @@
                     log.msg("Cannot proxy as another proxy: user '%s' as user '%s'" % (authid, authz))
                     raise HTTPError(responsecode.FORBIDDEN)
                 else:
-                    authzPrincipal = getPrincipalForType('group', authz)
+                    authzPrincipal = getPrincipalForType(
+                        DirectoryService.recordType_groups, authz)
 
                     if not authzPrincipal:
                         authzPrincipal = self.findPrincipalForAuthID(authz)

Modified: CalendarServer/branches/users/dreid/sudoers-3/twistedcaldav/tap.py
===================================================================
--- CalendarServer/branches/users/dreid/sudoers-3/twistedcaldav/tap.py	2007-01-09 00:33:04 UTC (rev 983)
+++ CalendarServer/branches/users/dreid/sudoers-3/twistedcaldav/tap.py	2007-01-09 00:58:52 UTC (rev 984)
@@ -149,9 +149,13 @@
         #
         # Setup the Directory
         #
+        directories = []
+        
         directoryClass = namedClass(config.DirectoryService['type'])
         baseDirectory = directoryClass(**config.DirectoryService['params'])
 
+        directories.append(baseDirectory)
+
         sudoDirectory = None
 
         if config.SudoersFile and os.path.exists(config.SudoersFile):
@@ -159,10 +163,14 @@
             sudoDirectory.realmName = baseDirectory.realmName
 
             CalDAVResource.sudoDirectory = sudoDirectory
-        
-        directory = AggregateDirectoryService((baseDirectory,
-                                               sudoDirectory))
+            directories.append(sudoDirectory)
 
+        directory = AggregateDirectoryService(directories)
+
+        if sudoDirectory:
+            directory.userRecordTypes.append(
+                SudoDirectoryService.recordType_sudoers)
+
         #
         # Setup Resource hierarchy
         #

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20070108/8bdb7c6d/attachment.html


More information about the calendarserver-changes mailing list