[Zope3-checkins] SVN: ldapauth/trunk/source.py Fixed an issue with LDAPPrincipalSource.__connect(): if a cached

Derrick Hudson dman at dman13.dyndns.org
Thu Mar 3 10:42:54 EST 2005


Log message for revision 29390:
  Fixed an issue with LDAPPrincipalSource.__connect():  if a cached
  connection exists it was assumed to be valid.  This assumption does not
  hold if, for example, the ldap server was restarted after the connection
  was created.  __connect() now tests the cached connection by binding as the
  admin and discards it if a ldap.SERVER_DOWN exception is raised.
  

Changed:
  U   ldapauth/trunk/source.py

-=-
Modified: ldapauth/trunk/source.py
===================================================================
--- ldapauth/trunk/source.py	2005-03-03 15:26:13 UTC (rev 29389)
+++ ldapauth/trunk/source.py	2005-03-03 15:42:54 UTC (rev 29390)
@@ -191,12 +191,26 @@
             return None
 
     def __connect(self):
-        conn = getattr(self, '_v_conn', None)
-        if not conn:
+        connection = getattr(self, '_v_conn', None)
+
+        if connection is not None :
+            # we have a cached connection,  test it to see if it is still valid
+            try :
+                connection.simple_bind_s(self.manager_dn, self.manager_passwd)
+            #except ldap.LDAPError, err :
+            #except (ldap.CONNECT_ERROR, ldap.SERVER_DOWN), err :
+            except ldap.SERVER_DOWN, err :
+                # it's not valid so discard it
+                connection = None
+
+        # no valid connection exists, create a new one and cache it
+        if connection is None :
             connectstring = 'ldap://%s:%s' % (self.host, self.port)
             connection = ldap.initialize(connectstring)
             self._v_conn = connection
-            return connection
-        else:
-            return conn
- 
+
+        return connection
+    # end __connect()
+
+# end class LDAPPrincipalSource
+



More information about the Zope3-Checkins mailing list