Changeset 6805
- Timestamp:
- 14/04/10 15:45:01 (11 years ago)
- Location:
- TI12-security/trunk/NDG_XACML/ndg/xacml
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
TI12-security/trunk/NDG_XACML/ndg/xacml/core/apply.py
r6804 r6805 136 136 137 137 # Marshall inputs 138 funcInputs = [ '']*len(self.expressions)138 funcInputs = [None]*len(self.expressions) 139 139 140 140 for i, expression in enumerate(self.expressions): -
TI12-security/trunk/NDG_XACML/ndg/xacml/core/attribute.py
r6792 r6805 35 35 "attribute values" 36 36 return self.__attributeValues 37 38 @attributeValues.setter 39 def attributeValues(self, value): 40 "attribute values" 41 if not isinstance(value, TypedList): 42 raise TypeError('Expecting %r type for "attributeValues" ' 43 'attribute; got %r' % (TypedList, type(value))) 37 44 45 self.__attributeValues = value 46 38 47 def _get_dataType(self): 39 48 return self.__dataType -
TI12-security/trunk/NDG_XACML/ndg/xacml/core/attributedesignator.py
r6796 r6805 12 12 from ndg.xacml.utils import TypedList 13 13 from ndg.xacml.core.expression import Expression 14 from ndg.xacml.core.attributevalue import AttributeValue 14 from ndg.xacml.core.attributevalue import (AttributeValue, 15 AttributeValueClassFactory) 15 16 from ndg.xacml.core.context.request import Request 16 17 from ndg.xacml.core.context.exceptions import MissingAttributeError … … 24 25 MUST_BE_PRESENT_ATTRIB_NAME = 'MustBePresent' 25 26 26 __slots__ = ('__attributeId', '__issuer', '__mustBePresent') 27 __slots__ = ( 28 '__attributeId', 29 '__issuer', 30 '__mustBePresent', 31 '__attributeValueFactory' 32 ) 27 33 28 34 def __init__(self): … … 31 37 self.__issuer = None 32 38 self.__mustBePresent = False 39 self.__attributeValueFactory = AttributeValueClassFactory() 33 40 34 41 @property … … 72 79 'attribute; got %r' % (bool, type(value))) 73 80 74 self.__mustBePresent = value 75 81 self.__mustBePresent = value 82 83 @property 84 def attributeValueFactory(self): 85 """Get Attribute Value factory function""" 86 return self.__attributeValueFactory 87 76 88 77 89 class SubjectAttributeDesignator(AttributeDesignator): 78 90 """XACML Subject Attribute Designator type""" 79 91 ELEMENT_LOCAL_NAME = 'SubjectAttributeDesignator' 80 92 81 93 def evaluate(self, context): 82 94 """Evaluate the result of the SubjectAttributeDesignator in a condition … … 92 104 (Request, type(context))) 93 105 94 attributeValueBag = TypedList(AttributeValue)95 dataType = self.dataType106 dataType = self.dataType 107 attributeValueBag = TypedList(self.attributeValueFactory(dataType)) 96 108 attributeId = self.attributeId 97 109 issuer = self.issuer … … 141 153 (Request, type(context))) 142 154 143 attributeValueBag = TypedList(AttributeValue)144 dataType = self.dataType155 dataType = self.dataType 156 attributeValueBag = TypedList(self.attributeValueFactory(dataType)) 145 157 attributeId = self.attributeId 146 158 issuer = self.issuer … … 190 202 (Request, type(context))) 191 203 192 attributeValueBag = TypedList(AttributeValue)193 dataType = self.dataType204 dataType = self.dataType 205 attributeValueBag = TypedList(self.attributeValueFactory(dataType)) 194 206 attributeId = self.attributeId 195 207 issuer = self.issuer … … 240 252 (Request, type(context))) 241 253 242 attributeValueBag = []243 dataType = self.dataType254 dataType = self.dataType 255 attributeValueBag = TypedList(self.attributeValueFactory(dataType)) 244 256 attributeId = self.attributeId 245 257 issuer = self.issuer -
TI12-security/trunk/NDG_XACML/ndg/xacml/core/attributevalue.py
r6804 r6805 51 51 52 52 self.__value = None 53 53 54 def __repr__(self): 55 return "%s = %r " % (super(AttributeValue, self).__repr__(), 56 self.__value) 57 54 58 def _get_value(self): 55 59 return self.__value … … 66 70 67 71 def evaluate(self, context): 68 """Evaluate the result of the expression in a condition 72 """Evaluate the result of the expression in a condition. In the case of 73 an attribute value it's simply itself 74 69 75 @param context: the request context 70 76 @type context: ndg.xacml.core.context.request.Request 71 @return: attribute value(s) resulting from execution of this expression 72 in a condition 73 @rtype: AttributeValue/NoneType 77 @return: this attribute value 78 @rtype: AttributeValue 74 79 """ 75 return self .__value80 return self 76 81 77 82 -
TI12-security/trunk/NDG_XACML/ndg/xacml/core/context/pdp.py
r6804 r6805 304 304 _attributeMatch = self.attributeDesignatorMatchFuncFactory( 305 305 matchFunctionClass(), 306 childMatch.attributeValue .value,306 childMatch.attributeValue, 307 307 childMatch.attributeDesignator) 308 308 … … 371 371 372 372 _attributeMatch = lambda attribute: ( 373 any([matchFunc.evaluate(matchAttributeValue, attrVal .value)373 any([matchFunc.evaluate(matchAttributeValue, attrVal) 374 374 for attrVal in attribute.attributeValues]) and 375 375 attribute.attributeId == attributeId and … … 403 403 404 404 result = applyElem.evaluate(self.request) 405 406 407 405 406 return result 407 408 409 -
TI12-security/trunk/NDG_XACML/ndg/xacml/core/functions/__init__.py
r6804 r6805 16 16 log = logging.getLogger(__name__) 17 17 18 from ndg.xacml.core.attributevalue import AttributeValue 18 from ndg.xacml.core.attributevalue import (AttributeValue, 19 AttributeValueClassFactory) 19 20 from ndg.xacml.utils import VettedDict, _isIterable 20 21 from ndg.xacml.utils.factory import callModuleObject … … 349 350 for n in functionSuffixParts if n]) 350 351 352 attributeValueClassFactory = AttributeValueClassFactory() 353 351 354 for identifier in self.__class__.FUNCTION_NAMES: 352 355 # Extract the function name and the type portion of the function … … 356 359 357 360 typeName = typePart[0].upper() + typePart[1:] 358 _type = AttributeValue.TYPE_MAP.get(typeName) 361 typeURI = AttributeValue.IDENTIFIER_PREFIX + typePart 362 _type = attributeValueClassFactory(typeURI) 359 363 if _type is None: 360 364 raise TypeError('No AttributeValue.TYPE_MAP entry for %r type' % -
TI12-security/trunk/NDG_XACML/ndg/xacml/core/functions/v1/at_least_one_member_of.py
r6804 r6805 16 16 class AtLeastOneMemberOfBase(AbstractFunction): 17 17 """Base class implementation for at least one member of XACML function - 18 check a n item of a given type is contained in a given bag18 check at least one item in one set is contained in the second set 19 19 20 20 urn:oasis:names:tc:xacml:1.0:function:<type>-at-least-one-member-of 21 22 @cvar TYPE: AttributeValue type for the sets 23 @type TYPE: AttributeValue sub-class 21 24 """ 22 25 TYPE = None 23 26 24 def evaluate(self, item, bag):27 def evaluate(self, set1, set2): 25 28 """Check input is contained in the bag 26 29 27 @param item: check to see if this string is contained in the bag 28 @type item: type 29 @param bag: bag of <type> values 30 @type bag: TypedList(<type>) 30 @param set1: check to see if at least one item in this set is contained 31 in the second set 32 @type set1: TypedList(self.__class__.TYPE) 33 @param set2: bag of self.__class__.TYPE values 34 @type set2: TypedList(self.__class__.TYPE) 31 35 @return: True if str is in bag, False otherwise 32 36 @rtype: bool 33 37 """ 34 if not isinstance(item, self.__class__.TYPE): 35 raise XacmlContextTypeError('Expecting %r derived type for "item"; ' 36 'got %r' % (self.__class__.TYPE, 37 type(item))) 38 if not isinstance(set1, Bag): 39 raise XacmlContextTypeError('Expecting %r derived type for "set1"; ' 40 'got %r' % (Bag, type(set1))) 38 41 39 if not isinstance(bag, Bag): 40 raise XacmlContextTypeError('Expecting %r derived type for "bag"; ' 41 'got %r' % (Bag, type(bag))) 42 if set1.elementType != self.__class__.TYPE: 43 raise XacmlContextTypeError('Expecting %r type elements for ' 44 '"set1"; got %r' % 45 (self.__class__.TYPE, set1.elementType)) 42 46 43 if bag.elementType != self.__class__.TYPE: 44 raise XacmlContextTypeError('Expecting %r type elements for "bag"; ' 45 'got %r' % 46 (self.__class__.TYPE, bag.elementType)) 47 return item in bag 47 if not isinstance(set2, Bag): 48 raise XacmlContextTypeError('Expecting %r derived type for "set2"; ' 49 'got %r' % (Bag, type(set2))) 50 51 if set2.elementType != self.__class__.TYPE: 52 raise XacmlContextTypeError('Expecting %r type elements for ' 53 '"set2"; got %r' % 54 (self.__class__.TYPE, set2.elementType)) 55 56 set2Values = [attr.value for attr in set2] 57 for i in set1: 58 if i.value in set2Values: 59 return True 60 61 return False 48 62 49 63 -
TI12-security/trunk/NDG_XACML/ndg/xacml/core/functions/v1/bag.py
r6804 r6805 36 36 bag = Bag(self.__class__.TYPE) 37 37 for i in args: 38 if not isinstance(i, basestring):38 if not isinstance(i, self.__class__.TYPE): 39 39 raise TypeError('Expecting %r derived type for bag element; ' 40 40 'got %r' % (self.__class__.TYPE, type(i))) -
TI12-security/trunk/NDG_XACML/ndg/xacml/core/functions/v1/regexp_match.py
r6804 r6805 10 10 __revision__ = '$Id: $' 11 11 import re 12 #import sys13 12 13 from ndg.xacml.core.context.exceptions import XacmlContextTypeError 14 from ndg.xacml.core.attributevalue import AttributeValueClassFactory 14 15 from ndg.xacml.core.functions import (AbstractFunction, 15 16 FunctionClassFactoryInterface) 16 from ndg.xacml.core.context.exceptions import XacmlContextTypeError17 17 18 18 … … 35 35 @rtype: bool 36 36 """ 37 if not isinstance(pat, basestring):37 if not isinstance(pat, self.__class__.TYPE): 38 38 raise TypeError('Expecting %r derived type for "pat"; got %r' % 39 ( basestring, type(pat)))39 (self.__class__.TYPE, type(pat))) 40 40 41 41 if not isinstance(input, self.__class__.TYPE): … … 43 43 (self.__class__.TYPE, type(input))) 44 44 45 return bool(re.match(pat , input))45 return bool(re.match(pat.value, input.value)) 46 46 47 48 attributeValueClassFactory = AttributeValueClassFactory() 47 49 48 50 class StringRegexMatch(RegexpMatchBase): 49 51 FUNCTION_NS = 'urn:oasis:names:tc:xacml:1.0:function:string-regexp-match' 50 TYPE = basestring52 TYPE = attributeValueClassFactory('http://www.w3.org/2001/XMLSchema#string') 51 53 52 54 -
TI12-security/trunk/NDG_XACML/ndg/xacml/test/ndg1.xml
r6796 r6805 75 75 <Resources> 76 76 <Resource> 77 <ResourceMatch MatchId="urn:oasis:names:tc:xacml: 1.0:function:regexp-string-match">77 <ResourceMatch MatchId="urn:oasis:names:tc:xacml:2.0:function:anyURI-regexp-match"> 78 78 <ResourceAttributeDesignator 79 79 AttributeId="urn:siteA:security:authz:1.0:attr:resourceURI" 80 DataType="http://www.w3.org/2001/XMLSchema# string"/>81 <AttributeValue DataType="http://www.w3.org/2001/XMLSchema# string">^http://localhost/test_accessDeniedToSecuredURI$</AttributeValue>80 DataType="http://www.w3.org/2001/XMLSchema#anyURI"/> 81 <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#anyURI">^http://localhost/test_accessDeniedToSecuredURI$</AttributeValue> 82 82 </ResourceMatch> 83 83 </Resource> -
TI12-security/trunk/NDG_XACML/ndg/xacml/test/test_context.py
r6802 r6805 71 71 'http://www.w3.org/2001/XMLSchema#anyURI' 72 72 73 StringAttributeValue = attributeValueFactory(73 AnyUriAttributeValue = attributeValueFactory( 74 74 'http://www.w3.org/2001/XMLSchema#anyURI') 75 openidSubjectAttribute.attributeValues.append( StringAttributeValue())75 openidSubjectAttribute.attributeValues.append(AnyUriAttributeValue()) 76 76 77 77 openidSubjectAttribute.attributeValues[-1].dataType = \ 78 78 'http://www.w3.org/2001/XMLSchema#anyURI' 79 80 79 81 openidSubjectAttribute.attributeValues[-1].value = \ 80 82 'https://my.name.somewhere.ac.uk' … … 82 84 subject.attributes.append(openidSubjectAttribute) 83 85 86 StringAttributeValue = attributeValueFactory( 87 'http://www.w3.org/2001/XMLSchema#string') 88 84 89 roleAttribute.attributeId = "urn:ndg:security:authz:1.0:attr" 85 90 roleAttribute.dataType = 'http://www.w3.org/2001/XMLSchema#string' 91 86 92 roleAttribute.attributeValues.append(StringAttributeValue()) 87 93 roleAttribute.attributeValues[-1].dataType = \ … … 101 107 102 108 resourceAttribute.dataType = "http://www.w3.org/2001/XMLSchema#anyURI" 103 resourceAttribute.attributeValues.append( StringAttributeValue())109 resourceAttribute.attributeValues.append(AnyUriAttributeValue()) 104 110 resourceAttribute.attributeValues[-1].value = \ 105 111 'http://www.localhost/test_securedURI' -
TI12-security/trunk/NDG_XACML/ndg/xacml/utils/__init__.py
r6777 r6805 47 47 self.__elementType = elementType 48 48 super(TypedList, self).__init__(*arg, **kw) 49 49 50 def __repr__(self): 51 return "%r type: %s" % (self.__elementType, 52 super(TypedList, self).__repr__()) 53 50 54 def _getElementType(self): 51 55 return self.__elementType
Note: See TracChangeset
for help on using the changeset viewer.