source: TI12-security/trunk/ndg_xacml/ndg/xacml/core/context/pdp.py @ 7109

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

Incomplete - task 2: XACML-Security Integration

  • updating epydoc ready for release.
  • Property svn:keywords set to Id
Line 
1"""NDG XACML Policy Decision Point type definition
2
3NERC DataGrid
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    @ivar __policy: policy object for PDP to use to apply access control
24    decisions
25    @type policy: ndg.xacml.core.policy.Policy / None
26    """
27    __slots__ = ('__policy',)
28   
29    def __init__(self, policy=None):
30        """
31        @param policy: policy object for PDP to use to apply access control
32        decisions, may be omitted.
33        @type policy: ndg.xacml.core.policy.Policy / None
34        """
35        self.__policy = None
36        if policy is not None:
37            self.policy = policy
38       
39    @classmethod
40    def fromPolicySource(cls, source, readerFactory):
41        """Create a new PDP instance with a given policy
42        @param source: source for policy
43        @type source: type (dependent on the reader set, it could be for example
44        a file path string, file object, XML element instance)
45        @param readerFactory: reader factory returns the reader to use to read
46        this policy
47        @type readerFactory: ndg.xacml.parsers.AbstractReader derived type
48        """           
49        pdp = cls()
50        pdp.policy = Policy.fromSource(source, readerFactory)
51        return pdp
52   
53    @property
54    def policy(self):
55        """Get policy
56        @return: policy object for PDP to use to apply access control decisions
57        @rtype: ndg.xacml.core.policy.Policy
58        """
59        return self.__policy
60   
61    @policy.setter
62    def policy(self, value):
63        '''Set policy
64        @param value: policy object for PDP to use to apply access control
65        decisions
66        @type value: ndg.xacml.core.policy.Policy
67        '''
68        if not isinstance(value, Policy):
69            raise TypeError('Expecting %r derived type for "policy" input; got '
70                            '%r instead' % (Policy, type(value)))
71        self.__policy = value
72                                       
73    def evaluate(self, request):
74        """Make an access control decision for the given request based on the
75        single policy provided
76       
77        @param request: XACML request context
78        @type request: ndg.xacml.core.context.request.Request
79        @return: XACML response instance
80        @rtype: ndg.xacml.core.context.response.Response
81        """
82        response = self.policy.evaluate(request)
83       
84        return response
85
86
87
Note: See TracBrowser for help on using the repository browser.