Edgewall Software

Changes between Version 10 and Version 11 of TracDev/SecurityBranch


Ignore:
Timestamp:
Dec 8, 2007, 11:07:17 PM (16 years ago)
Author:
osimons
Comment:

Updated the API examples to use new resource descriptors.

Legend:

Unmodified
Added
Removed
Modified
  • TracDev/SecurityBranch

    v10 v11  
    5454}}}
    5555
    56 New style:
     56New style is based on adding a resource descriptor (`trac.resource.Resource`) as identification in permission checks:
    5757
    5858{{{
     
    6464# wish to restrict 'WikiStart' you must provide ('wiki', 'WikiStart').
    6565if 'WIKI_MODIFY' in req.perm('wiki', 'WikiStart', 20):
    66         ...
     66    ...
    6767
    68 # or, checking the current resource context
    69 if 'WIKI_MODIFY' in req.perm(context):
    70         ...
     68# A resource descriptor can be created and reused for the purpose.
     69page_resource = Resource('wiki', 'WikiStart', 20)
     70if 'WIKI_MODIFY' in req.perm(page_resource):
     71    ...
    7172
    7273# Assert that user has permission
    73 req.perm.require('WIKI_MODIFY', 'wiki', 'WikiStart')
     74req.perm(page_resource).require('WIKI_MODIFY')
    7475# or ...
    75 req.perm.require('WIKI_MODIFY', context)
     76req.perm(page_resource).require('WIKI_MODIFY')
    7677}}}
    7778
     
    8384#!python
    8485class IPermissionPolicy(Interface):
    85     """A security policy provider."""
    86     def check_permission(username, action, context):
    87         """Check that username can perform action in context.
     86    """A security policy provider used for fine grained permission checks."""
    8887
    89         Must return True if action is allowed, False if action is denied, or
    90         None if indifferent."""
     88    def check_permission(action, username, resource, perm):
     89        """Check that the action can be performed by username on the resource
     90        ...
    9191}}}
     92
     93See `trac.perm.IPermissionPolicy` source code for much more information.
    9294
    9395== Testing the features ==