1 """NDG XACML core package
2
3 NERC DataGrid
4 """
5 __author__ = "P J Kershaw"
6 __date__ = "16/03/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: __init__.py 8010 2012-01-30 16:24:06Z rwilkinson $"
12 from ndg.xacml.utils import TypedList
16 """Base class for all XACML types
17
18 @cvar XACML_1_0_NS_PREFIX: XACML version 1.0 namespace prefix
19 @type XACML_1_0_NS_PREFIX: string
20 @cvar XACML_2_0_NS_PREFIX: XACML version 2.0 namespace prefix
21 @type XACML_2_0_NS_PREFIX: string
22 @cvar XMLNS: list of valid XACML namespaces
23 @type XMLNS: tuple
24 @cvar ELEMENT_LOCAL_NAME: XML element local name for the given type
25 @type ELEMENT_LOCAL_NAME: NoneType but implement as string in derived
26 classes
27
28 @ivar __xmlns: XML namespace for the XACML type
29 @type __xmlns: NoneType / basestring
30
31 @ivar __elem: XML element
32 @type __elem: NoneType / dependent on Python XML parser used
33 """
34 XACML_1_0_NS_PREFIX = "urn:oasis:names:tc:xacml:1.0"
35 XACML_2_0_NS_PREFIX = "urn:oasis:names:tc:xacml:2.0"
36
37 XMLNS = (XACML_1_0_NS_PREFIX, XACML_2_0_NS_PREFIX)
38
39 __slots__ = ('__xmlns', '__reader', '__writer', '__elem')
40
41 ELEMENT_LOCAL_NAME = None
42
44 """Element local name check makes this a virtual method
45
46 @raise NotImplementedError: derived classes must set
47 ELEMENT_LOCAL_NAME to a string
48 """
49 self.__xmlns = None
50 self.__elem = None
51 self.__reader = None
52 self.__writer = None
53
54 if not isinstance(self.__class__.ELEMENT_LOCAL_NAME, basestring):
55 raise NotImplementedError('"ELEMENT_LOCAL_NAME" must be defined in '
56 'a derived class')
57
59 """Get XML Namespace for this XACML type
60 @return: the XML namespace set
61 @rtype: basestring/NoneType
62 """
63 return self.__xmlns
64
66 """Set XML Namespace for this XACML type
67 @param value: the XML namespace to set
68 @type value: basestring/NoneType
69 """
70 if not isinstance(value, basestring):
71 raise TypeError('Expecting string type for "xmlns" '
72 'attribute; got %r' % type(value))
73 self.__xmlns = value
74
75 xmlns = property(_getXmlns, _setXmlns,
76 doc="XML Namespace for policy the document")
77
78 @property
80 """Check XML namespace fits with the known XACML namespaces
81 @return: True if valid, False otherwise
82 @rtype: bool
83 """
84 return self.xmlns in XacmlCoreBase.XMLNS
85
86 @property
88 """XML Node for as represented by parser/writer specified with the
89 reader/writer attributes. Readers of context elements should set this
90 element if a policy uses AttributeSelectors to do XPath queries into
91 the request context
92 """
93 return self.__elem
94
95 @elem.setter
96 - def elem(self, value):
97 """"XML Node for as represented by parser/writer specified with the
98 reader/writer attributes
99
100 @param value: XML node instance
101 @type value: type (governed by reader/writer set for this XACML object)
102 """
103 self.__elem = value
104
106 '''Enable pickling
107
108 @return: object's attribute dictionary
109 @rtype: dict
110 '''
111 _dict = {}
112 for attrName in XacmlCoreBase.__slots__:
113
114
115 if attrName.startswith('__'):
116 attrName = "_XacmlCoreBase" + attrName
117
118 _dict[attrName] = getattr(self, attrName)
119
120 return _dict
121
124 """Base class for policy types
125
126 @cvar XACML_2_0_POLICY_NS: XACML 2.0 policy XML namespace
127 @type XACML_2_0_POLICY_NS: string
128 """
129 XACML_2_0_POLICY_NS = (XacmlCoreBase.XACML_2_0_NS_PREFIX +
130 ":policy:schema:os")
131 __slots__ = ()
132
139
142 """Abstract Base class for XACML Policy Subject, Resource, Action and
143 Environment types: e.g. ndg.xacml.core.subject.Subject
144
145 @cvar MATCH_TYPE: Set the type for match attributes in the derived class
146 implementation e.g. ResourceMatch, SubjectMatch etc.
147 @type MATCH_TYPE: NoneType - derived class must implement
148
149 @ivar __matches: list of matches for this target
150 @type __matches: ndg.xacml.core.utils.TypedList
151 """
152 MATCH_TYPE = None
153
154 __slots__ = ('__matches', )
155
165
166 @property
168 """Get matches list for this target
169 """
170 return self.__matches
171
172
173 XACML_1_0_PREFIX = "urn:oasis:names:tc:xacml:1.0:"
176 """XACML Identifiers"""
190
201
207
212
218