[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/Security/Registries - PrincipalRegistry.py:1.2
Jim Fulton
jim@zope.com
Mon, 15 Jul 2002 18:01:41 -0400
Update of /cvs-repository/Zope3/lib/python/Zope/App/Security/Registries
In directory cvs.zope.org:/tmp/cvs-serv3603/lib/python/Zope/App/Security/Registries
Modified Files:
PrincipalRegistry.py
Log Message:
Added logic to the ZopePublication object to handle placeful
authentication services.
Fixed some bugs in the service manager and made the mapping
implementation there handle only local services.
Refactored the tests in ZopePublication to push some of the
browser-specific tests down to the Browser package.
=== Zope3/lib/python/Zope/App/Security/Registries/PrincipalRegistry.py 1.1 => 1.2 ===
$Id$
"""
+__metaclass__ = type
from Zope.Exceptions import NotFoundError
from Zope.App.Security.ILoginPassword import ILoginPassword
from Zope.ComponentArchitecture import getAdapter, queryAdapter
from Zope.App.Security.IAuthenticationService import IAuthenticationService
from Zope.App.Security.IPrincipal import IPrincipal
+from Zope.App.Security.IUnauthenticatedPrincipal \
+ import IUnauthenticatedPrincipal
class DuplicateLogin(Exception): pass
class DuplicateId(Exception): pass
-# XXX why isn't this subclassing 'Registry' ? ? ?
class PrincipalRegistry:
__implements__ = IAuthenticationService
@@ -52,7 +54,7 @@
if id in self.__principalsById:
raise DuplicateId(id)
self.__defaultid = id
- p = Principal(principal, title, description, '', '')
+ p = UnauthenticatedPrincipal(principal, title, description)
self.__defaultObject = p
return p
@@ -116,16 +118,12 @@
addCleanUp(principalRegistry._clear)
del addCleanUp
-class Principal:
+class PrincipalBase:
- __implements__ = IPrincipal
-
- def __init__(self, id, title, description, login, pw):
+ def __init__(self, id, title, description):
self.__id = id
self.__title = title
self.__description = description
- self.__login = login
- self.__pw = pw
def getId(self):
return self.__id
@@ -136,8 +134,23 @@
def getDescription(self):
return self.__description
+class Principal(PrincipalBase):
+
+ __implements__ = IPrincipal
+
+ def __init__(self, id, title, description, login, pw):
+ super(Principal, self).__init__(id, title, description)
+ self.__login = login
+ self.__pw = pw
+
def getLogin(self):
return self.__login
def validate(self, pw):
return pw == self.__pw
+
+
+class UnauthenticatedPrincipal(PrincipalBase):
+
+ __implements__ = IUnauthenticatedPrincipal
+