[CalendarServer-changes] [384] CalendarServer/branches/users/wsanchez/provisioning/twistedcaldav/ repository.py

source_changes at macosforge.org source_changes at macosforge.org
Mon Nov 6 19:32:54 PST 2006


Revision: 384
          http://trac.macosforge.org/projects/calendarserver/changeset/384
Author:   wsanchez at apple.com
Date:     2006-11-06 19:32:53 -0800 (Mon, 06 Nov 2006)

Log Message:
-----------
Use new principal provisioning classes.

Modified Paths:
--------------
    CalendarServer/branches/users/wsanchez/provisioning/twistedcaldav/repository.py

Modified: CalendarServer/branches/users/wsanchez/provisioning/twistedcaldav/repository.py
===================================================================
--- CalendarServer/branches/users/wsanchez/provisioning/twistedcaldav/repository.py	2006-11-07 03:32:36 UTC (rev 383)
+++ CalendarServer/branches/users/wsanchez/provisioning/twistedcaldav/repository.py	2006-11-07 03:32:53 UTC (rev 384)
@@ -24,6 +24,14 @@
 
 __all__ = ["RepositoryBuilder"]
 
+import os
+
+from xml.dom.minidom import Element
+from xml.dom.minidom import Text
+import xml.dom.minidom
+
+from zope.interface import implements
+
 from twisted.application.internet import SSLServer, TCPServer
 from twisted.application.service import Application, IServiceCollection, MultiService
 from twisted.cred.portal import Portal
@@ -47,13 +55,9 @@
 from twistedcaldav.resource import CalDAVResource
 from twistedcaldav.static import CalDAVFile, CalendarHomeFile, CalendarPrincipalFile
 from twistedcaldav.directory.cred import DirectoryCredentialsChecker
+from twistedcaldav.directory.idirectory import IDirectoryService
+from twistedcaldav.directory.appleopendirectory import OpenDirectoryService
 
-import os
-
-from xml.dom.minidom import Element
-from xml.dom.minidom import Text
-import xml.dom.minidom
-
 ELEMENT_REPOSITORY = "repository"
 
 ELEMENT_DOCROOT = "docroot"
@@ -106,6 +110,7 @@
 ATTRIBUTE_ENABLE = "enable"
 ATTRIBUTE_ONLYSSL = "onlyssl"
 ATTRIBUTE_CREDENTIALS = "credentials"
+ATTRIBUTE_DIRECTORY_NODE = "node"
 
 ATTRIBUTE_VALUE_PROPERTY = "property"
 ATTRIBUTE_VALUE_DIRECTORY = "directory"
@@ -169,13 +174,37 @@
             MultiService.stopService(self)
             self.logObserver.stop()
     
+    class DirectoryServiceProxy(object):
+        # FIXME: This is a hack to make this config work for now
+        implements(IDirectoryService)
+
+        service = None
+
+        def __getattr__(self, name):
+            attr = getattr(self.service, name)
+
+            if type(attr) is type(self.__getattr__):
+                def m(*args, **kwargs):
+                    return attr(*args, **kwargs)
+                return m
+            else:
+                return attr
+
+        def __setattr__(self, name, value):
+            if name == "service":
+                object.__setattr__(self, name, value)
+            else:
+                raise AttributeError("Attributes are read-only")
+
+    directory = DirectoryServiceProxy()
+
     # Build the server
     builder = RepositoryBuilder(docroot,
                                 doAccounts=doacct,
                                 resetACLs=doacl,
                                 maxsize=maxsize,
                                 quota=quota)
-    builder.buildFromFile(repo)
+    builder.buildFromFile(repo, directory)
     rootresource = builder.docRoot.collection.resource
     
     application = Application("CalDAVServer")
@@ -192,7 +221,9 @@
         portal.registerChecker(auth.TwistedPropertyChecker())
         print "Using property-based password checker."
     elif authenticator.credentials == ATTRIBUTE_VALUE_DIRECTORY:
-        portal.registerChecker(DirectoryCredentialsChecker())
+        opendirectory = OpenDirectoryService(authenticator.directoryNode)
+        directory.service = opendirectory
+        portal.registerChecker(DirectoryCredentialsChecker(opendirectory))
         print "Using directory-based password checker."
     elif authenticator.credentials == ATTRIBUTE_VALUE_KERBEROS:
         if authenticator.type == "basic":
