[Zope] Adding security to a new class method...
Brian Lloyd
brian@zope.com
Tue, 28 May 2002 11:31:02 -0400
> I've written some code that programmatically adds a method to the
> ObjectManager class, but I want to secure my method so that not
> everyone can
> access it. How can I secure the method after the class has been
> registered?
>
> Thanks,
>
> Jeff
Hi Jeff - here's something (untested) that _should_ work:
from AccessControl.SecurityInfo import ClassSecurityInfo
from OFS.ObjectManager import ObjectManager
# Hack ObjectManager and add security. Note that whether
# this is _possible_ and whether its really a _good idea_
# are two separate things :) This may not necessarily
# do what you expect in terms of protecting subclasses,
# for example.
def myMethod(self):
return 'something'
# add method to class
ObjectManager.myMethod = myMethod
# add security assertions.
security = ClassSecurityInfo()
security.declareProtected('Some permission', 'myMethod')
security.apply(ObjectManager)
Brian Lloyd brian@zope.com
V.P. Engineering 540.361.1716
Zope Corporation http://www.zope.com