[Zodb-checkins] CVS: ZODB3/ZEO - ClientStorage.py:1.93.2.2 StorageServer.py:1.92.10.2

Johan Dahlin jdahlin at telia.com
Mon May 19 14:46:37 EDT 2003


Update of /cvs-repository/ZODB3/ZEO
In directory cvs.zope.org:/tmp/cvs-serv17295/ZEO

Modified Files:
      Tag: ZODB3-auth-branch
	ClientStorage.py StorageServer.py 
Log Message:
Merge AuthZEOStorage with ZEOStorage. Don't use __import__(). Introduce register_module() and get_module(). Use hmac.py from python 2.2 (for python 2.1 support)

=== ZODB3/ZEO/ClientStorage.py 1.93.2.1 => 1.93.2.2 ===
--- ZODB3/ZEO/ClientStorage.py:1.93.2.1	Tue May 13 16:42:38 2003
+++ ZODB3/ZEO/ClientStorage.py	Mon May 19 13:46:06 2003
@@ -28,9 +28,9 @@
 
 from ZEO import ClientCache, ServerStub
 from ZEO.TransactionBuffer import TransactionBuffer
-from ZEO.Exceptions \
-     import ClientStorageError, UnrecognizedResult, ClientDisconnected, \
-            AuthError
+from ZEO.Exceptions import ClientStorageError, UnrecognizedResult, \
+     ClientDisconnected, AuthError
+from ZEO.auth import get_module
 from ZEO.zrpc.client import ConnectionManager
 
 from ZODB import POSException
@@ -374,22 +374,22 @@
         # XXX There should probably be a registry of valid authentication
         # mechanisms for the client, and we should only import those
         # modules.
-        
-        fullname = 'ZEO.auth.auth_' + protocol
-        try:
-            module = __import__(fullname, globals(), locals(), protocol)
-        except ImportError:
-            log("%s: no such an auth protocol: %s" %
-                (self.__class__.__name__, protocol))
-
-        # instantiate the client authenticator
-        Client = getattr(module, 'Client', None)
-        if not Client:
-            log("%s: %s is not a valid auth protocol, must have a " + \
-                "Client class" % (self.__class__.__name__, protocol))
+
+        module = get_module(protocol)
+        if not module:
+            log2(PROBLEM, "%s: no such an auth protocol: %s" %
+                 (self.__class__.__name__, protocol))
+            return
+
+        storage_class, client, db_class = module
+
+        if not client:
+            log2(PROBLEM,
+                 "%s: %s isn't a valid protocol, must have a Client class" %
+                 (self.__class__.__name__, protocol))
             raise AuthError, "invalid protocol"
         
-        c = Client(stub)
+        c = client(stub)
         
         # Initiate authentication, returns boolean specifying whether OK
         return c.start(self._username, self._password)


=== ZODB3/ZEO/StorageServer.py 1.92.10.1 => 1.92.10.2 ===
--- ZODB3/ZEO/StorageServer.py:1.92.10.1	Tue Apr 29 16:02:54 2003
+++ ZODB3/ZEO/StorageServer.py	Mon May 19 13:46:06 2003
@@ -31,11 +31,11 @@
 
 from ZEO import ClientStub
 from ZEO.CommitLog import CommitLog
-from ZEO.auth.database import Database
 from ZEO.monitor import StorageStats, StatsServer
 from ZEO.zrpc.server import Dispatcher
 from ZEO.zrpc.connection import ManagedServerConnection, Delay, MTDelay
 from ZEO.zrpc.trigger import trigger
+from ZEO.Exceptions import AuthError
 
 import zLOG
 from ZODB.ConflictResolution import ResolvedSerial
@@ -66,7 +66,7 @@
 
     ClientStorageStubClass = ClientStub.ClientStorage
 
-    def __init__(self, server, read_only=0):
+    def __init__(self, server, read_only=0, do_auth=0):
         self.server = server
         # timeout and stats will be initialized in register()
         self.timeout = None
