Changeset 6774 for TI12-security/trunk
- Timestamp:
- 25/03/10 15:22:31 (10 years ago)
- Location:
- TI12-security/trunk/NDG_XACML/ndg/xacml
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
TI12-security/trunk/NDG_XACML/ndg/xacml/core/__init__.py
r6770 r6774 17 17 XACML_2_0_XMLNS = "urn:oasis:names:tc:xacml:2.0:policy:schema:os" 18 18 19 __slots__ = ('__xmlns', '__reader', '__writer' )19 __slots__ = ('__xmlns', '__reader', '__writer', '__elem') 20 20 21 21 ELEMENT_LOCAL_NAME = None … … 25 25 self.__reader = None 26 26 self.__writer = None 27 self.__elem = None 27 28 28 29 if not isinstance(self.__class__.ELEMENT_LOCAL_NAME, basestring): … … 67 68 self.__writer(self, obj) 68 69 70 @property 71 def elem(self): 72 """XML Node for as represented by parser/writer specified with the 73 reader/writer attributes. Readers of context elements should set this 74 element if a policy uses AttributeSelectors to do XPath queries into 75 the request context 76 """ 77 return self.__elem 78 79 @elem.setter 80 def elem(self, value): 81 """"XML Node for as represented by parser/writer specified with the 82 reader/writer attributes 83 84 @param value: XML node instance 85 @type value: type (governed by reader/writer set for this XACML object) 86 """ 87 self.__elem = value 88 69 89 70 90 class TargetChildBase(XacmlCoreBase): -
TI12-security/trunk/NDG_XACML/ndg/xacml/core/match.py
r6770 r6774 44 44 @attributeDesignator.setter 45 45 def attributeDesignator(self, value): 46 """Set match attribute designator. Match may have an 47 attributeDesignator or an attributeSelector setting a designator DELETES 48 any attributeSelector previously set 49 """ 46 50 if not isinstance(value, AttributeDesignator): 47 51 raise TypeError('Expecting %r type for "attributeDesignator" ' … … 50 54 51 55 self.__attributeDesignator = value 56 self.__attributeSelector = None 52 57 53 58 @property … … 57 62 @attributeSelector.setter 58 63 def attributeSelector(self, value): 64 """Set match attribute selector. Match may have an 65 attributeDesignator or an attributeSelector setting a selector DELETES 66 any attributeDesignator previously set 67 """ 59 68 if not isinstance(value, AttributeSelector): 60 69 raise TypeError('Expecting %r type for "matchId" ' … … 63 72 64 73 self.__attributeSelector = value 74 self.__attributeDesignator = None 65 75 66 76 def _getMatchId(self): -
TI12-security/trunk/NDG_XACML/ndg/xacml/parsers/etree/applyreader.py
r6766 r6774 34 34 ''' 35 35 TYPE = Apply 36 37 # These two are not currently implemented. When an implementation is made 38 # the ELEMENT_LOCAL_NAME may be referenced from the native class rather than 39 # a class variable here 40 FUNCTION_ELEMENT_LOCAL_NAME = 'Function' 41 VARIABLE_REFERENCE_ELEMENT_LOCAL_NAME = 'VariableReference' 36 42 37 43 def __call__(self, obj): … … 93 99 applyObj.expressions.append( 94 100 EnvironmentAttributeDesignatorReader.parse(subElem)) 95 101 96 102 elif localName == AttributeSelector.ELEMENT_LOCAL_NAME: 97 103 AttributeSelectorReader = ReaderFactory.getReader( 98 104 AttributeSelector) 99 105 applyObj.expressions.append( 100 AttributeSelectorReader.parse(subElem)) 106 AttributeSelectorReader.parse(subElem)) 107 108 elif localName == Condition.ELEMENT_LOCAL_NAME: 109 ConditionReader = ReaderFactory.getReader(Condition) 110 applyObj.expressions.append(ConditionReader.parse(subElem)) 111 112 elif localName == self.__class__.FUNCTION_ELEMENT_LOCAL_NAME: 113 raise NotImplementedError('%r Apply sub-element not ' 114 'implemented', localName) 115 116 elif (localName == 117 self.__class__.VARIABLE_REFERENCE_ELEMENT_LOCAL_NAME): 118 raise NotImplementedError('%r Apply sub-element not ' 119 'implemented', localName) 101 120 else: 102 raise NotImplementedError('%r Apply sub-element not '103 'recognised',localName)121 raise XMLParseError('%r Apply sub-element not recognised', 122 localName) 104 123 105 124 return applyObj -
TI12-security/trunk/NDG_XACML/ndg/xacml/test/test_xacml.py
r6771 r6774 276 276 277 277 def evaluate(self, request): 278 """Make an access control decision for the given request based on the 279 policy set 280 281 @param request: XACML request context 282 @type request: ndg.xacml.core.context.request.Request 283 @return: XACML response instance 284 @rtype: ndg.xacml.core.context.response.Response 285 """ 278 286 response = Response 279 287 result = Result() 280 288 response.results.append(result) 281 result.decision = Decision.INDETERMINATE 282 283 # Check policy target for match 284 if not self.matchTarget(self.policy.target, request): 285 result.decision = Decision.NOT_APPLICABLE 286 return response 287 288 # Check rules 289 for rule in self.policy.rules: 290 if not self.matchTarget(rule.target, request): 291 continue 289 result.decision = Decision.NOT_APPLICABLE 290 291 # Exception block around all rule processing in order to set 292 # INDETERMINATE response from any exceptions raised 293 try: 294 # Check policy target for match 295 log.debug('Checking policy target for match...') 296 297 if not self.matchTarget(self.policy.target, request): 298 log.debug('No match for policy target setting Decision=%r', 299 Decision.NOT_APPLICABLE_STR) 300 301 result.decision = Decision.NOT_APPLICABLE 302 return response 303 304 # Check rules 305 for rule in self.policy.rules: 306 log.debug('Checking policy rule %r for match...', rule.id) 307 if not self.matchTarget(rule.target, request): 308 log.debug('No match to request context for target in rule ' 309 '%r', rule.id) 310 continue 311 except: 312 log.error('Exception raised evaluating request context, returning ' 313 'Decision=%r:%s', 314 Decision.INDETERMINATE_STR, 315 traceback.format_exc()) 316 result.decision = Decision.INDETERMINATE 292 317 293 318 return response 319 294 320 295 321 def matchTarget(self, target, request): 296 322 if target is None: 323 log.debug('No target set so no match with request context') 297 324 return False 298 325 299 for targetSubject in target.subjects: 300 for requestSubject in request.subjects: 301 if subject. 326 # From section 5.5 of the XACML 2.0 Core Spec: 327 # 328 # For the parent of the <Target> element to be applicable to the 329 # decision request, there MUST be at least one positive match between 330 # each section of the <Target> element and the corresponding section of 331 # the <xacml-context:Request> element. 332 for i in ('subjects', 'resources', 'actions', 'environments'): 333 for targetChild in getattr(target, i): 334 for requestChild in getattr(request, i): 335 if self.matchTargetChild(targetChild, requestChild): 336 return True 337 338 339 340 return False 341 342 @classmethod 343 def matchTargetChild(cls, targetChild, requestChild): 344 """Match a child (Subject, Resource, Action or Environment) from the 345 request context with a given target's child 346 347 @param targetChild: Target Subject, Resource, Action or Environment 348 object 349 @type targetChild: ndg.xacml.core.TargetChildBase 350 @param requestChild: Request Subject, Resource, Action or Environment 351 object 352 @type requestChild: ndg.xacml.core.context.RequestChildBase 353 @return: True if request context matches something in the target 354 @rtype: bool 355 @raise NotImplementedError: AttributeSelector processing is not 356 currently supported. If an AttributeSelector is found in the policy, 357 this exception will be raised. 358 """ 359 if targetChild is None: 360 # Default if target child is not set is to match all children 361 return True 362 363 for childMatch in targetChild.matches: 364 attributeValue = childMatch.attributeValue 365 366 # Create a match function based on the presence or absence of an 367 # AttributeDesignator or AttributeSelector 368 if childMatch.attributeDesignator is not None: 369 attributeId = childMatch.attributeDesignator.attributeId 370 dataType = childMatch.attributeDesignator.dataType 371 372 _attributeMatch = lambda requestChildAttribute: ( 373 requestChildAttribute.attributeValue == attributeValue and 374 requestChildAttribute.attributeId == attributeId and 375 requestChildAttribute.dataType == dataType 376 ) 377 378 elif childMatch.attributeSelector is not None: 379 # Nb. This will require that the request provide a reference to 380 # it's XML representation and an abstraction of the XML parser 381 # for executing XPath searches into that representation 382 raise NotImplementedError('This PDP implementation does not ' 383 'support <AttributeSelector> ' 384 'elements') 385 else: 386 _attributeMatch = lambda requestChildAttribute: ( 387 requestChildAttribute.attributeValue == attributeValue 388 ) 389 390 for attribute in requestChild.attributes: 391 if _attributeMatch(attribute): 392 return True 393 394 return False 395 302 396 303 397 class TestContextHandler(AbstractContextHandler):
Note: See TracChangeset
for help on using the changeset viewer.