Package ndg :: Package xacml :: Package core :: Package context :: Module request
[hide private]

Source Code for Module ndg.xacml.core.context.request

  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: request.py 8010 2012-01-30 16:24:06Z rwilkinson $" 
 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  from ndg.xacml.core.context.handlerinterface import CtxHandlerInterface 
 22  from ndg.xacml.utils.xpath_selector import XPathSelectorInterface 
23 24 25 -class Request(XacmlContextBase):
26 """XACML Request class 27 28 @cvar ELEMENT_LOCAL_NAME: XML local element name, derived classes should 29 set 30 @type ELEMENT_LOCAL_NAME: string 31 32 @ivar __subjects: list of subjects corresponding to this request 33 @type __subjects: ndg.xacml.utils.TypedList 34 @ivar __resources: list of resources corresponding to this request 35 @type __subjects: ndg.xacml.utils.TypedList 36 @ivar __action: action for this request 37 @type __action: None / ndg.xacml.core.context.action.Action 38 @ivar __environment: environment associated with this request 39 @type __environment: None / ndg.xacml.core.context.environment.Environment 40 41 @ivar ctxHandler: reference to context handler to enable the PDP to 42 query for additional attributes. The Context Handler itself queries a 43 Policy Information Point. This handler setting may be omitted. If so, 44 the PDP will rely entirely on the input request context for making 45 access control decisions 46 @type ctxHandler: ndg.xacml.core.context.handler.CtxHandlerInterface / 47 None 48 """ 49 __slots__ = ( 50 '__subjects', 51 '__resources', 52 '__action', 53 '__environment', 54 '__ctxHandler', 55 '__attributeSelector', 56 ) 57 ELEMENT_LOCAL_NAME = 'Request' 58
59 - def __init__(self):
60 super(Request, self).__init__() 61 62 self.__subjects = TypedList(Subject) 63 self.__resources = TypedList(Resource) 64 self.__action = None 65 self.__environment = None 66 67 self.__ctxHandler = None 68 self.__attributeSelector = None
69 70 @property
71 - def subjects(self):
72 """Get Request subjects 73 @return: list of subjects 74 @rtype: ndg.xacml.utils.TypedList 75 """ 76 return self.__subjects
77 78 @property
79 - def resources(self):
80 """Get Request resources 81 @return: list of resources 82 @rtype: ndg.xacml.utils.TypedList 83 """ 84 return self.__resources
85 86 @property
87 - def action(self):
88 """Get Request action 89 @return: action type 90 @rtype: None / ndg.xacml.core.context.action.Action 91 """ 92 return self.__action
93 94 @action.setter
95 - def action(self, value):
96 """Set Request action 97 @param value: action type 98 @type value: ndg.xacml.core.context.action.Action 99 """ 100 if not isinstance(value, Action): 101 raise TypeError('Expecting %r type for request "action" ' 102 'attribute; got %r' % (Action, type(value))) 103 104 self.__action = value
105 106 @property
107 - def environment(self):
108 """Get Request environment 109 @return: environment settings 110 @rtype: None / ndg.xacml.core.context.environment.Environment 111 """ 112 return self.__environment
113 114 @environment.setter
115 - def environment(self, value):
116 """Set Request environment 117 @param value: environment settings 118 @type value: ndg.xacml.core.context.environment.Environment 119 """ 120 if not isinstance(value, Environment): 121 raise TypeError('Expecting %r type for request "environment" ' 122 'attribute; got %r' % (Environment, type(value))) 123 124 self.__environment = value
125 126 @property
127 - def ctxHandler(self):
128 """Get Context handler used by evaluate method to query the PIP for 129 additional attribute values 130 @return: context handler 131 @rtype: None / ndg.xacml.core.context.handler.CtxHandlerInterface 132 derived type 133 """ 134 return self.__ctxHandler
135 136 @ctxHandler.setter
137 - def ctxHandler(self, value):
138 """Set Context handler used by evaluate method to query the PIP for 139 additional attribute values 140 @param value: context handler 141 @type value: ndg.xacml.core.context.handler.CtxHandlerInterface 142 derived type 143 """ 144 if not isinstance(value, CtxHandlerInterface): 145 raise TypeError('Expecting %r type for "ctxHandler" attribute; got ' 146 '%r' % (CtxHandlerInterface, type(value))) 147 148 self.__ctxHandler = value
149 150 @property
151 - def attributeSelector(self):
152 """Get attribute selector used to make XPath selections on request 153 @return: attribute selector 154 @rtype: None / ndg.xacml.utils.xpath_selector.XpathSelectorInterface 155 derived type 156 """ 157 return self.__attributeSelector
158 159 @attributeSelector.setter
160 - def attributeSelector(self, value):
161 """Set attribute selector used to make XPath selections on request 162 @param value: attribute selector 163 @type value: ndg.xacml.utils.xpath_selector.XpathSelectorInterface 164 derived type 165 """ 166 if not isinstance(value, XPathSelectorInterface): 167 raise TypeError('Expecting %r type for "attributeSelector" ' 168 'attribute; got %r' % 169 (XPathSelectorInterface, type(value))) 170 171 self.__attributeSelector = value
172
173 - def __getstate__(self):
174 '''Enable pickling 175 176 @return: object's attribute dictionary 177 @rtype: dict 178 ''' 179 _dict = super(Request, self).__getstate__() 180 for attrName in Request.__slots__: 181 # Ugly hack to allow for derived classes setting private member 182 # variables 183 if attrName.startswith('__'): 184 attrName = "_Request" + attrName 185 186 _dict[attrName] = getattr(self, attrName) 187 188 return _dict
189