@@ -80,7 +80,18 @@
         self.locked = 0
         self.verifying = 0
         self.log_label = _label
+        self.authenticated = 0
+        self.do_auth = do_auth
+        
+    def finish_auth(self, authenticated):
+        if not self.do_auth:
+            return 1
+        self.authenticated = authenticated
+        return authenticated
 
+    def set_database(self, database):
+        self.database = database
+        
     def notifyConnected(self, conn):
         self.connection = conn # For restart_other() below
         self.client = self.ClientStorageStubClass(conn)
@@ -165,6 +176,9 @@
         For authenticated storages this method will be called by the client
         immediately after authentication is finished.
         """
+        if self.do_auth and not self.authenticated:
+            raise AuthError, "Client was never authenticated with server!"
+
         if self.storage is not None:
             self.log("duplicate register() call")
             raise ValueError, "duplicate register() call"
@@ -664,6 +678,7 @@
         self.read_only = read_only
         self.auth_protocol = auth_protocol
         self.auth_filename = auth_filename
+        self.database = None
         if auth_protocol:
             self._setup_auth(auth_protocol)
         # A list of at most invalidation_queue_size invalidations
@@ -689,40 +704,33 @@
             self.monitor = None
             
     def _setup_auth(self, protocol):
-        # Load the auth protocol
-        fullname = 'ZEO.auth.auth_' + protocol
-        try:
-            module = __import__(fullname, globals(), locals(), protocol)
-        except ImportError:
+        # Can't be done in global scope, because of cyclic references
+        from ZEO.auth import get_module
+
+        module = get_module(protocol)
+        if not module:
             log("%s: no such an auth protocol: %s" %
                 (self.__class__.__name__, protocol))
-            self.auth_protocol = None
             return
         
-        from ZEO.auth.storage import AuthZEOStorage
+        storage_class, client, db_class = module
         
-        # And set up ZEOStorageClass
-        klass = getattr(module, 'StorageClass', None)
-        if not klass or not issubclass(klass, AuthZEOStorage):
-            log(("%s: %s is not a valid auth protocol, must have a " + \
-                "StorageClass class") % (self.__class__.__name__, protocol))
+        if not storage_class or not issubclass(storage_class, ZEOStorage):
+            log(("%s: %s isn't a valid protocol, must have a StorageClass" %
+                 (self.__class__.__name__, protocol)))
             self.auth_protocol = None
             return
-        self.ZEOStorageClass = klass
+        self.ZEOStorageClass = storage_class
 
         log("%s: using auth protocol: %s" % \
             (self.__class__.__name__, protocol))
         
-        dbklass = getattr(module, 'DatabaseClass', None)
-        if not dbklass:
-            dbklass = Database
-
         # We create a Database instance here for use with the authenticator
         # modules. Having one instance allows it to be shared between multiple
         # storages, avoiding the need to bloat each with a new authenticator
         # Database that would contain the same info, and also avoiding any
         # possibly synchronization issues between them.
-        self.database = dbklass(self.auth_filename)
+        self.database = db_class(self.auth_filename)
         
     def new_connection(self, sock, addr):
         """Internal: factory to create a new connection.
@@ -731,10 +739,13 @@
         whenever accept() returns a socket for a new incoming
         connection.
         """
-        z = self.ZEOStorageClass(self, self.read_only)
-        if self.auth_protocol:
-            z.set_database(self.database)
-        c = self.ManagedServerConnectionClass(sock, addr, z, self)
+        if self.auth_protocol and self.database:
+            zstorage = self.ZEOStorageClass(self, self.read_only, do_auth=1)
+            zstorage.set_database(self.database)
+        else:
+            zstorage = self.ZEOStorageClass(self, self.read_only)
+            
+        c = self.ManagedServerConnectionClass(sock, addr, zstorage, self)
         log("new connection %s: %s" % (addr, `c`))
         return c
 




More information about the Zodb-checkins mailing list