|
Testing Security in a Debugging Session
Submitted by: slinkp
Last Edited: 2003-02-28
Category: Security
|
Average rating is:
0.0 out of 5
|
(0 ratings) |
|
Description:
You're debugging Zope at the python prompt and want to
find out e.g. if a user has permission to do something.
Kudos to Chris McDonough and Sean Upton for showing me how to do
this on the zope mailing list!
Quick summary: You need to register the user with the
SecurityManager, like so:
from AccessControl.SecurityManagement import newSecurityManager
user = some_folder.acl_users.getUser('UserName').__of__(some_folder.acl_users)
newSecurityManager(None, user)
Now let's look at that in the context of a debugging session,
and also see what happens if you DON'T do this.
|
Source (Text):
Zope debugging session for /zope/InstanceHome
The root application object is bound to name 'app'.
To let other people see your changes, you must:
get_transaction().commit()
To see other people's changes, you must:
app._p_jar.sync()
>>> folder = app.paul_stuff.test_dynausers
>>> user = folder.acl_users.getUser('bob')
>>> user
bob
>>> user.getRoles()
('Manager', 'ldap_role', 'Authenticated')
>>>
...
>>> from AccessControl.PermissionRole import rolesForPermissionOn
>>> rolesForPermissionOn('View', folder.testview)
('Manager', 'ldap_role')
>>>
...
...
...
>>> print user.has_permission('View', folder.testview)
None
>>>
...
...
...
...
...
...
...
>>> from AccessControl import getSecurityManager
>>> getSecurityManager().getUser()
Anonymous User
>>>
...
...
...
...
>>> from AccessControl.SecurityManagement import newSecurityManager
>>> user = folder.acl_users.getUser('bob').__of__(folder.acl_users)
>>>
...
...
>>> newSecurityManager(None, user)
>>>
...
>>> getSecurityManager().getUser()
bob
>>>
...
>>> print user.has_permission('View', folder.testview)
1
|
Explanation:
Exploring zope in an interactive debugging session is
HIGHLY recommended. Instructions on getting into a
live session are in the "Developers' Guide:"http://www.zope.org/Documentation/Books/ZDG/current/TestingAndDebugging.stx
But unfortunately you will quickly find that there's a lot of
"magic" that Zope does, which you have to invoke manually
in a debug session, or else some things just won't work right.
For example: security. There's nothing in the dev guide about
debugging security, and without the magic words shown in this
recipe, some_user.has_permission() fails mysteriously.
There may well be other security methods that work the same
way, using getSecurityManager().getUser() instead of the user
you might have expected.
|
Comments:
No Comments
|
|