@@ -277,24 +308,24 @@
         if self.quota <= 0:
             self.quota = None
         
-    def buildFromFile(self, file):
+    def buildFromFile(self, filename, directory):
         """
         Parse the required information from an XML file.
         @param file: the path of the XML file to parse.
         """
         # Read in XML
-        fd = open(file, "r")
+        fd = open(filename, "r")
         doc = xml.dom.minidom.parse( fd )
         fd.close()
 
         # Verify that top-level element is correct
         repository_node = doc._get_documentElement()
         if repository_node._get_localName() != ELEMENT_REPOSITORY:
-            self.log("Ignoring file \"%s\" because it is not a repository builder file" % (file,))
+            self.log("Ignoring file %r because it is not a repository builder file" % (filename,))
             return
         self.parseXML(repository_node)
         
-        self.docRoot.build()
+        self.docRoot.build(directory)
         if self.doAccounts:
             self.accounts.provision(
                 self.docRoot.principalCollections,
@@ -350,11 +381,11 @@
                 self.collection.parseXML(child, self)
                 break
 
-    def build(self):
+    def build(self, directory):
         """
         Build the entire repository starting at the root resource.
         """
-        self.collection.build(self.path, "/")
+        self.collection.build(self.path, "/", directory)
         
         # Setup the principal-collection-set property if required
         if self.autoPrincipalCollectionSet:
@@ -376,7 +407,7 @@
     """
     def __init__(self):
         self.name = None
-        self.pytype = "twistedcaldav.static.CalDAVFile" # FIXME: Why not None?
+        self.pytype = None
         self.params = {}
         self.properties = []
         self.acl = None
@@ -458,7 +489,7 @@
                 self.properties.append(Prop())
                 self.properties[-1].parseXML(child)
 
-    def build(self, docroot, urlroot):
+    def build(self, docroot, urlroot, directory):
         """
         Create this collection, initialising any properties and then create any child
         collections.
@@ -482,14 +513,19 @@
         kwargs = {}
         argnames = resource_class.__init__.func_code.co_varnames
         for name, value in (
-            ("path", mypath),
-            ("url" , myurl ),
+            ("path"     , mypath   ),
+            ("url"      , myurl    ),
+            ("directory", directory),
         ):
             if name in argnames:
                 kwargs[name] = value
         if self.params:
             kwargs["params"] = self.params
-        self.resource = resource_class(**kwargs)
+        try:
+            self.resource = resource_class(**kwargs)
+        except Exception, e:
+            log.err("Unable to instantiate Python class %r with arguments %r" % (resource_class, kwargs))
+            raise
 
         self.uri = myurl
         
@@ -502,7 +538,7 @@
             self.resource.setAccessControlList(self.acl.acl)
 
         for member in self.members:
-            child = member.build(mypath, myurl)
+            child = member.build(mypath, myurl, directory)
             # Only putChild if one does not already exists
             if self.resource.putChildren.get(member.name, None) is None:
                 self.resource.putChild(member.name, child)
@@ -696,10 +732,10 @@
                     self.calendarHome.resource,
                 )
 
-        # Check for proper account home
-        if not self.accountCollection:
-            log.err("Accounts cannot be created: no principal collection was marked with an account attribute.")
-            raise ValueError, "Accounts cannot be created."
+#        # Check for proper account home
+#        if not self.accountCollection:
+#            log.err("Accounts cannot be created: no principal collection was marked with an account attribute.")
+#            raise ValueError, "Accounts cannot be created."
 
         # Provision each user
         for repeat, principal in self.items:
@@ -964,6 +1000,8 @@
                 self.onlyssl = node.getAttribute(ATTRIBUTE_ONLYSSL) == ATTRIBUTE_VALUE_YES
             if node.hasAttribute(ATTRIBUTE_CREDENTIALS):
                 self.credentials = node.getAttribute(ATTRIBUTE_CREDENTIALS)
+            if node.hasAttribute(ATTRIBUTE_DIRECTORY_NODE):
+                self.directoryNode = node.getAttribute(ATTRIBUTE_DIRECTORY_NODE)
             for child in node._get_childNodes():
                 if child._get_localName() == ELEMENT_REALM:
                     if child.firstChild is not None:

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


More information about the calendarserver-changes mailing list