source: TI12-security/trunk/ndg_xacml/ndg/xacml/core/context/handler.py @ 7299

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

Incomplete - task 2: XACML-Security Integration

  • Working on PIP to make Attribute Service query
  • Property svn:keywords set to Id
Line 
1"""NDG Security Context handler definition
2
3NERC DataGrid
4"""
5__author__ = "P J Kershaw"
6__date__ = "24/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$"
12from abc import ABCMeta, abstractmethod
13
14from ndg.xacml.core.context.pdpinterface import PDPInterface
15from ndg.xacml.core.context.pipinterface import PIPInterface
16
17
18class PEPInterface(object):
19    """Policy Enforcement Point Interface"""
20    __metaclass__ = ABCMeta
21    __slots__ = ()
22           
23    @abstractmethod
24    def handlePEPRequest(self, pepRequest):
25        """Handle request from Policy Enforcement Point
26       
27        @param pepRequest: request from PEP, derived class determines its type
28        e.g. SAML AuthzDecisionQuery
29        @type pepRequest: type
30        @return: PEP response - derived class determines type
31        @rtype: None
32        """
33        raise NotImplementedError()
34       
35       
36class CtxHandlerInterface(PEPInterface):
37    """Context Handler interface."""
38    __metaclass__ = ABCMeta
39    __slots__ = ()
40   
41    def pipQuery(self, request, designator):
42        """Query a Policy Information Point to retrieve the attribute values
43        corresponding to the specified input designator.  Optionally, update the
44        requestCtx.  This could be a subject, environment or resource.  Matching
45        attributes values are returned
46       
47        @param request: request context
48        @type request: ndg.xacml.core.context.request.Request
49        @param designator: designator requiring additional subject attribute
50        information
51        @type designator: ndg.xacml.core.expression.Expression derived type
52        @return: list of attribute values for subject corresponding to given
53        policy designator
54        @rtype: list
55        """
56        return []
57   
58
59class CtxHandlerBase(CtxHandlerInterface):
60    """Base class for Context handlers - extends Context handler interface to
61    include Policy Decision Point and Policy Information Point references
62    """
63   
64    __slots__ = (
65        '__pip',
66        '__pdp', 
67    )
68     
69    def __init__(self):
70        self.__pip = None
71        self.__pdp = None
72       
73    def _getPip(self):
74        return self.__pip
75
76    def _setPip(self, value):
77        if not isinstance(value, PIPInterface):
78            raise TypeError('Expecting %r type for "pip" attribute; got %r '
79                            'instead' % 
80                            (PDPInterface, value))
81           
82        self.__pip = value
83
84    pip = property(_getPip, _setPip, None, "Policy Information Point")
85         
86    def _getPdp(self):
87        return self.__pdp
88
89    def _setPdp(self, value):
90        if not isinstance(value, PDPInterface):
91            raise TypeError('Expecting %r type for "pdp" attribute; got %r '
92                            'instead' % 
93                            (PDPInterface, value))
94           
95        self.__pdp = value
96
97    pdp = property(_getPdp, _setPdp, None, "Policy Decision Point")
98       
Note: See TracBrowser for help on using the repository browser.