1 """NDG XACML context package defines classes for types in the access control
2 context schema
3
4 NERC DataGrid
5 """
6 __author__ = "P J Kershaw"
7 __date__ = "24/03/10"
8 __copyright__ = "(C) 2010 Science and Technology Facilities Council"
9 __contact__ = "Philip.Kershaw@stfc.ac.uk"
10 __license__ = "BSD - see LICENSE file in top-level directory"
11 __contact__ = "Philip.Kershaw@stfc.ac.uk"
12 __revision__ = "$Id: __init__.py 8010 2012-01-30 16:24:06Z rwilkinson $"
13 from ndg.xacml.utils import TypedList
14 from ndg.xacml.core import XacmlCoreBase
15 from ndg.xacml.core.attribute import Attribute
16
17
18 -class XacmlContextBase(XacmlCoreBase):
19 """Base class for XACML Request and Response types
20
21 @cvar ELEMENT_LOCAL_NAME: XML local element name, derived classes should
22 set
23 @type ELEMENT_LOCAL_NAME: None"""
24 XACML_2_0_CONTEXT_NS = XacmlCoreBase.XACML_2_0_NS_PREFIX + ':context:schema:os'
25 XACML_2_0_CONTEXT_NS_PREFIX = 'xacml-context'
26
27 ELEMENT_LOCAL_NAME = None
28 __slots__ = ()
29
31 """ELEMENT_LOCAL_NAME check makes this class virtual - derived classes
32 must override this method and set ELEMENT_LOCAL_NAME to the appropriate
33 string
34 """
35 super(XacmlContextBase, self).__init__()
36 if self.__class__.ELEMENT_LOCAL_NAME is None:
37 raise NotImplementedError('Set "ELEMENT_LOCAL_NAME" in a derived '
38 'type')
39
40 - def __getstate__(self):
41 '''Enable pickling
42
43 @return: object's attribute dictionary
44 @rtype: dict
45 '''
46 _dict = super(XacmlContextBase, self).__getstate__()
47 for attrName in XacmlContextBase.__slots__:
48
49
50 if attrName.startswith('__'):
51 attrName = "_XacmlContextBase" + attrName
52
53 _dict[attrName] = getattr(self, attrName)
54
55 return _dict
56
57 - def __setstate__(self, attrDict):
58 '''Explicit implementation needed with __slots__'''
59 for attr, val in attrDict.items():
60 setattr(self, attr, val)
61
63 """Base class for XACML Context Subject, Resource, Action and Environment
64 types
65
66 @ivar __attributes: XACML Context subject attributes
67 @type __attributes: ndg.xacml.utils.TypedList
68 """
69 __slots__ = ('__attributes', )
70
75
76 @property
78 """
79 @return: XACML Context subject attributes
80 @rtype: ndg.xacml.utils.TypedList
81 """
82 return self.__attributes
83
85 '''Enable pickling
86
87 @return: object's attribute dictionary
88 @rtype: dict
89 '''
90 _dict = super(RequestChildBase, self).__getstate__()
91 for attrName in RequestChildBase.__slots__:
92
93
94 if attrName.startswith('__'):
95 attrName = "_RequestChildBase" + attrName
96 _dict[attrName] = getattr(self, attrName)
97 return _dict
98