[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/Security - SecurityManagement.py:1.1.2.2
Tres Seaver
tseaver@zope.com
Sat, 1 Dec 2001 00:19:03 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/App/Security
In directory cvs.zope.org:/tmp/cvs-serv20386/Zope/App/Security
Modified Files:
Tag: Zope-3x-branch
SecurityManagement.py
Log Message:
- Refactored 'SecurityManagement.new/replaceSecurityManager' to allow
return of prior value from both, and eliminate redundant code.
- Fixed reliance on return from 'SecurityManagement.newSecurityManager'
(which will actually be the *old* value) in 'getSecurityManage'.
- Implemented unit tests for 'SecurityManagement' APIs.
=== Zope3/lib/python/Zope/App/Security/SecurityManagement.py 1.1.2.1 => 1.1.2.2 ===
from ISecurityManagement import ISecurityManagement, ISecurityManagementSetup
from SecurityManager import SecurityManager
+from SecurityManager import setSecurityPolicy as _setSecurityPolicy
from SecurityContext import SecurityContext
__implements__ = ( ISecurityManagement, ISecurityManagementSetup )
@@ -32,12 +33,7 @@
Install a new SecurityManager, using user. Return the
old SecurityManager, if any, or None.
"""
- thread_id = get_ident()
- old = _managers.get( thread_id, None )
- _managers[ thread_id ] = SecurityManager( thread_id
- , SecurityContext( user )
- )
- return old
+ return replaceSecurityManager( SecurityManager( SecurityContext( user ) ) )
def replaceSecurityManager( old_manager ):
"""
@@ -45,7 +41,9 @@
must implement ISecurityManager.
"""
thread_id = get_ident()
+ old = _managers.get( thread_id, None )
_managers[ thread_id ] = old_manager
+ return old
def noSecurityManager():
"""
@@ -68,16 +66,18 @@
if manager is None:
import User
- manager = newSecurityManager( User.UserWithName( 'Anonymous User' ) )
+ newSecurityManager( User.UserWithName( 'Anonymous User' ) )
+ manager=_managers.get( thread_id, None )
return manager
def setSecurityPolicy( aSecurityPolicy ):
"""
- Set the system default security policy.
+ Set the system default security policy, and return the previous
+ value.
This method should only be caused by system startup code.
It should never, for example, be called during a web request.
"""
- SecurityManager.setSecurityPolicy( aSecurityPolicy )
+ return _setSecurityPolicy( aSecurityPolicy )