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

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

Moved PDPInterface into separate module. Extensive additions to unit tests. PDP class now in pdp module in context package.

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