source: TI12-security/trunk/NDG_XACML/ndg/xacml/core/context/pdp.py @ 6825

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI12-security/trunk/NDG_XACML/ndg/xacml/core/context/pdp.py@6825
Revision 6825, 2.6 KB checked in by pjkersha, 10 years ago (diff)

Moved PDP evaluate content into Policy.evaluate

Line 
1"""NDG XACML Policy Decision Point type definition
2
3NERC DataGrid Project
4"""
5__author__ = "P J Kershaw"
6__date__ = "25/02/10"
7__copyright__ = "(C) 2010 Science and Technology Facilities Council"
8__contact__ = "Philip.Kershaw@stfc.ac.uk"
9__license__ = "BSD - see LICENSE file in top-level directory"
10__contact__ = "Philip.Kershaw@stfc.ac.uk"
11__revision__ = "$Id: $"
12import logging
13log = logging.getLogger(__name__)
14
15from ndg.xacml.core.context.pdpinterface import PDPInterface
16from ndg.xacml.core.policy import Policy
17
18
19class PDP(PDPInterface):
20    """A XACML Policy Decision Point implementation.  It supports the use of a
21    single policy but not policy sets
22    """
23    __slots__ = ('__policy', )
24   
25    def __init__(self, policy=None):
26        """
27        @param policy: policy object for PDP to use to apply access control
28        decisions, may be omitted.
29        @type policy: ndg.xacml.core.policy.Policy / None
30        """
31        self.__policy = None
32        if policy is not None:
33            self.policy = policy
34           
35        self.__request = None
36
37    @classmethod
38    def fromPolicySource(cls, source, readerFactory):
39        """Create a new PDP instance with a given policy
40        @param source: source for policy
41        @type source: type (dependent on the reader set, it could be for example
42        a file path string, file object, XML element instance)
43        @param readerFactory: reader factory returns the reader to use to read
44        this policy
45        @type readerFactory: ndg.xacml.parsers.AbstractReader derived type
46        """           
47        pdp = cls()
48        pdp.policy = Policy.fromSource(source, readerFactory)
49        return pdp
50   
51    @property
52    def policy(self):
53        """policy object for PDP to use to apply access control decisions"""
54        return self.__policy
55   
56    @policy.setter
57    def policy(self, value):
58        '''policy object for PDP to use to apply access control decisions'''
59        if not isinstance(value, Policy):
60            raise TypeError('Expecting %r derived type for "policy" input; got '
61                            '%r instead' % (Policy, type(value)))
62        self.__policy = value
63                                       
64    def evaluate(self, request):
65        """Make an access control decision for the given request based on the
66        single policy provided
67       
68        @param request: XACML request context
69        @type request: ndg.xacml.core.context.request.Request
70        @return: XACML response instance
71        @rtype: ndg.xacml.core.context.response.Response
72        """
73        response = self.policy.evaluate(request)
74       
75        return response
76
77
78
Note: See TracBrowser for help on using the repository browser.