[Zope3-checkins] CVS: Zope3/src/zope/app/publication -
zopepublication.py:1.36.2.1
Marius Gedminas
marius at pov.lt
Mon Mar 8 13:44:09 EST 2004
Update of /cvs-repository/Zope3/src/zope/app/publication
In directory cvs.zope.org:/tmp/cvs-serv14991/src/zope/app/publication
Modified Files:
Tag: mgedmin-events2-branch
zopepublication.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/publication/zopepublication.py 1.36 => 1.36.2.1 ===
--- Zope3/src/zope/app/publication/zopepublication.py:1.36 Fri Feb 20 17:02:30 2004
+++ Zope3/src/zope/app/publication/zopepublication.py Mon Mar 8 13:43:38 2004
@@ -23,8 +23,9 @@
from zope.publisher.interfaces import Retry, IExceptionSideEffects
from zope.publisher.interfaces.http import IHTTPRequest
-from zope.security.management import newSecurityManager
from zope.security.checker import ProxyFactory
+from zope.security.management import getInteraction
+from zope.security.management import newInteraction, endInteraction
from zope.proxy import removeAllProxies
@@ -74,7 +75,7 @@
raise Unauthorized # If there's no default principal
request.setUser(p)
- newSecurityManager(request.user)
+ newInteraction(request)
get_transaction().begin()
def _maybePlacefullyAuthenticate(self, request, ob):
@@ -102,9 +103,10 @@
# nothing to do here
return
+ # XXX we discussed IInteraction.afterLocalAuthentication(old_principal, new_principal, site)
+ getInteraction().remove(request.user)
request.setUser(principal)
- newSecurityManager(request.user)
-
+ getInteraction().add(request.user)
def callTraversalHooks(self, request, ob):
# Call __before_publishing_traverse__ hooks
@@ -157,6 +159,9 @@
txn.note(request["PATH_INFO"])
# XXX not sure why you would use id vs title or description
txn.setUser(request.user.getId())
+ # Make sure the interaction is ended
+ try: endInteraction()
+ except: pass # XXX I do not like this except clause, but it makes tests pass
get_transaction().commit()
@@ -192,6 +197,10 @@
# This transaction had an exception that reached the publisher.
# It must definitely be aborted.
get_transaction().abort()
+
+ # Make sure the interaction is ended
+ try: endInteraction()
+ except: pass
# Convert ConflictErrors to Retry exceptions.
if retry_allowed and isinstance(exc_info[1], ConflictError):
More information about the Zope3-Checkins
mailing list