[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/OFS/Services/AuthenticationService - AuthenticationService.py:1.2 IUser.py:1.2 User.py:1.2 configure.zcml:1.3

Stephan Richter srichter@cbu.edu
Sat, 13 Jul 2002 14:26:56 -0400


Update of /cvs-repository/Zope3/lib/python/Zope/App/OFS/Services/AuthenticationService
In directory cvs.zope.org:/tmp/cvs-serv32438/lib/python/Zope/App/OFS/Services/AuthenticationService

Modified Files:
	AuthenticationService.py IUser.py User.py configure.zcml 
Log Message:
Yes, I forgot the configure.zcml.

I also added Role support now. While it uses the global registry right now,
I am already working on a IAnnotations version. I will check that in soon.


=== Zope3/lib/python/Zope/App/OFS/Services/AuthenticationService/AuthenticationService.py 1.1 => 1.2 ===
                                   IHomogenousContainer):
     """TTW manageable authentication service"""
 
+    def getAllUsers():
+        """Get all users of the Service."""
+
 
 class AuthenticationService(BTreeContainer):
 
@@ -48,6 +51,9 @@
             if p.getLogin() == login:
                 return p
         return None
+
+    def getAllUsers(self):
+        return self.values()
 
     ############################################################
     # Implementation methods for interface


=== Zope3/lib/python/Zope/App/OFS/Services/AuthenticationService/IUser.py 1.1 => 1.2 ===
     def getLogin():
         """Get the login for the user."""
 
+    def getRoles():
+        """Get the roles for the user."""
+
     def validate(pw):
         """Seee whether the password is valid."""
 
@@ -38,6 +41,9 @@
 
     def setLogin(login):
         """Set login of User."""
+
+    def setRoles(roles):
+        """Set roles of User."""
 
     def setPassword(password):
         """Set password of User."""


=== Zope3/lib/python/Zope/App/OFS/Services/AuthenticationService/User.py 1.1 => 1.2 ===
 $Id$
 """
 from Persistence import Persistent
-from Zope.App.OFS.Annotation.IAnnotatable import IAnnotatable
+from Zope.App.OFS.Annotation.IAttributeAnnotatable import IAttributeAnnotatable
 from Zope.App.OFS.Services.AuthenticationService.IUser import IUser
+from Zope.App.Security.Grants.Global.PrincipalRoleManager import \
+     principalRoleManager
 
 class User(Persistent):
     """A persistent implementation of the IUser interface """
     
-    __implements__ =  IUser, IAnnotatable
+    __implements__ =  IUser, IAttributeAnnotatable
 
     def __init__(self, id, title, description, login, pw):
         self.__id = id
@@ -42,6 +44,12 @@
         'See Zope.App.OFS.Services.AuthenticationService.IUser.IReadUser'
         return self.__login
 
+    def getRoles(self):
+        'See Zope.App.OFS.Services.AuthenticationService.IUser.IReadUser'
+        roles = principalRoleManager.getRolesForPrincipal(self.getId())
+        roles = map(lambda r: r[0], roles)
+        return roles
+    
     def validate(self, pw):
         'See Zope.App.OFS.Services.AuthenticationService.IUser.IReadUser'
         return pw == self.__pw
@@ -78,5 +86,11 @@
     def setPassword(self, password):
         'See Zope.App.OFS.Services.AuthenticationService.IUser.IWriteUser'
         self.__pw = password
+
+    def setRoles(self, roles):
+        'See Zope.App.OFS.Services.AuthenticationService.IUser.IReadUser'
+        id = self.getId()
+        for role in roles:
+            principalRoleManager.assignRoleToPrincipal(role, id)
     #
     ############################################################


=== Zope3/lib/python/Zope/App/OFS/Services/AuthenticationService/configure.zcml 1.2 => 1.3 ===
   <factory id="AuthenticationService" permission="Zope.ManageServices" />
     <require
         permission="Zope.View"
-        interface="Zope.App.Security.IAuthenticationService." />
+        interface=".AuthenticationService.ILocalAuthenticationService." />
     <require
         permission="Zope.ManageServices"
         interface="Zope.App.OFS.Container.IContainer." />
@@ -29,6 +29,6 @@
 
 <!-- Further directives -->
 
-<!-- No config file! include package=".Views" /  -->
+<include package=".Views" />
 
 </zopeConfigure>