[PEAK] peak.security
darryl
developer at csrules.dyndns.org
Fri Dec 5 17:30:24 EST 2003
Given all the content in your very detailed and expressive message i
came up with the following:
----------------------------------------------------------------------------------------------
# peak imports
from peak.api import *
class Owner(security.Permission):
pass
class Building(object):
security.allow(
burnBuilding = Owner
)
def burnBuilding(self):
print "burn baby burn!"
class BuildingRules(security.RuleSet):
rules = Items(
checkCanBurn = [Owner.of(Building)]
)
def checkCanBurn(self, attempt):
return attempt.user is attempt.subject.owner
BuildingRules.declareRulesFor(security.IPermissionChecker)
class MyBuildingInteraction(security.Interaction):
user = None
permissionProtocol = security.IPermissionChecker
----------------------------------------------------------------------------------------------
From the handy python prompt:
>>> from security_test import *
>>> myHouse=Building()
>>> Maniac = Owner()
>>> myHouse.owner = Maniac
>>> theInteraction=MyBuildingInteraction(user=Maniac)
>>>allowed = theInteraction.allows(myHouse,"burnBuilding")
>>> if allowed:
... myHouse.burnBuilding()
...
burn baby burn!
Am i getting close?
More information about the PEAK
mailing list