1 | """NDG XACML AttributeSelector type |
---|
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$" |
---|
12 | import logging |
---|
13 | log = logging.getLogger(__name__) |
---|
14 | |
---|
15 | from ndg.xacml.core.expression import Expression |
---|
16 | |
---|
17 | |
---|
18 | class AttributeSelector(Expression): |
---|
19 | '''XACML Attribute Selector type |
---|
20 | @cvar ELEMENT_LOCAL_NAME: XML local name for this element |
---|
21 | @type ELEMENT_LOCAL_NAME: string |
---|
22 | @cvar REQUEST_CONTEXT_PATH_ATTRIB_NAME: request context XML attribute name |
---|
23 | @type REQUEST_CONTEXT_PATH_ATTRIB_NAME: string |
---|
24 | @cvar MUST_BE_PRESENT_ATTRIB_NAME: must be present XML attribute name |
---|
25 | @type MUST_BE_PRESENT_ATTRIB_NAME: string |
---|
26 | |
---|
27 | ''' |
---|
28 | ELEMENT_LOCAL_NAME = 'AttributeSelector' |
---|
29 | MUST_BE_PRESENT_ATTRIB_NAME = 'MustBePresent' |
---|
30 | REQUEST_CONTEXT_PATH_ATTRIB_NAME = 'RequestContextPath' |
---|
31 | |
---|
32 | __slots__ = ('__mustBePresent', '__requestContextPath') |
---|
33 | |
---|
34 | def __init__(self): |
---|
35 | '''XACML Attribute Selector type |
---|
36 | ''' |
---|
37 | super(AttributeSelector, self).__init__() |
---|
38 | self.__mustBePresent = None |
---|
39 | self.__requestContextPath = None |
---|
40 | |
---|
41 | @property |
---|
42 | def requestContextPath(self): |
---|
43 | """Get request context path |
---|
44 | @return: request context path |
---|
45 | @rtype: basestring |
---|
46 | """ |
---|
47 | return self.__requestContextPath |
---|
48 | |
---|
49 | @requestContextPath.setter |
---|
50 | def requestContextPath(self, value): |
---|
51 | """Set request context path |
---|
52 | @param value: request context path |
---|
53 | @type value: basestring |
---|
54 | @raise TypeError: incorrect input type |
---|
55 | """ |
---|
56 | if not isinstance(value, basestring): |
---|
57 | raise TypeError('Expecting %r type for "requestContextPath" ' |
---|
58 | 'attribute; got %r' % (basestring, type(value))) |
---|
59 | |
---|
60 | self.__requestContextPath = value |
---|
61 | |
---|
62 | @property |
---|
63 | def mustBePresent(self): |
---|
64 | """Get Must Be Present flag |
---|
65 | @return: must be present flag |
---|
66 | @rtype: bool |
---|
67 | """ |
---|
68 | return self.__mustBePresent |
---|
69 | |
---|
70 | @mustBePresent.setter |
---|
71 | def mustBePresent(self, value): |
---|
72 | """Set Must Be Present flag |
---|
73 | @param value: must be present flag |
---|
74 | @type value: bool |
---|
75 | @raise TypeError: incorrect input type |
---|
76 | """ |
---|
77 | if not isinstance(value, bool): |
---|
78 | raise TypeError('Expecting %r type for "mustBePresent" ' |
---|
79 | 'attribute; got %r' % (bool, type(value))) |
---|
80 | |
---|
81 | self.__mustBePresent = value |
---|
82 | |
---|
83 | def evaluate(self, context): |
---|
84 | """Placeholder to override abstract method and enable this class to be |
---|
85 | instantiated. However, AttributeSelectors are not fully implemented so |
---|
86 | this method raises a not implemented error. |
---|
87 | """ |
---|
88 | raise NotImplementedError('PDP evaluation for AttributeSelectors is ' |
---|
89 | 'not currently implemented') |
---|