source: TI12-security/trunk/NDGSecurity/python/ndg_security_common/ndg/security/common/authz/xacml/__init__.py @ 6730

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg-security/TI12-security/trunk/NDGSecurity/python/ndg_security_common/ndg/security/common/authz/xacml/__init__.py@6730
Revision 6730, 2.1 KB checked in by pjkersha, 11 years ago (diff)
  • Working Credential Wallet refactored for Python 2.6
  • Pruned out more old code: ZSI and Twisted SAOP/WSDL wrappers, Session Manager and WS-Security, Test 'Site B' Attribute Authority - for testing role mapping.
  • Started XACML package ElementTree based parser.
Line 
1class XACMLError(Exception):
2    """Base class for XACML package exception types"""
3   
4   
5class XMLParseError(XACMLError):
6    """XACML package XML Parsing error"""
7   
8   
9class PolicyComponent(object):
10    """Base class for Policy and Policy subelements"""
11    XACML_2_0_XMLNS = "urn:oasis:names:tc:xacml:2.0:policy:schema:os"
12
13    __slots__ = ('__xmlns', '__reader', '__writer')
14
15    ELEMENT_LOCAL_NAME = None
16   
17    def __init__(self):
18        self.__xmlns = PolicyComponent.XACML_2_0_XMLNS
19        self.__reader = None
20        self.__writer = None
21       
22    def _getXmlns(self):
23        return self.__xmlns
24
25    def _setXmlns(self, value):
26        if not isinstance(value, basestring):
27            raise TypeError('Expecting string type for "xmlns" '
28                            'attribute; got %r' % type(value))
29        self.__xmlns = value
30
31    xmlns = property(_getXmlns, _setXmlns, 
32                     doc="XML Namespace for policy the document")
33   
34    @property
35    def isValidXmlns(self):
36        return self.xmlns in PolicyComponent.XMLNS
37
38    def read(self, obj):
39        """Read using callable assinged to reader property"""
40        if self.__reader is None:
41            raise AttributeError('No reader set for %r' % self.__class__)
42       
43        self.__reader(self, obj)
44
45    @classmethod
46    def Read(cls, obj):
47        """Construct a new Policy""" 
48        xacmlObj = cls()
49        xacmlObj.read(obj)
50        return xacmlObj
51   
52    def write(self, obj):
53        """Read using callable assinged to reader property"""
54        if self.__writer is None:
55            raise AttributeError('No writer set for %r' % self.__class__)
56       
57        self.__writer(self, obj)
58       
59           
60class RequestPropertyBase(PolicyComponent):
61    """Base type for Subject, Resource, Action and Environment types"""
62    MATCH_TYPE = None
63   
64    __slots__ = ('__matches', )
65   
66    def __init__(self):
67        # Derived types can specify the type for matches via the MATCH_TYPE
68        # class variable
69        self.__matches = TypedList(self.__class__.MATCH_TYPE)
70       
71    @property
72    def matches(self):
73        return self.__matches
Note: See TracBrowser for help on using the repository browser.