[Zope3-checkins] CVS: Zope3/src/zope/app/workflow/stateful - instance.py:1.16.2.2

Marius Gedminas marius at pov.lt
Mon Mar 8 13:44:12 EST 2004


Update of /cvs-repository/Zope3/src/zope/app/workflow/stateful
In directory cvs.zope.org:/tmp/cvs-serv14991/src/zope/app/workflow/stateful

Modified Files:
      Tag: mgedmin-events2-branch
	instance.py 
Log Message:
Replaced security managers and security contexts with interactions.  There is
at most one active interaction per thread, accessible with getInteraction().
Code that used getSecurityManager to get the authenticated principal should now
use the current interaction.  Note that the interaction contains an iterable of
principals instead of just one principal.  Code that used a security manager to
implement user logins should now use newInteraction/ endInteraction pair.  Code
that used a security manager to check whether the authenticated user has a
permission to do something should now ask the security policy directly (there's
a new global function getSecurityPolicy).

Interactions are tied with security policies: ISecurityPolicy has a method
used to create a new interaction for a given request.  This is not necessarily
the best idea, perhaps a global hook (setInteractionFactory) would be better.

Things not done yet:
 - Not all places in the code are ready to cope with more than one principal.
 - The README in zope.security and the sandbox security example need to be
   updated.
 - There was an idea of using a notification method in IInteraction that would
   let it customize the handling of local authentication during traversal.
   It could be e.g. afterLocalAuthentication(old_principal, new_principal, site)
   Currently the ZopePublication code just does
     interaction.remove(old_principal)
     interaction.add(new_principal)
   when request.user is changed during traversal.
 - The interaction API could be polished a bit (perhaps the request argument
   to newInteraction should be optional, perhaps there should be an alternative
   principals argument to newInteraction, perhaps endInteraction should not
   raise an exception when it is called outside of an active interaction).
 - It is not clearly cut when security checks should use the global interaction
   and when they should use the interaction of the security proxy.  Perhaps
   use the global one if interaction stored in the proxy is None?
 - It is not defined explicitly where the interaction argument can safely be
   None (as an argument to ProxyFactory, as an argument to security checkers,
   etc.).
 - Some places that construct security proxies pass None to ProxyFactory.
   Perhaps they should use the current interaction instead.  Or maybe not.





=== Zope3/src/zope/app/workflow/stateful/instance.py 1.16.2.1 => 1.16.2.2 ===
--- Zope3/src/zope/app/workflow/stateful/instance.py:1.16.2.1	Mon Feb 23 14:18:05 2004
+++ Zope3/src/zope/app/workflow/stateful/instance.py	Mon Mar  8 13:43:42 2004
@@ -38,7 +38,7 @@
 from zope.interface import directlyProvides, implements
 from zope.proxy import removeAllProxies
 from zope.schema import getFields
-from zope.security.management import getSecurityManager
+from zope.security.management import getInteraction, getSecurityPolicy
 from zope.security.checker import CheckerPublic, Checker
 from zope.security.proxy import Proxy
 from zope.tales.engine import Engine
@@ -225,7 +225,9 @@
         ctx = {}
         # data should be readonly for condition-evaluation
         ctx['data'] = self.data
-        ctx['principal'] = getSecurityManager().getPrincipal()
+        principals = list(getInteraction().principals)
+        assert len(principals) == 1 # XXX
+        ctx['principal'] = principals[0]
 
         # XXX This needs to be discussed:
         # how can we know if this ProcessInstance is annotated
@@ -274,7 +276,8 @@
         return script(contexts)
 
     def _outgoingTransitions(self, clean_pd):
-        sm = getSecurityManager()
+        policy = getSecurityPolicy()
+        interaction = getInteraction()
         ret = []
         contexts = self._getContext()
 
@@ -285,8 +288,8 @@
                 #
                 if (permission is not None
                     and permission is not CheckerPublic
-                    and not sm.checkPermission(permission, self)
-                    ):
+                    and not policy.checkPermission(permission, self,
+                                                   interaction)):
                     continue
 
                 ctx = self._extendContext(trans, contexts)




More information about the Zope3-Checkins mailing list