[Zope3-checkins] CVS: Zope3/src/zope/app/security - zopepolicy.py:1.6

Albertas Agejevas alga@codeworks.lt
Thu, 13 Mar 2003 11:28:47 -0500


Update of /cvs-repository/Zope3/src/zope/app/security
In directory cvs.zope.org:/tmp/cvs-serv11423/src/zope/app/security

Modified Files:
	zopepolicy.py 
Log Message:
Made SecurityManager.getPrincipal() return a Principal object wrapped
in a context of its AuthenticationService.


=== Zope3/src/zope/app/security/zopepolicy.py 1.5 => 1.6 ===
--- Zope3/src/zope/app/security/zopepolicy.py:1.5	Tue Feb 11 21:17:31 2003
+++ Zope3/src/zope/app/security/zopepolicy.py	Thu Mar 13 11:28:16 2003
@@ -50,10 +50,8 @@
 globalContext = object()
 
 
-def _computeBasePrincipalRoles(principalid, object):
-    auth = getService(object, Authentication)
-    p = auth.getPrincipal(principalid)
-    roles = tuple(p.getRoles()) + ('Anonymous',)
+def _computeBasePrincipalRoles(principal, object):
+    roles = tuple(principal.getRoles()) + ('Anonymous',)
     roledict = {}
     for role in roles:
         roledict[role] = Allow
@@ -98,7 +96,7 @@
         if user is system_user:
             return 1
         roledict = _computeBasePrincipalRoles(user, object)
-        principals = {user : roledict}
+        principals = {user.getId() : roledict}
 
         role_permissions = {}
         remove = {}
@@ -245,6 +243,7 @@
     permissions = {}
     roles = _computeBasePrincipalRoles(principal, object)
     role_permissions = {}
+    principalid = principal.getId()
 
     # Make two passes.
 
@@ -252,12 +251,12 @@
 
 
     # get placeless principal permissions
-    for permission, setting in getPermissionsForPrincipal(principal):
+    for permission, setting in getPermissionsForPrincipal(principalid):
         if permission not in permissions:
             permissions[permission] = setting
 
     # get placeless principal roles
-    for role, setting in getRolesForPrincipal(principal):
+    for role, setting in getRolesForPrincipal(principalid):
         if role not in roles:
             roles[role] = setting
 
@@ -268,14 +267,14 @@
         prinper = queryAdapter(place, IPrincipalPermissionMap)
         if prinper is not None:
             for permission, setting in prinper.getPermissionsForPrincipal(
-                principal):
+                principalid):
                 if permission not in permissions:
                     permissions[permission] = setting
 
         # Collect principal roles
         prinrole = queryAdapter(place, IPrincipalRoleMap)
         if prinrole is not None:
-            for role, setting in prinrole.getRolesForPrincipal(principal):
+            for role, setting in prinrole.getRolesForPrincipal(principalid):
                 if role not in roles:
                     roles[role] = setting