Changeset 6792
- Timestamp:
- 31/03/10 16:41:23 (11 years ago)
- Location:
- TI12-security/trunk/NDG_XACML/ndg/xacml
- Files:
-
- 1 added
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
TI12-security/trunk/NDG_XACML/ndg/xacml/core/attribute.py
r6770 r6792 10 10 __contact__ = "Philip.Kershaw@stfc.ac.uk" 11 11 __revision__ = "$Id: $" 12 from ndg.xacml.utils import TypedList 12 13 from ndg.xacml.core import XacmlCoreBase 13 14 from ndg.xacml.core.attributevalue import AttributeValue … … 22 23 ISSUER_ATTRIB_NAME = 'Issuer' 23 24 24 __slots__ = ('__attributeValue ', '__dataType', '__attributeId', '__issuer')25 __slots__ = ('__attributeValues', '__dataType', '__attributeId', '__issuer') 25 26 26 27 def __init__(self): 27 self.__attributeValue = None28 self.__attributeValues = TypedList(AttributeValue) 28 29 self.__dataType = None 29 30 self.__attributeId = None 30 31 self.__issuer = None 31 32 32 def _get_attributeValue(self): 33 return self.__attributeValue 34 35 def _set_attributeValue(self, value): 36 if not isinstance(value, AttributeValue): 37 raise TypeError('Expecting %r type for "attributeValue" ' 38 'attribute; got %r' % (AttributeValue, type(value))) 39 40 self.__attributeValue = value 41 42 attributeValue = property(_get_attributeValue, _set_attributeValue, None, 43 "attribute value") 33 @property 34 def attributeValues(self): 35 "attribute values" 36 return self.__attributeValues 44 37 45 38 def _get_dataType(self): -
TI12-security/trunk/NDG_XACML/ndg/xacml/core/attributedesignator.py
r6790 r6792 69 69 70 70 self.__mustBePresent = value 71 72 73 def evaluate(self, context): 74 """Evaluate the result of the expression in a condition 75 76 TODO: implement this placeholder 77 78 @param context: the request context 79 @type context: ndg.xacml.core.context.request.Request 80 @return: attribute value(s) resulting from execution of this expression 81 in a condition 82 @rtype: AttributeValue/NoneType 83 """ 84 return self.__value 71 85 72 86 -
TI12-security/trunk/NDG_XACML/ndg/xacml/core/attributevalue.py
r6748 r6792 32 32 self.__value = value 33 33 34 value = property(_get_value, _set_value, None, "expression value") 34 value = property(_get_value, _set_value, None, "expression value") 35 36 def evaluate(self, context): 37 """Evaluate the result of the expression in a condition 38 @param context: the request context 39 @type context: ndg.xacml.core.context.request.Request 40 @return: attribute value(s) resulting from execution of this expression 41 in a condition 42 @rtype: AttributeValue/NoneType 43 """ 44 return self.__value -
TI12-security/trunk/NDG_XACML/ndg/xacml/core/context/pdp.py
r6790 r6792 16 16 17 17 from ndg.xacml.core.context.pdpinterface import PDPInterface 18 from ndg.xacml.core.rule import Effect19 18 from ndg.xacml.core.policy import Policy 20 19 from ndg.xacml.core.apply import Apply … … 64 63 def __init__(self, *arg, **kw): 65 64 super(UnsupportedFunctionError, self).__init__(*arg, **kw) 66 self.response.results[0].status.statusCode = StatusCode.PROCESSING_ERROR 65 self.response.results[0].status.statusCode.value = \ 66 StatusCode.PROCESSING_ERROR 67 67 68 68 … … 76 76 def __init__(self, *arg, **kw): 77 77 super(UnsupportedElementError, self).__init__(*arg, **kw) 78 self.response.results[0].status.statusCode = StatusCode.SYNTAX_ERROR 78 self.response.results[0].status.statusCode.value = \ 79 StatusCode.SYNTAX_ERROR 79 80 80 81 … … 433 434 434 435 _attributeMatch = lambda attribute: ( 435 matchFunc.evaluate(matchAttributeValue,436 attribute.attributeValue.value) and436 any([matchFunc.evaluate(matchAttributeValue, attrVal.value) 437 for attrVal in attribute.attributeValues]) and 437 438 attribute.attributeId == attributeId and 438 439 attribute.dataType == dataType and … … 489 490 490 491 # Marshall inputs 491 funcInputs = ('',)*len(applyElem.expressions)492 funcInputs = ['',]*len(applyElem.expressions) 492 493 for i, expression in enumerate(applyElem.expressions): 493 494 marshaller = inputMarshallerMap.get(expression.__class__) … … 506 507 507 508 # Execute function on the retrieved inputs 508 result = func(* funcInputs)509 result = func(*tuple(funcInputs)) 509 510 510 511 # Pass the result back to the parent <Apply> element … … 524 525 if isinstance(attributeDesignator, SubjectAttributeDesignator): 525 526 for i in self.request.subjects: 526 attributeValues.extend(527 [j.attributeValue for j in i.attributes528 if j.attributeValue.dataType == dataType])527 for j in i.attributes: 528 attributeValues.extend([k.value for k in j.attributeValues 529 if k.dataType == dataType]) 529 530 530 531 elif isinstance(attributeDesignator, ResourceAttributeDesignator): 531 532 for i in self.request.resources: 532 attributeValues.extend(533 [j.attributeValue for j in i.attributes534 if j.attributeValue.dataType == dataType])533 for j in i.attributes: 534 attributeValues.extend([k.value for k in j.attributeValues 535 if k.dataType == dataType]) 535 536 536 537 elif isinstance(attributeDesignator, ActionAttributeDesignator): 537 attributeValues.append([j.attributeValue for j in i.attributes 538 if j.attributeValue.dataType == dataType]) 538 for j in i.attributes: 539 attributeValues.extend([k.value for k in j.attributeValues 540 if k.dataType == dataType]) 539 541 540 542 elif isinstance(attributeDesignator, EnvironmentAttributeDesignator): 541 attributeValues.append([j.attributeValue for j in i.attributes 542 if j.attributeValue.dataType == dataType]) 543 for j in i.attributes: 544 attributeValues.extend([k.value for k in j.attributeValues 545 if k.dataType == dataType]) 543 546 else: 544 547 raise TypeError('Expecting %r derived type got %r' % -
TI12-security/trunk/NDG_XACML/ndg/xacml/core/expression.py
r6770 r6792 10 10 __contact__ = "Philip.Kershaw@stfc.ac.uk" 11 11 __revision__ = "$Id: $" 12 from abc import ABCMeta, abstractmethod 13 12 14 from ndg.xacml.core import XacmlCoreBase 13 15 … … 15 17 class Expression(XacmlCoreBase): 16 18 """XACML Expression type""" 19 __metaclass__ = ABCMeta 17 20 ELEMENT_LOCAL_NAME = None 18 21 DATA_TYPE_ATTRIB_NAME = 'DataType' … … 21 24 22 25 def __init__(self): 26 super(Expression, self).__init__() 23 27 self.__dataType = None 24 28 … … 35 39 dataType = property(_get_dataType, _set_dataType, None, 36 40 "expression value data type") 37 41 42 @abstractmethod 43 def evaluate(self, context): 44 """Evaluate the result of the expression in a condition. Derived 45 classes must implement 46 47 @param context: the request context 48 @type context: ndg.xacml.core.context.request.Request 49 @return: attribute value(s) resulting from execution of this expression 50 in a condition 51 @rtype: AttributeValue/NoneType 52 """ 53 raise NotImplementedError() -
TI12-security/trunk/NDG_XACML/ndg/xacml/core/functions/v1/string_equal.py
r6782 r6792 9 9 __contact__ = "Philip.Kershaw@stfc.ac.uk" 10 10 __revision__ = '$Id: $' 11 import re12 13 11 from ndg.xacml.core.functions import AbstractFunction 14 12 -
TI12-security/trunk/NDG_XACML/ndg/xacml/core/functions/v2/anyuri_regexp_match.py
r6782 r6792 29 29 @rtype: bool 30 30 """ 31 if not isinstance(uriPat, basestring): 32 raise TypeError('Expecting %r derived type for "uriPat"; got %r' % 33 (basestring, type(uri1))) 34 35 if not isinstance(uri, basestring): 36 raise TypeError('Expecting %r derived type for "uri"; got %r' % 37 (basestring, type(uri))) 38 31 39 return bool(re.match(uriPat, uri)) 32 40 -
TI12-security/trunk/NDG_XACML/ndg/xacml/test/ndg1.xml
r6790 r6792 20 20 AttributeId="urn:oasis:names:tc:xacml:1.0:resource:resource-id" 21 21 DataType="http://www.w3.org/2001/XMLSchema#anyURI"/> 22 <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#anyURI"> 23 ^http://www.localhost/.*$ 24 </AttributeValue> 22 <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#anyURI">^http://www.localhost/.*$</AttributeValue> 25 23 </ResourceMatch> 26 24 </Resource> … … 29 27 30 28 <!-- Deny everything by default --> 31 <!--32 29 <Rule RuleId="urn:ndg:security1.0:authz:test:DenyAllRule" Effect="Deny"/> 33 -->34 30 <!-- 35 31 Following rules punch holes through the deny everything rule above … … 48 44 <ResourceAttributeDesignator 49 45 AttributeId="urn:oasis:names:tc:xacml:1.0:resource:resource-id" 50 DataType="http://www.w3.org/2001/XMLSchema#string"/> 51 <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#anyURI"> 52 ^http://localhost/test_securedURI.*$ 53 </AttributeValue> 46 DataType="http://www.w3.org/2001/XMLSchema#anyURI"/> 47 <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#anyURI">^http://localhost/test_securedURI.*$</AttributeValue> 54 48 </ResourceMatch> 55 49 </Resource> … … 60 54 The condition narrows down the constraints layed down in the target to 61 55 something more specific 56 57 The user must have at least one of the roles set - in this 58 case 'urn:siteA:security:authz:1.0:attr:staff' 62 59 --> 63 <Condition> 64 <!-- 65 The user must have at least one of the roles set - in this 66 case 'urn:siteA:security:authz:1.0:attr:staff' 67 --> 68 <Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:string-at-least-one-member-of"> 69 <SubjectAttributeDesignator 70 AttributeId="urn:siteA:security:authz:1.0:attr" 71 DataType="http://www.w3.org/2001/XMLSchema#string"/> 72 <Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:string-bag"> 73 <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string"> 74 staff 75 </AttributeValue> 76 <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string"> 77 admin 78 </AttributeValue> 79 <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string"> 80 postdoc 81 </AttributeValue> 82 </Apply> 60 <Condition FunctionId="urn:oasis:names:tc:xacml:1.0:function:string-at-least-one-member-of"> 61 <SubjectAttributeDesignator 62 AttributeId="urn:ndg:security:authz:1.0:attr" 63 DataType="http://www.w3.org/2001/XMLSchema#string"/> 64 <Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:string-bag"> 65 <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">staff</AttributeValue> 66 <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">admin</AttributeValue> 67 <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">postdoc</AttributeValue> 83 68 </Apply> 84 69 </Condition> … … 88 73 <Resources> 89 74 <Resource> 90 <ResourceMatch 91 MatchId="urn:oasis:names:tc:xacml:1.0:function:regexp-string-match"> 75 <ResourceMatch MatchId="urn:oasis:names:tc:xacml:1.0:function:regexp-string-match"> 92 76 <ResourceAttributeDesignator 93 77 AttributeId="urn:siteA:security:authz:1.0:attr:resourceURI" 94 78 DataType="http://www.w3.org/2001/XMLSchema#string"/> 95 <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string"> 96 ^/test_accessDeniedToSecuredURI$ 97 </AttributeValue> 79 <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">^http://localhost/test_accessDeniedToSecuredURI$</AttributeValue> 98 80 </ResourceMatch> 99 81 </Resource> 100 82 </Resources> 101 83 </Target> 102 <Condition FunctionId="urn:oasis:names:tc:xacml:1.0:function:equal"> 103 <!-- 104 The user must have at least one of the roles set - in this 105 case 'urn:siteA:security:authz:1.0:attr:forbidden' or 106 'urn:siteA:security:authz:1.0:attr:keepout' 107 --> 108 <Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:string-at-least-one-member-of"> 109 <SubjectAttributeDesignator 110 AttributeId="urn:siteA:security:authz:1.0:attr" 111 MustBePresent="false" 112 DataType="http://www.w3.org/2001/XMLSchema#string"/> 113 <Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:string-bag"> 114 <AttributeValue 115 DataType="urn:ndg:security:1.0:authz:attributeType"> 116 <name DataType="http://www.w3.org/2001/XMLSchema#string"> 117 urn:siteA:security:authz:1.0:attr:forbidden 118 </name> 119 <issuer DataType="http://www.w3.org/2001/XMLSchema#string"> 120 http://localhost:7443/AttributeAuthority 121 </issuer> 122 </AttributeValue> 123 <AttributeValue 124 DataType="urn:ndg:security:1.0:authz:attributeType"> 125 <name DataType="http://www.w3.org/2001/XMLSchema#string"> 126 urn:siteA:security:authz:1.0:attr:keepout 127 </name> 128 <issuer DataType="http://www.w3.org/2001/XMLSchema#string"> 129 http://localhost:7443/AttributeAuthority 130 </issuer> 131 </AttributeValue> 132 </Apply> 84 <Condition FunctionId="urn:oasis:names:tc:xacml:1.0:function:string-at-least-one-member-of"> 85 <SubjectAttributeDesignator 86 AttributeId="urn:ndg:security:authz:1.0:attr" 87 DataType="http://www.w3.org/2001/XMLSchema#string"/> 88 <Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:string-bag"> 89 <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">forbidden</AttributeValue> 90 <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">keepout</AttributeValue> 133 91 </Apply> 134 92 </Condition> -
TI12-security/trunk/NDG_XACML/ndg/xacml/test/test_context.py
r6783 r6792 59 59 def _createRequestCtx(self): 60 60 request = Request() 61 subject = Subject() 61 62 62 subject = Subject() 63 subjectAttribute = Attribute() 64 subject.attributes.append(subjectAttribute) 65 subjectAttribute.attributeId = \ 66 "urn:oasis:names:tc:xacml:1.0:subject:subject-id" 67 subjectAttribute.dataType = \ 68 "urn:oasis:names:tc:xacml:1.0:data-type:rfc822Name" 69 subjectAttribute.attributeValue = AttributeValue() 70 subjectAttribute.attributeValue.value = 'bs@simpsons.com' 63 openidSubjectAttribute = Attribute() 64 roleAttribute = Attribute() 71 65 66 openidSubjectAttribute.attributeId = "urn:esg:openid" 67 openidSubjectAttribute.dataType = \ 68 'http://www.w3.org/2001/XMLSchema#anyURI' 69 openidSubjectAttribute.attributeValues.append(AttributeValue()) 70 openidSubjectAttribute.attributeValues[-1].dataType = \ 71 'http://www.w3.org/2001/XMLSchema#anyURI' 72 openidSubjectAttribute.attributeValues[-1].value = \ 73 'https://my.name.somewhere.ac.uk' 74 75 subject.attributes.append(openidSubjectAttribute) 76 77 roleAttribute.attributeId = "urn:ndg:security:authz:1.0:attr" 78 roleAttribute.dataType = 'http://www.w3.org/2001/XMLSchema#string' 79 roleAttribute.attributeValues.append(AttributeValue()) 80 roleAttribute.attributeValues[-1].dataType = \ 81 'http://www.w3.org/2001/XMLSchema#string' 82 roleAttribute.attributeValues[-1].value = 'staff' 83 84 subject.attributes.append(roleAttribute) 85 72 86 request.subjects.append(subject) 73 87 … … 80 94 81 95 resourceAttribute.dataType = "http://www.w3.org/2001/XMLSchema#anyURI" 82 resourceAttribute.attributeValue = AttributeValue()83 resourceAttribute.attributeValue .value = \96 resourceAttribute.attributeValues.append(AttributeValue()) 97 resourceAttribute.attributeValues[-1].value = \ 84 98 'http://www.localhost/test_securedURI' 85 99 … … 93 107 "urn:oasis:names:tc:xacml:1.0:action:action-id" 94 108 actionAttribute.dataType = "http://www.w3.org/2001/XMLSchema#string" 95 actionAttribute.attributeValue = AttributeValue()96 actionAttribute.attributeValue .value = 'read'109 actionAttribute.attributeValues.append(AttributeValue()) 110 actionAttribute.attributeValues[-1].value = 'read' 97 111 98 112 return request
Note: See TracChangeset
for help on using the changeset viewer.