[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/Security - PrincipalRegistry.py:1.1.2.4

Guido van Rossum guido@python.org
Thu, 13 Dec 2001 12:22:46 -0500


Update of /cvs-repository/Zope3/lib/python/Zope/App/Security
In directory cvs.zope.org:/tmp/cvs-serv31148

Modified Files:
      Tag: Zope-3x-branch
	PrincipalRegistry.py 
Log Message:
Implement authenticate() method that uses HTTP basic authentication.

=== Zope3/lib/python/Zope/App/Security/PrincipalRegistry.py 1.1.2.3 => 1.1.2.4 ===
 from IPrincipal import IPrincipal
 from Zope.Exceptions import NotFoundError
+from ILoginPassword import ILoginPassword
+from Zope.ComponentArchitecture import getAdapter
 
 class DuplicateLogin(Exception): pass
 class DuplicateId(Exception): pass
 
 class PrincipalRegistry:
 
-
     __implements__ = IAuthenticationService
 
     # Methods implementing IAuthenticationService
     
     def authenticate(self, request):
-        pass
-        
+        a = getAdapter(request, ILoginPassword, None)
+        if a is not None:
+            login = a.getLogin()
+            if login is not None:
+                p = self.__principalsByLogin.get(login, None)
+                if p is not None:
+                    password = a.getPassword()
+                    if p.validate(password):
+                        return p.getId()
+        return None
+
     def unauthorized(self, id, request):
         pass