[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/Security - SimpleSecurityPolicies.py:1.1.2.1 SecurityManager.py:1.1.2.5
Tres Seaver
tseaver@zope.com
Fri, 30 Nov 2001 22:51:14 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/App/Security
In directory cvs.zope.org:/tmp/cvs-serv1658
Modified Files:
Tag: Zope-3x-branch
SecurityManager.py
Added Files:
Tag: Zope-3x-branch
SimpleSecurityPolicies.py
Log Message:
- Refactor trivial security policies into their own module,
'SimpleSecurityPolicies'; rename 'DefaultSecurityPolicy' =>
'ParanoidSecurityPolicy'.
=== Added File Zope3/lib/python/Zope/App/Security/SimpleSecurityPolicies.py ===
# Copyright (c) 2001 Zope Coporation and Contributors. All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 1.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
""" Simple ISecurityPolicy implementations."""
from ISecurityPolicy import ISecurityPolicy
from Zope.Exceptions import Unauthorized
class ParanoidSecurityPolicy:
"""
Deny all access.
"""
__implements__ = ISecurityPolicy
def validate( self, name, value, context ):
raise Unauthorized
def checkPermission( sel, permission, object, context ):
return 0
class PermissiveSecurityPolicy:
"""
Allow all access
"""
__implements__ = ISecurityPolicy
def validate( self, name, value, context ):
pass
def checkPermission( self, permission, object, context ):
return 1
=== Zope3/lib/python/Zope/App/Security/SecurityManager.py 1.1.2.4 => 1.1.2.5 ===
import os, string
-
-from ISecurityPolicy import ISecurityPolicy
-from Zope.Exceptions import Unauthorized
+from SimpleSecurityPolicies import ParanoidSecurityPolicy
MAX_STACK_SIZE = 100
-class DefaultSecurityPolicy:
- """
- Deny all.
- """
- __implements__ = ISecurityPolicy
-
- def validate( self, name, value, context ):
- raise Unauthorized
-
- def checkPermission( sel, permission, object, context ):
- return 0
+_defaultPolicy = ParanoidSecurityPolicy()
-
-_defaultPolicy = DefaultSecurityPolicy()
-
-def setSecurityPolicy(aSecurityPolicy):
+def setSecurityPolicy( aSecurityPolicy ):
"""
Set the system default security policy.
@@ -39,8 +24,9 @@
never, for example, be called during a web request.
"""
global _defaultPolicy
- last = _defaultPolicy
- _defaultPolicy = aSecurityPolicy
+
+ last, _defaultPolicy = _defaultPolicy, aSecurityPolicy
+
return last
from ISecurityManager import ISecurityManager