Changeset 6823
- Timestamp:
- 16/04/10 10:36:08 (11 years ago)
- Location:
- TI12-security/trunk/NDG_XACML/ndg/xacml/core
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
TI12-security/trunk/NDG_XACML/ndg/xacml/core/policy.py
r6822 r6823 17 17 from ndg.xacml.core.rule import Rule 18 18 from ndg.xacml.core.obligation import Obligation 19 from ndg.xacml.core.rule_combining_alg import (RuleCombiningAlgInterface, 20 RuleCombiningAlgClassFactory) 19 from ndg.xacml.core.rule_combining_alg import (RuleCombiningAlgClassFactory, 20 RuleCombiningAlgInterface) 21 from ndg.xacml.core.exceptions import (UnsupportedStdFunctionError, 22 UnsupportedFunctionError) 21 23 22 24 … … 43 45 OBLIGATIONS_LOCAL_NAME = "Obligations" 44 46 45 # Plan to support permit overrides in a future release46 RULE_COMBINING_ALG_IDS = (47 "urn:oasis:names:tc:xacml:1.0:rule-combining-algorithm:permit-overrides",48 "urn:oasis:names:tc:xacml:1.0:rule-combining-algorithm:deny-overrides",49 )50 47 __slots__ = ( 51 48 '__policyId', … … 61 58 ) 62 59 63 def __init__(self): 60 def __init__(self, ruleCombiningAlgFactory=None): 61 """Customise rule combining behaviour by passing in a custom combining 62 algorithm factory. This is invoked when the combining algorithm Id 63 property is set in order to create the corresponding combining algorithm 64 object 65 """ 64 66 super(Policy, self).__init__() 65 67 self.__policyId = None … … 76 78 self.__obligations = TypedList(Obligation) 77 79 78 self.__ruleCombiningAlgFactory = RuleCombiningAlgClassFactory() 80 self.__ruleCombiningAlgFactory = None 81 if ruleCombiningAlgFactory is None: 82 self.ruleCombiningAlgFactory = RuleCombiningAlgClassFactory() 83 else: 84 self.ruleCombiningAlgFactory = ruleCombiningAlgFactory 79 85 80 86 self.__ruleCombiningAlg = None … … 94 100 _setRuleCombiningAlgFactory, 95 101 doc="Rule Combining Algorithm Factory") 96 def _getRuleCombiningAlg(self): 102 103 @property 104 def ruleCombiningAlg(self): 105 "Rule Combining algorithm" 97 106 return self.__ruleCombiningAlg 98 99 def _setRuleCombiningAlg(self, value):100 if (value not in (NotImplemented, None) and101 not issubclass(value, RuleCombiningAlgInterface)):102 raise TypeError('Expecting %r derived type or None or '103 'NotImplemented for "ruleCombiningAlg" attibute; '104 'got %r' % (RuleCombiningAlgInterface, type(value)))105 106 self.__ruleCombiningAlg = value107 108 ruleCombiningAlg = property(_getRuleCombiningAlg, _setRuleCombiningAlg,109 doc="Rule Combining algorithm")110 107 111 108 @classmethod … … 168 165 'attribute; got %r' % type(value)) 169 166 170 if value not in Policy.RULE_COMBINING_ALG_IDS:171 raise AttributeError('%r rule combining algorithm is invalid. '172 'Only these algorithms are currently '173 'supported %r' %174 (value, Policy.RULE_COMBINING_ALG_IDS))175 167 self.__ruleCombiningAlgId = value 176 168 self._setRuleCombiningAlgFromId() 169 170 def _setRuleCombiningAlgFromId(self): 171 """Set the rule combining algorithm implementation from the Id set 172 """ 177 173 # Look-up rule combining algorithm 178 self.__ruleCombiningAlg= self.__ruleCombiningAlgFactory(174 ruleCombiningAlgClass = self.__ruleCombiningAlgFactory( 179 175 self.__ruleCombiningAlgId) 176 if not issubclass(ruleCombiningAlgClass, RuleCombiningAlgInterface): 177 raise TypeError('Expecting %r derived type for rule combining ' 178 'algorithm class; got %r' % 179 (RuleCombiningAlgInterface, ruleCombiningAlgClass)) 180 181 self.__ruleCombiningAlg = ruleCombiningAlgClass() 182 if self.__ruleCombiningAlg is NotImplemented: 183 raise UnsupportedStdFunctionError('The rule combining algorithm %r ' 184 'is not currently implemented' % 185 self.__ruleCombiningAlgId) 186 187 elif self.__ruleCombiningAlg is None: 188 raise UnsupportedFunctionError('%r is not recognised as a valid ' 189 'XACML rule combining algorithm' % 190 self.__ruleCombiningAlgId) 180 191 181 192 ruleCombiningAlgId = property(_getRuleCombiningAlgId, 182 193 _setRuleCombiningAlgId, None, 183 194 doc="Rule Combining Algorithm Id") 184 185 195 186 196 @property … … 241 251 None, 242 252 "Policy PolicyDefaults element") 243 def parse(self): 244 """Parse the policy file set in policyFilePath attribute 245 """ 246 elem = ElementTree.parse(self.policyFilePath) 247 root = elem.getroot() 248 249 self.xmlns = QName.getNs(root.tag) 250 if not self.isValidXmlns: 251 raise InvalidPolicyXmlNsError("Namespace %r is recognised; valid " 252 "namespaces are: %r" % 253 (self.xmlns, Policy.XMLNS)) 254 255 for elem in root: 256 localName = QName.getLocalPart(elem.tag) 257 if localName == Policy.DESCRIPTION_LOCALNAME: 258 self.description = elem.text.strip() 259 260 elif localName == Policy.TARGET_LOCALNAME: 261 self.targets.append(Target.Parse(elem)) 262 263 else: 264 raise PolicyParseError("Invalid policy attribute: %s" % 265 localName) 266 267 @classmethod 268 def Parse(cls, policyFilePath): 269 policy = cls(policyFilePath=policyFilePath) 270 policy.parse() 271 return policy 272 273 253 254 -
TI12-security/trunk/NDG_XACML/ndg/xacml/core/rule_combining_alg.py
r6822 r6823 50 50 51 51 52 class PermitOverridesRuleCombin gAlg(RuleCombiningAlgInterface):52 class PermitOverridesRuleCombiningAlg(RuleCombiningAlgInterface): 53 53 """Implementation of permit overrides XACML rule combining algorithm""" 54 54 … … 70 70 atLeastOneDeny = False 71 71 72 for rule in rules: 72 for rule in rules: 73 73 decision = rule.evaluate(context) 74 74 if decision == Decision.DENY: … … 105 105 """Class Factory mapping Rule Combining Algorithm identifiers to their 106 106 class implementations""" 107 108 # All algorithms are not implemented by default(!) 107 109 DEFAULT_MAP = {}.fromkeys(ALGORITHMS, NotImplemented) 110 111 # Permit overrides is the only one currently implemented 108 112 DEFAULT_MAP[ 109 113 'urn:oasis:names:tc:xacml:1.0:rule-combining-algorithm:permit-overrides' 110 ] = PermitOverridesRuleCombin gAlg114 ] = PermitOverridesRuleCombiningAlg 111 115 112 116 def __init__(self, map=DEFAULT_MAP): … … 116 120 def __call__(self, identifier): 117 121 """Return the class for a given Rule Combining Algorithm identifier 122 @param identifier: XACML rule combining algorithm urn 123 @type identifier: basestring 124 @return: rule combining class corresponding to the given input 125 identifier 126 @rtype: RuleCombiningAlgInterface derived type or NoneType if no match 127 is found or NotImplementedType if the identifier corresponds to a valid 128 XACML rule combining algorithm but is not supported in this 129 implementation 118 130 """ 119 self.__map.get(identifier)131 return self.__map.get(identifier)
Note: See TracChangeset
for help on using the changeset viewer.