1 | """NDG XACML module for Request type |
---|
2 | |
---|
3 | NERC DataGrid |
---|
4 | """ |
---|
5 | __author__ = "P J Kershaw" |
---|
6 | __date__ = "23/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.utils import TypedList |
---|
16 | from ndg.xacml.core.context import XacmlContextBase |
---|
17 | from ndg.xacml.core.context.subject import Subject |
---|
18 | from ndg.xacml.core.context.resource import Resource |
---|
19 | from ndg.xacml.core.context.action import Action |
---|
20 | from ndg.xacml.core.context.environment import Environment |
---|
21 | |
---|
22 | |
---|
23 | class Request(XacmlContextBase): |
---|
24 | """XACML Request class |
---|
25 | |
---|
26 | @cvar ELEMENT_LOCAL_NAME: XML local element name, derived classes should |
---|
27 | set |
---|
28 | @type ELEMENT_LOCAL_NAME: string |
---|
29 | |
---|
30 | @ivar __subjects: list of subjects corresponding to this request |
---|
31 | @type __subjects: ndg.xacml.utils.TypedList |
---|
32 | @ivar __resources: list of resources corresponding to this request |
---|
33 | @type __subjects: ndg.xacml.utils.TypedList |
---|
34 | @ivar __action: action for this request |
---|
35 | @type __action: None / ndg.xacml.core.context.action.Action |
---|
36 | @ivar __environment: environment associated with this request |
---|
37 | @type __environment: None / ndg.xacml.core.context.environment.Environment |
---|
38 | |
---|
39 | @ivar ctxHandler: reference to context handler to enable the PDP to |
---|
40 | query for additional attributes. The Context Handler itself queries a |
---|
41 | Policy Information Point. This handler setting may be omitted. If so, |
---|
42 | the PDP will rely entirely on the input request context for making |
---|
43 | access control decisions |
---|
44 | @type ctxHandler: ndg.xacml.core.context.handler.CtxHandlerInterface / |
---|
45 | None |
---|
46 | """ |
---|
47 | __slots__ = ( |
---|
48 | '__subjects', |
---|
49 | '__resources', |
---|
50 | '__action', |
---|
51 | '__environment', |
---|
52 | '__ctxHandler', |
---|
53 | ) |
---|
54 | ELEMENT_LOCAL_NAME = 'Request' |
---|
55 | |
---|
56 | def __init__(self): |
---|
57 | super(Request, self).__init__() |
---|
58 | |
---|
59 | self.__subjects = TypedList(Subject) |
---|
60 | self.__resources = TypedList(Resource) |
---|
61 | self.__action = None |
---|
62 | self.__environment = None |
---|
63 | |
---|
64 | self.__ctxHandler = None |
---|
65 | |
---|
66 | @property |
---|
67 | def subjects(self): |
---|
68 | """Get Request subjects |
---|
69 | @return: list of subjects |
---|
70 | @rtype: ndg.xacml.utils.TypedList |
---|
71 | """ |
---|
72 | return self.__subjects |
---|
73 | |
---|
74 | @property |
---|
75 | def resources(self): |
---|
76 | """Get Request resources |
---|
77 | @return: list of resources |
---|
78 | @rtype: ndg.xacml.utils.TypedList |
---|
79 | """ |
---|
80 | return self.__resources |
---|
81 | |
---|
82 | @property |
---|
83 | def action(self): |
---|
84 | """Get Request action |
---|
85 | @return: action type |
---|
86 | @rtype: None / ndg.xacml.core.context.action.Action |
---|
87 | """ |
---|
88 | return self.__action |
---|
89 | |
---|
90 | @action.setter |
---|
91 | def action(self, value): |
---|
92 | """Set Request action |
---|
93 | @param value: action type |
---|
94 | @type value: ndg.xacml.core.context.action.Action |
---|
95 | """ |
---|
96 | if not isinstance(value, Action): |
---|
97 | raise TypeError('Expecting %r type for request "action" ' |
---|
98 | 'attribute; got %r' % (Action, type(value))) |
---|
99 | |
---|
100 | self.__action = value |
---|
101 | |
---|
102 | @property |
---|
103 | def environment(self): |
---|
104 | """Get Request environment |
---|
105 | @return: environment settings |
---|
106 | @rtype: None / ndg.xacml.core.context.environment.Environment |
---|
107 | """ |
---|
108 | return self.__environment |
---|
109 | |
---|
110 | @environment.setter |
---|
111 | def environment(self, value): |
---|
112 | """Set Request environment |
---|
113 | @param value: environment settings |
---|
114 | @type value: ndg.xacml.core.context.environment.Environment |
---|
115 | """ |
---|
116 | if not isinstance(value, Environment): |
---|
117 | raise TypeError('Expecting %r type for request "environment" ' |
---|
118 | 'attribute; got %r' % (Environment, type(value))) |
---|
119 | |
---|
120 | self.__environment = value |
---|
121 | |
---|
122 | @property |
---|
123 | def ctxHandler(self): |
---|
124 | """Get Context handler used by evaluate method to query the PIP for |
---|
125 | additional attribute values |
---|
126 | @return: context handler |
---|
127 | @rtype: None / ndg.xacml.core.context.handler.CtxHandlerInterface |
---|
128 | derived type |
---|
129 | """ |
---|
130 | return self.__ctxHandler |
---|
131 | |
---|
132 | @ctxHandler.setter |
---|
133 | def ctxHandler(self, value): |
---|
134 | """Set Context handler used by evaluate method to query the PIP for |
---|
135 | additional attribute values |
---|
136 | @param value: context handler |
---|
137 | @type value: ndg.xacml.core.context.handler.CtxHandlerInterface |
---|
138 | derived type |
---|
139 | """ |
---|
140 | if not isinstance(value, CtxHandlerInterface): |
---|
141 | raise TypeError('Expecting %r type for "ctxHandler" attribute; got ' |
---|
142 | '%r' % (CtxHandlerInterface, type(value))) |
---|
143 | |
---|
144 | self.__ctxHandler = value |
---|