1 """NDG Security Obligation type definition
2
3 NERC DataGrid
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: obligation.py 7955 2011-12-21 18:29:45Z rwilkinson $"
12 from ndg.xacml.utils import TypedList
13 from ndg.xacml.core import XacmlCoreBase
14 from ndg.xacml.core.attributevalue import AttributeValue
18 """XACML AttributeAssignment type"""
19
22 """Define effect type for Obligation
23
24 @cvar PERMIT_STR: permit decision string
25 @type PERMIT_STR: string
26
27 @cvar DENY_STR: deny decision string
28 @type DENY_STR: string
29
30 @cvar TYPES: list of valid effect strings
31 @type TYPES: tuple
32
33 @ivar __value: obligation effect
34 @type value: None / basestring
35 """
36
37
38 PERMIT_STR = "Permit"
39
40
41 DENY_STR = "Deny"
42
43 TYPES = (PERMIT_STR, DENY_STR)
44
45 __slots__ = ('__value',)
46
48 """Initialise attributes giving an effect type
49 @param effectType:
50 @type effectType:
51 """
52 self.__value = None
53 self.value = effectType
54
56 '''Enable pickling
57
58 @return: instance attributes dictionary
59 @rtype: dict
60 '''
61 _dict = {}
62 for attrName in Effect.__slots__:
63
64
65 if attrName.startswith('__'):
66 attrName = "_Effect" + attrName
67
68 _dict[attrName] = getattr(self, attrName)
69
70 return _dict
71
73 '''Enable pickling
74 @param attrDict: instance attributes dictionary
75 @type attrDict: dict
76 '''
77 for attrName, val in attrDict.items():
78 setattr(self, attrName, val)
79
81 """Set effect
82
83 @param value: effect
84 @type value: ndg.xacml.core.obligation.Effect or basestring
85 @raise TypeError: incorrect type for input
86 @raise AttributeError: effect value not recognised
87 """
88 if isinstance(value, Effect):
89
90 value = str(value)
91
92 elif not isinstance(value, basestring):
93 raise TypeError('Expecting string or Effect instance for '
94 '"value" attribute; got %r instead' % type(value))
95
96 if value not in self.__class__.TYPES:
97 raise AttributeError('Permissable effect types are %r; got '
98 '%r instead' % (Effect.TYPES, value))
99 self.__value = value
100
102 """Get effect
103
104 @return: effect value
105 @rtype: ndg.xacml.core.obligation.Effect
106 """
107 return self.__value
108
109 value = property(fget=_getValue, fset=_setValue, doc="Effect value")
110
112 """
113 @return: effect as a string
114 @rtype: basestring
115 """
116 return self.__value
117
119 """
120 @param effect: ndg.xacml.core.obligation.Effect or basestring
121 @raise TypeError: incorrect type for input
122 @raise AttributeError: effect value not recognised
123 """
124 if isinstance(effect, Effect):
125
126 value = effect.value
127
128 elif isinstance(effect, basestring):
129 value = effect
130
131 else:
132 raise TypeError('Expecting string or Effect instance for '
133 'input effect value; got %r instead' % type(value))
134
135 if value not in self.__class__.TYPES:
136 raise AttributeError('Permissable effect types are %r; got '
137 '%r instead' % (Effect.TYPES, value))
138
139 return self.__value == value
140
143 """XACML Obligation type
144
145 @cvar ELEMENT_LOCAL_NAME: XML element local name
146 @type ELEMENT_LOCAL_NAME: string
147 @cvar ATTRIBUTE_ASSIGNMENTS_ELEMENT_LOCAL_NAME: attribute assignments XML
148 attribute name
149 @type ATTRIBUTE_ASSIGNMENTS_ELEMENT_LOCAL_NAME: string
150 @cvar OBLIGATION_ID_ATTRIB_NAME: obligation ID XML attribute name
151 @type OBLIGATION_ID_ATTRIB_NAME: string
152
153 @ivar __attributeAssignments: list of attribute assignments
154 @type __attributeAssignments: ndg.xacml.utils.TypedList
155 @ivar __obligationId: obligation id
156 @type __obligationId: NoneType / basestring
157 @ivar __fulfillOn: fulfil on condition
158 @type __fulfillOn: NoneType / basestring
159 """
160 ELEMENT_LOCAL_NAME = 'Obligation'
161 ATTRIBUTE_ASSIGNMENTS_ELEMENT_LOCAL_NAME = 'AttributeAssignment'
162 FULFILLON_ELEMENT_LOCAL_NAME = 'FulfillOn'
163 OBLIGATION_ID_ATTRIB_NAME = 'ObligationId'
164
165 __slots__ = ('__attributeAssignments', '__obligationId', '__fulfillOn')
166
172
173 @property
175 """Obligation attribute assignments
176 @return: attribute assignments
177 @rtype: ndg.xacml.utils.TypedList
178 """
179 return self.__attributeAssignments
180
181 @property
183 """obligation Id
184 @return: obligation id
185 @rtype: NoneType / basestring
186 """
187 return self.__obligationId
188
189 @obligationId.setter
191 """obligation Id
192
193 @param value: obligation id
194 @type value: NoneType / basestring
195 @raise TypeError: incorrect input type
196 """
197 if not isinstance(value, basestring):
198 raise TypeError('Expecting %r type for "obligationId" attribute; '
199 'got %r' % (basestring, type(value)))
200
201 self.__obligationId = value
202
203 @property
205 """Fulfill obligation on the given effect Permit/Deny
206
207 @return: fulfil condition
208 @rtype: NoneType / basestring
209 """
210 return self.__fulfillOn
211
212 @fulfillOn.setter
214 """Fulfill obligation on the given effect Permit/Deny
215 @param value: fulfil condition
216 @type value: NoneType / basestring
217 @raise TypeError: incorrect type for input
218 """
219 if not isinstance(value, basestring):
220 raise TypeError('Expecting %r type for "fulfillOn" attribute; got '
221 '%r' % (Effect, type(value)))
222
223 self.__fulfillOn = value
224