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

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

Added Context Handler and Attribute classes.

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:
42    """Context Handler Abstract Base class"""
43    __metaclass__ = ABCMeta
44   
45    @classmethod
46    def __subclasshook__(cls, C):
47        """Derived class must implement __call__"""
48        if PEPInterface.__subclasshook__(C) == NotImplemented:
49            return NotImplemented
50       
51        if cls is AbstractContextHandler:
52            if any("__call__" in B.__dict__ for B in C.__mro__):
53                return True
54           
55        return NotImplemented
56
57
58
59# Set up new class as an abstract base itself             
60PEPInterface.register(AbstractContextHandler)
Note: See TracBrowser for help on using the repository browser.