[Zope3-checkins] SVN: ldapauth/trunk/ Supporting the trunk branch of Zope3

Nicolas Evrard nicoe at altern.org
Fri Aug 20 21:46:57 EDT 2004


Log message for revision 27204:
  Supporting the trunk branch of Zope3
  
  Added a LDAPPrincipalUser. This user does not store password information as
  this seems to be a bad idea.
  
  


Changed:
  U   ldapauth/trunk/check.py
  U   ldapauth/trunk/interfaces.py
  U   ldapauth/trunk/source.py
  U   ldapauth/trunk/tests/FakeLDAP.py
  U   ldapauth/trunk/tests/test_ldapsource.py
  U   ldapauth/trunk/tests/test_pluggableauthandcache.py
  A   ldapauth/trunk/user.py


-=-
Modified: ldapauth/trunk/check.py
===================================================================
--- ldapauth/trunk/check.py	2004-08-21 01:45:38 UTC (rev 27203)
+++ ldapauth/trunk/check.py	2004-08-21 01:46:57 UTC (rev 27204)
@@ -16,7 +16,7 @@
 $Id$
 """
 import ldap
-from zope.security.proxy import trustedRemoveSecurityProxy
+from zope.security.proxy import removeSecurityProxy
 from zope.interface import implements
 from zope.app.pluggableauth import SimplePrincipal
 
@@ -33,7 +33,7 @@
     
     def testConnection(self):
         self.report = []
-        source = trustedRemoveSecurityProxy(self.context)
+        source = removeSecurityProxy(self.context)
         self.report.append("... check existing connection")
 
         try:
@@ -69,7 +69,7 @@
             
     def testGetPrincipals(self, name):
         self.report = []
-        source = trustedRemoveSecurityProxy(self.context)
+        source = removeSecurityProxy(self.context)
 
         try:
             connectstring = "ldap://%s:%s" % (source.host, source.port)

Modified: ldapauth/trunk/interfaces.py
===================================================================
--- ldapauth/trunk/interfaces.py	2004-08-21 01:45:38 UTC (rev 27203)
+++ ldapauth/trunk/interfaces.py	2004-08-21 01:46:57 UTC (rev 27204)
@@ -19,10 +19,17 @@
 
 from zope.schema import TextLine, Int, List, Password, Choice
 from zope.app.i18n import ZopeMessageIDFactory as _
-from zope.app.pluggableauth.interfaces import IPrincipalSource
+from zope.app.pluggableauth.interfaces import IPrincipalSource, IPrincipal
 
+class ILDAPPrincipal(IPrincipal):
+    """A principal in LDPA language
+    """
 
-
+    login = TextLine(
+            title = _(u'Login'),
+            description = _(u'Login name used on the site'),
+            required = True)
+    
 class ILDAPBasedPrincipalSource(IPrincipalSource):
     """Describe LDAP-based authentication sources.
     

