[Zope3-checkins] SVN: Zope3/branches/mgedmin-security/src/zope/app/publication/ Changed zopepublication to use interactions instead of security managers.

Marius Gedminas marius at pov.lt
Wed May 12 16:40:35 EDT 2004


Log message for revision 24608:
Changed zopepublication to use interactions instead of security managers.




-=-
Modified: Zope3/branches/mgedmin-security/src/zope/app/publication/tests/test_zopepublication.py
===================================================================
--- Zope3/branches/mgedmin-security/src/zope/app/publication/tests/test_zopepublication.py	2004-05-12 20:28:36 UTC (rev 24607)
+++ Zope3/branches/mgedmin-security/src/zope/app/publication/tests/test_zopepublication.py	2004-05-12 20:40:35 UTC (rev 24608)
@@ -33,7 +33,7 @@
 from zope.publisher.interfaces import IRequest, IPublishTraverse
 from zope.publisher.browser import BrowserResponse
 from zope.security import simplepolicies
-from zope.security.management import setSecurityPolicy, getSecurityManager
+from zope.security.management import setSecurityPolicy, getInteraction
 
 from zope.app import zapi
 from zope.app.tests.placelesssetup import PlacelessSetup
@@ -370,8 +370,8 @@
         defineChecker(Folder, InterfaceChecker(IFolder))
 
         self.publication.beforeTraversal(self.request)
-        user = getSecurityManager().getPrincipal()
-        self.assertEqual(user, self.request.principal)
+        self.assertEqual(list(getInteraction().participations),
+                         [self.request])
         self.assertEqual(self.request.principal.id, 'anonymous')
         root = self.publication.getApplication(self.request)
         self.publication.callTraversalHooks(self.request, root)
@@ -382,8 +382,8 @@
         ob = self.publication.traverseName(self.request, ob, 'f2')
         self.publication.afterTraversal(self.request, ob)
         self.assertEqual(self.request.principal.id, 'test.bob')
-        user = getSecurityManager().getPrincipal()
-        self.assertEqual(user, self.request.principal)
+        self.assertEqual(list(getInteraction().participations),
+                         [self.request])
 
     def testTransactionCommitAfterCall(self):
         root = self.db.open().root()

Modified: Zope3/branches/mgedmin-security/src/zope/app/publication/zopepublication.py
===================================================================
--- Zope3/branches/mgedmin-security/src/zope/app/publication/zopepublication.py	2004-05-12 20:28:36 UTC (rev 24607)
+++ Zope3/branches/mgedmin-security/src/zope/app/publication/zopepublication.py	2004-05-12 20:40:35 UTC (rev 24608)
@@ -27,7 +27,7 @@
 from zope.publisher.interfaces import Retry, IExceptionSideEffects
 from zope.publisher.interfaces import IRequest, IPublication
 
-from zope.security.management import newSecurityManager
+from zope.security.management import newInteraction, endInteraction
 from zope.security.checker import ProxyFactory
 from zope.security.proxy import trustedRemoveSecurityProxy
 from zope.proxy import removeAllProxies
@@ -73,7 +73,7 @@
                 raise Unauthorized # If there's no default principal
 
         request.setPrincipal(p)
-        newSecurityManager(request.principal)
+        newInteraction(request)
         get_transaction().begin()
 
     def _maybePlacefullyAuthenticate(self, request, ob):
@@ -102,9 +102,7 @@
                 return
 
         request.setPrincipal(principal)
-        newSecurityManager(request.principal)
 
-
     def callTraversalHooks(self, request, ob):
         # Call __before_publishing_traverse__ hooks
 
@@ -152,6 +150,11 @@
     def afterCall(self, request, ob):
         txn = get_transaction()
         self.annotateTransaction(txn, request, ob)
+
+        # Make sure the interaction is ended
+        try: endInteraction()
+        except: pass # XXX I do not like this except clause, but it makes tests pass
+
         txn.commit()
 
     def annotateTransaction(self, txn, request, ob):
@@ -227,6 +230,10 @@
         # 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):
             tryToLogWarning('ZopePublication',




More information about the Zope3-Checkins mailing list