Changeset 6782 for TI12-security/trunk
- Timestamp:
- 26/03/10 16:34:43 (10 years ago)
- Location:
- TI12-security/trunk/NDG_XACML/ndg/xacml
- Files:
-
- 1 added
- 1 deleted
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
TI12-security/trunk/NDG_XACML/ndg/xacml/core/context/pdp.py
r6780 r6782 94 94 # INDETERMINATE response from any exceptions raised 95 95 try: 96 log.debug('Checking policy target for match ...')96 log.debug('Checking policy target for match with request...') 97 97 98 98 if not self.matchTarget(self.policy.target, request): … … 102 102 result.decision = Decision.NOT_APPLICABLE 103 103 return response 104 105 log.debug('Request matches the Policy target') 104 106 105 107 # Check rules … … 109 111 log.debug('No match to request context for target in rule ' 110 112 '%r', rule.id) 111 continue 113 continue 114 115 # Apply the condition 116 self.appyCondition(rule.condition) 112 117 except: 113 118 log.error('Exception raised evaluating request context, returning ' … … 139 144 # decision request, there MUST be at least one positive match between 140 145 # each section of the <Target> element and the corresponding section of 141 # the <xacml-context:Request> element. 142 for i in self.__class__.TARGET_CHILD_ATTRS: 143 for targetChild in getattr(target, i): 144 for requestChild in getattr(request, i): 145 if self.matchTargetChild(targetChild, requestChild): 146 return True 146 # the <xacml-context:Request> element. 147 # 148 # Also, 7.6: 149 # 150 # The target value SHALL be "Match" if the subjects, resources, actions 151 # and environments specified in the target all match values in the 152 # request context. 153 statusValues = [False]*len(self.__class__.TARGET_CHILD_ATTRS) 154 155 # Iterate for target subjects, resources, actions and environments 156 # elements 157 for i, status in zip(self.__class__.TARGET_CHILD_ATTRS, statusValues): 158 # If any one of the <Target> children is missing then it counts as 159 # a match e.g. for <Subjects> child element - Section 5.5: 160 # 161 # <Subjects> [Optional] Matching specification for the subject 162 # attributes in the context. If this element is missing, 163 # then the target SHALL match all subjects. 164 targetElem = getattr(target, i) 165 if len(targetElem) == 0: 166 status = True 167 continue 168 169 # Iterate over each for example, subject in the list of subjects or 170 # for example, resource in the list of resources and so on 171 for targetSubElem in targetElem: 172 173 # For the given subject/resource/action/environment check for a 174 # match with the equivalent in the request 175 requestElem = getattr(request, i) 176 for requestSubElem in requestElem: 177 if self.matchTargetChild(targetSubElem, requestSubElem): 178 # Within the list of e.g. subjects if one subject 179 # matches then this counts as a subject match overall 180 # for this target 181 status = True 147 182 148 return False 183 # Target matches if all the children (i.e. subjects, resources, actions 184 # and environment sections) have at least one match. Otherwise it 185 # doesn't count as a match 186 return all(statusValues) 149 187 150 188 def matchTargetChild(self, targetChild, requestChild): … … 164 202 this exception will be raised. 165 203 """ 204 matchStatus = True 205 166 206 if targetChild is None: 167 207 # Default if target child is not set is to match all children 168 208 return True 169 209 210 211 # Section 7.6 212 # 213 # A subject, resource, action or environment SHALL match a value in the 214 # request context if the value of all its <SubjectMatch>, 215 # <ResourceMatch>, <ActionMatch> or <EnvironmentMatch> elements, 216 # respectively, are âTrueâ. 170 217 for childMatch in targetChild.matches: 171 218 # Get the match function from the Match ID … … 187 234 dataType = childMatch.attributeDesignator.dataType 188 235 236 # Issuer is an optional match - see core spec 7.2.4 237 issuer = childMatch.attributeDesignator.issuer 238 if issuer is not None: 239 # Issuer found - set lambda to match this against the 240 # issuer setting in the request 241 _issuerMatch = lambda requestChildIssuer: (issuer == 242 requestChildIssuer) 243 else: 244 # No issuer set - lambda returns True regardless 245 _issuerMatch = lambda requestChildIssuer: True 246 247 189 248 _attributeMatch = lambda requestChildAttribute: ( 190 249 matchFunc.evaluate(matchAttributeValue, 191 250 requestChildAttribute.attributeValue.value) and 192 251 requestChildAttribute.attributeId == attributeId and 193 requestChildAttribute.dataType == dataType 252 requestChildAttribute.dataType == dataType and 253 _issuerMatch(requestChildAttribute.issuer) 194 254 ) 195 255 … … 208 268 209 269 for attribute in requestChild.attributes: 210 if _attributeMatch(attribute): 211 return True 212 213 return False 214 270 if _attributeMatch(attribute) == True: 271 if log.getEffectiveLevel() <= logging.DEBUG: 272 log.debug('Request attribute %r set to %r matches ' 273 'target', 274 attribute.attributeId, 275 attribute.attributeValue.value) 276 277 # Default status is True - any *Match element NOT matching 278 # will result in an overall status of no match 279 else: 280 # Don't return here but set the status to False. The other 281 # attributes need to be checked in case an error occurs. 282 # In this case the top-level PDP exception handling block 283 # will catch it and set an overall decision of INDETERMINATE 284 matchStatus = False 285 286 return matchStatus 287 288 def applyCondition(self, condition): 289 """Apply a rule condition""" 290 -
TI12-security/trunk/NDG_XACML/ndg/xacml/core/functions/v1/string_equal.py
r6777 r6782 4 4 """ 5 5 __author__ = "P J Kershaw" 6 __date__ = " 02/04/09"6 __date__ = "26/03/10" 7 7 __copyright__ = "" 8 8 __license__ = "BSD - see LICENSE file in top-level directory" -
TI12-security/trunk/NDG_XACML/ndg/xacml/core/functions/v2/anyuri_regexp_match.py
r6777 r6782 4 4 """ 5 5 __author__ = "P J Kershaw" 6 __date__ = " 02/04/09"6 __date__ = "26/03/10" 7 7 __copyright__ = "" 8 8 __license__ = "BSD - see LICENSE file in top-level directory" -
TI12-security/trunk/NDG_XACML/ndg/xacml/test/ndg1.xml
r6777 r6782 18 18 <ResourceMatch MatchId="urn:oasis:names:tc:xacml:2.0:function:anyURI-regexp-match"> 19 19 <ResourceAttributeDesignator 20 AttributeId="urn: siteA:security:authz:1.0:attr:resourceURI"20 AttributeId="urn:oasis:names:tc:xacml:1.0:resource:resource-id" 21 21 DataType="http://www.w3.org/2001/XMLSchema#anyURI"/> 22 22 <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#anyURI"> 23 ^ /.*$23 ^http://www.localhost/.*$ 24 24 </AttributeValue> 25 25 </ResourceMatch> … … 45 45 <Resource> 46 46 <!-- Pattern match the request URI --> 47 <ResourceMatch MatchId="urn:oasis:names:tc:xacml: 1.0:function:regexp-string-match">47 <ResourceMatch MatchId="urn:oasis:names:tc:xacml:2.0:function:anyURI-regexp-match"> 48 48 <ResourceAttributeDesignator 49 AttributeId="urn: siteA:security:authz:1.0:attr:resourceURI"49 AttributeId="urn:oasis:names:tc:xacml:1.0:resource:resource-id" 50 50 DataType="http://www.w3.org/2001/XMLSchema#string"/> 51 <AttributeValue DataType="http://www.w3.org/2001/XMLSchema# string">52 ^ /test_securedURI.*$51 <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#anyURI"> 52 ^http://localhost/test_securedURI.*$ 53 53 </AttributeValue> 54 54 </ResourceMatch> … … 70 70 AttributeId="urn:siteA:security:authz:1.0:attr" 71 71 MustBePresent="false" 72 DataType="http://www.w3.org/2001/XMLSchema#string"/> 72 DataType="http://www.w3.org/2001/XMLSchema#string" 73 Issuer="https://localhost:7443/AttributeAuthority"/> 73 74 <Apply FunctionId="urn:oasis:names:tc:xacml:1.0:function:string-bag"> 74 75 <!-- … … 77 78 from the applicable issuing attribute authority 78 79 --> 79 <AttributeValue 80 DataType="urn:ndg:security:1.0:authz:attributeType"> 81 <name DataType="http://www.w3.org/2001/XMLSchema#string"> 82 urn:siteA:security:authz:1.0:attr:staff 83 </name> 84 <issuer DataType="http://www.w3.org/2001/XMLSchema#string"> 85 http://localhost:7443/AttributeAuthority 86 </issuer> 80 <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string"> 81 urn:siteA:security:authz:1.0:attr:staff 87 82 </AttributeValue> 88 83 </Apply> -
TI12-security/trunk/NDG_XACML/ndg/xacml/test/test_context.py
r6780 r6782 82 82 resourceAttribute.attributeValue = AttributeValue() 83 83 resourceAttribute.attributeValue.value = \ 84 'file://example/med/record/patient/BartSimpson'84 'http://www.localhost/test_securedURI' 85 85 86 86 request.resources.append(resource)
Note: See TracChangeset
for help on using the changeset viewer.