Modified: ldapauth/trunk/source.py
===================================================================
--- ldapauth/trunk/source.py	2004-08-21 01:45:38 UTC (rev 27203)
+++ ldapauth/trunk/source.py	2004-08-21 01:46:57 UTC (rev 27204)
@@ -17,19 +17,23 @@
 """
 
 import ldap
+
 from persistent import Persistent
+
+from zope.exceptions import NotFoundError
+from zope.interface import implements
+
+from zope.app.location import locate
 from zope.app.container.contained import DuplicationError, Contained, setitem
 from zope.app.pluggableauth.interfaces import \
         ILoginPasswordPrincipalSource, IContainerPrincipalSource
-from zope.app.location import locate
-from zope.app.pluggableauth import SimplePrincipal
-from zope.exceptions import NotFoundError
-from zope.interface import implements
+from zope.app.security.interfaces import IPrincipal
 
 from zope.app.cache.caching import getCacheForObject, getLocationForCache
 from zope.app.cache.annotationcacheable import AnnotationCacheable
 
 from interfaces import ILDAPBasedPrincipalSource
+from user import LDAPPrincipal
 
 class LDAPPrincipalSource(Contained, Persistent):
     """A Principal source using LDAP"""
@@ -131,9 +135,8 @@
                 '(%s=%s)' % (self.login_attribute, login))
         if lsearch:
             uid_dn, uid_dict = lsearch[0]
-            principal = SimplePrincipal(
-                    login = uid_dict[self.login_attribute][0],
-                    password = uid_dict['userPassword'][0])
+            principal = LDAPPrincipal(
+                    login = uid_dict[self.login_attribute][0])
             return principal
         else:
             return None
@@ -162,9 +165,8 @@
         principals = []
         for node in lsearch:
             node_dn, node_dict = node
-            principal = SimplePrincipal(
-                    login = node_dict[self.login_attribute][0],
-                    password = node_dict['userPassword'][0])
+            principal = LDAPPrincipal(
+                    login = node_dict[self.login_attribute][0])
             try:
                 self[principal.login] = principal
             except DuplicationError:
@@ -176,22 +178,15 @@
 
     def authenticate(self, uid, password):
         if password:
-            principal = self[uid]
-            if principal and principal.password == password:
+            l = self.__connect()
+            dn = '%s=%s,' % (self.login_attribute, uid) + self.basedn
+            try:
+                l.simple_bind_s(dn, password)
+                principal = LDAPPrincipal(login = uid)
+                self[uid] = principal
                 return principal
-            elif principal and principal.password != password:
+            except ldap.INVALID_CREDENTIALS:
                 return None
-            else:
-                l = self.__connect()
-                dn = '%s=%s,' % (self.login_attribute, uid) + self.basedn
-                try:
-                    l.simple_bind_s(dn, password)
-                    principal = SimplePrincipal(login = uid,
-                            password = password)
-                    self[uid] = principal
-                    return principal
-                except ldap.INVALID_CREDENTIALS:
-                    return None
         else:
             return None
 

Modified: ldapauth/trunk/tests/FakeLDAP.py
===================================================================
--- ldapauth/trunk/tests/FakeLDAP.py	2004-08-21 01:45:38 UTC (rev 27203)
+++ ldapauth/trunk/tests/FakeLDAP.py	2004-08-21 01:46:57 UTC (rev 27204)
@@ -4,7 +4,7 @@
 #               independently of a running LDAP server
 #
 # This software is governed by a license (ZPL v2.1).
-# (c) Jens Vagelpohl
+# (c) Jens Vagelpohl, Nicolas Évrard
 #
 #####################################################################
 __version__='$Revision: 1.7 $'[11:-2]

Modified: ldapauth/trunk/tests/test_ldapsource.py
===================================================================
--- ldapauth/trunk/tests/test_ldapsource.py	2004-08-21 01:45:38 UTC (rev 27203)
+++ ldapauth/trunk/tests/test_ldapsource.py	2004-08-21 01:46:57 UTC (rev 27204)
@@ -53,7 +53,6 @@
 
     def test_getPrincipal(self):
         toto = self.source.getPrincipal('\t\ttoto_l')
-        self.assertEqual(toto.password, 'toto_p')
         self.assertEqual(toto.login, 'toto_l')
         self.assertRaises(NotFoundError, self.source.getPrincipal, '\t\tmoo')
 
@@ -65,10 +64,12 @@
         self.assertEquals(len(self.source.getPrincipals('ta')), 1)
 
     def test_authenticate(self):
-        self.assertEquals(self.source.authenticate('toto_l', 'toto_p').login,
+        self.assertEquals(
+                self.source.authenticate('toto_l', 'toto_p').login,
                 'toto_l')
-        self.assertEquals(self.source.authenticate('toto_l', 'toto_p').password,
-                'toto_p')
+        self.assertEquals(
+                self.source.authenticate('toto_l', 'toto_p').login,
+                'toto_l')
         self.assertEquals(self.source.authenticate('toto_l', 'toto'), None)
         self.assertEquals(self.source.authenticate('toto', 'toto'), None)
 

Modified: ldapauth/trunk/tests/test_pluggableauthandcache.py
===================================================================
--- ldapauth/trunk/tests/test_pluggableauthandcache.py	2004-08-21 01:45:38 UTC (rev 27203)
+++ ldapauth/trunk/tests/test_pluggableauthandcache.py	2004-08-21 01:46:57 UTC (rev 27204)
@@ -48,8 +48,7 @@
 from zope.app.pluggableauth.interfaces import IPrincipalSource
 from zope.app.pluggableauth import PluggableAuthenticationService, \
         SimplePrincipal
-from zope.app.pluggableauth.browser.authentication import \
-    PrincipalAuthenticationView
+from zope.app.pluggableauth import PrincipalAuthenticationView
 
 from zope.publisher.interfaces.http import IHTTPCredentials
 from zope.publisher.browser import TestRequest as Request
@@ -139,11 +138,9 @@
         source_toto = source.getPrincipal('\t\ttoto_l')
         auth_toto = auth.getPrincipal(source_toto.id)
         self.assertEqual('toto_l', auth_toto.login)
-        self.assertEqual('toto_p', auth_toto.password)
 
     def test_authServiceGetPrincipals(self):
         users = self._auth.getPrincipals('t')
-        self.assertEquals(len(list(users)), 3)
         for user in users:
             self.assert_('t' in user.login)
         self.assertEquals(len(list(self._auth.getPrincipals('ta'))), 1)

Added: ldapauth/trunk/user.py
===================================================================
--- ldapauth/trunk/user.py	2004-08-21 01:45:38 UTC (rev 27203)
+++ ldapauth/trunk/user.py	2004-08-21 01:46:57 UTC (rev 27204)
@@ -0,0 +1,43 @@
+##############################################################################
+#
+# Copyright (c) 2004 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""A LDAP user for the ldapauth plugable authentication module.
+
+$Id$
+"""
+
+from zope.interface import implements
+
+from zope.app.container.contained import Contained
+from zope.app.security.interfaces import IPrincipal
+
+class LDAPPrincipal(Contained):
+    """A really simple implemantation of the principal interface"""
+
+    implements(IPrincipal)
+
+    def __init__(self, login):
+        self._id = login
+        self.login = login
+        self.title = ''
+        self.description = ''
+
+    def _getId(self):
+        source = self.__parent__
+        auth = source.__parent__
+        return "%s\t%s\t%s" % (auth.earmark, source.__name__, self._id)
+
+    def _setId(self, id):
+        self._id = id
+
+    id = property(_getId, _setId)


Property changes on: ldapauth/trunk/user.py
___________________________________________________________________
Name: svn:eol-style
   + native



More information about the Zope3-Checkins mailing list