source: TI12-security/trunk/NDG_XACML/ndg/xacml/core/context/handler.py @ 6771

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

Added request subject, resource, action and environment types

Line 
1"""NDG Security Context handler definition
2
3NERC DataGrid Project
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
14
15class PEPInterface:
16    """Policy Enforcement Point Interface"""
17    __metaclass__ = ABCMeta
18   
19    @classmethod
20    def __subclasshook__(cls, C):
21        """Derived class must implement __call__"""
22        if cls is PEPInterface:
23            if any("handlePEPRequest" in B.__dict__ for B in C.__mro__):
24                return True
25           
26        return NotImplemented
27       
28    @abstractmethod
29    def handlePEPRequest(self, pepRequest):
30        """Handle request from Policy Enforcement Point
31       
32        @param pepRequest: request from PEP, derived class determines its type
33        e.g. SAML AuthzDecisionQuery
34        @type pepRequest: type
35        @return: PEP response - derived class determines type
36        @rtype: None
37        """
38        raise NotImplementedError()
39       
40       
41class AbstractContextHandler(object):
42    """Context Handler Abstract Base class"""
43    __metaclass__ = ABCMeta
44    __slots__ = ('__pdp',)
45   
46    def __init__(self):
47        self.__pdp = None
48       
49    @classmethod
50    def __subclasshook__(cls, C):
51        """Derived class must implement __call__"""
52        if PEPInterface.__subclasshook__(C) == NotImplemented:
53            return NotImplemented
54       
55        if cls is AbstractContextHandler:
56            if any("__call__" in B.__dict__ for B in C.__mro__):
57                return True
58           
59        return NotImplemented
60   
61    def _getPDP(self):
62        return self.__pdp
63   
64    def _setPDP(self, value):
65        if not isinstance(value, PDPInterface):
66            raise TypeError('Expecting %r derived type for "pdp" attribute; '
67                            'got %r' % (PDPInterface, type(pdp))
68       
69        self.__pdp = value
70       
71    pdp = property(_getPDP, _setPDP, doc="Interface to PDP")
Note: See TracBrowser for help on using the repository browser.