Changeset 7682 for TI12-security/trunk/ndg_xacml/ndg
- Timestamp:
- 01/11/10 16:30:22 (10 years ago)
- Location:
- TI12-security/trunk/ndg_xacml/ndg/xacml
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
TI12-security/trunk/ndg_xacml/ndg/xacml/core/attributevalue.py
r7661 r7682 150 150 def __repr__(self): 151 151 return "%s = %r " % (super(AttributeValue, self).__repr__(), 152 self. __value)152 self.value) 153 153 154 154 def __eq__(self, attrVal): -
TI12-security/trunk/ndg_xacml/ndg/xacml/core/functions/__init__.py
r7668 r7682 611 611 @type functionNs: basestring 612 612 """ 613 # Try map for custom function class 614 if functionNs in self: 615 return self[functionNs] 616 617 # else try the class factory - there is one factory per family of 618 # functions e.g. bag functions, at least one member of functions etc. 613 619 functionFactory = self.__classFactoryMap.get(functionNs) 614 620 if functionFactory is not None: -
TI12-security/trunk/ndg_xacml/ndg/xacml/core/rule.py
r7365 r7682 390 390 else: 391 391 decision = Decision.NOT_APPLICABLE 392 392 393 log.debug('Rule %r evaluates to %s', self.id, decision) 393 394 return decision 394 395 -
TI12-security/trunk/ndg_xacml/ndg/xacml/core/rule_combining_alg.py
r7108 r7682 10 10 __contact__ = "Philip.Kershaw@stfc.ac.uk" 11 11 __revision__ = "$Id$" 12 from abc import ABCMeta, abstractmethod 12 import logging 13 log = logging.getLogger(__name__) 14 15 from abc import abstractmethod 13 16 14 17 from ndg.xacml.core.context.result import Decision … … 86 89 atLeastOneError = True 87 90 88 if effect(rule)== Decision.DENY:91 if rule.effect.value == Decision.DENY: 89 92 potentialDeny = True 90 93 … … 130 133 131 134 if decision == Decision.PERMIT: 135 log.debug("Rule %r permits, returning overall permit decision", 136 rule.id) 132 137 return Decision.PERMIT 133 138 … … 144 149 145 150 if potentialPermit: 151 log.debug('Rule found with potential permit but it evaluates to ' 152 'indeterminate, returning overall indeterminate decision') 146 153 return Decision.INDETERMINATE 147 154 148 155 if atLeastOneDeny: 156 log.debug('At least one rule with a deny decision found, returning ' 157 'overall deny decision') 149 158 return Decision.DENY 150 159 151 160 if atLeastOneError: 152 return Decision.INDETERMINATE 153 161 log.debug('At least one rule with an error found, returning ' 162 'overall indeterminate decision') 163 return Decision.INDETERMINATE 164 165 log.debug('No rules were applicable to the request, returning ' 166 'overall not applicable decision') 154 167 return Decision.NOT_APPLICABLE 155 168 -
TI12-security/trunk/ndg_xacml/ndg/xacml/parsers/etree/policyreader.py
r7109 r7682 98 98 elif localName == Rule.ELEMENT_LOCAL_NAME: 99 99 RuleReader = ReaderFactory.getReader(Rule) 100 policy.rules.append(RuleReader.parse(childElem)) 100 rule = RuleReader.parse(childElem) 101 if rule.id in [_rule.id for _rule in policy.rules]: 102 raise XMLParseError("Duplicate Rule ID %r found" % rule.id) 103 104 policy.rules.append(rule) 101 105 102 106 elif localName == xacmlType.OBLIGATIONS_LOCAL_NAME: -
TI12-security/trunk/ndg_xacml/ndg/xacml/test/__init__.py
r7666 r7682 14 14 from ndg.xacml.core.attributevalue import (AttributeValueClassFactory, 15 15 AttributeValue) 16 from ndg.xacml.core.functions.v1.bag import BagBase 17 from ndg.xacml.core.functions.v1.at_least_one_member_of import \ 18 AtLeastOneMemberOfBase 19 16 20 from ndg.xacml.parsers import XMLParseError 17 21 from ndg.xacml.parsers.etree import QName … … 46 50 def value(self): 47 51 """Override default value property to give custom result. Also, 48 'value' becomes a read-only property""" 49 return self.group, self.value 52 'value' becomes a read-only property. Making this change is critical 53 to the function of the GroupRoleAtLeastOneMemberOf class below - it 54 relies on being able to make comparison of the value attribute of 55 different GroupRoleAttributeValue instances. Defined this way, 56 comparison is by group,role to group,role tuple 57 """ 58 return self.group, self.role 50 59 60 61 class GroupRoleBag(BagBase): 62 """Bag function for Group/Role custom attribute value type""" 63 TYPE = GroupRoleAttributeValue 64 FUNCTION_NS = 'urn:grouprole-bag' 65 66 67 class GroupRoleAtLeastOneMemberOf(AtLeastOneMemberOfBase): 68 """At least one member of function for Group/Role custom attribute value 69 type""" 70 TYPE = GroupRoleAttributeValue 71 FUNCTION_NS = 'urn:grouprole-bag' 72 51 73 52 74 class ETreeGroupRoleDataTypeReader(ETreeDataTypeReaderBase): -
TI12-security/trunk/ndg_xacml/ndg/xacml/test/context/test_pdp.py
r7666 r7682 36 36 'http://localhost/action-and-single-subject-role-restricted' 37 37 AT_LEAST_ONE_SUBJECT_ROLE_RESTRICTED_ID = \ 38 'http://localhost/at-least-o f-subject-role-restricted'38 'http://localhost/at-least-one-of-subject-role-restricted' 39 39 40 40 def setUp(self): -
TI12-security/trunk/ndg_xacml/ndg/xacml/test/context/test_pdp_with_custom_attributevalue_types.py
r7668 r7682 20 20 from ndg.xacml.core.attributevalue import AttributeValueClassFactory 21 21 from ndg.xacml.core.functions import functionMap 22 from ndg.xacml.core.functions.v1.bag import BagBase23 from ndg.xacml.core.functions.v1.at_least_one_member_of import \24 AtLeastOneMemberOfBase25 22 from ndg.xacml.core.context.request import Request 26 23 from ndg.xacml.core.context.subject import Subject … … 35 32 from ndg.xacml.test import (XACML_ESGFTEST1_FILEPATH, 36 33 GroupRoleAttributeValue, 37 ETreeGroupRoleDataTypeReader) 34 ETreeGroupRoleDataTypeReader, 35 GroupRoleBag, 36 GroupRoleAtLeastOneMemberOf) 38 37 from ndg.xacml.test.context import (AnyUriAttributeValue, StringAttributeValue, 39 38 SUBJECT_ID) 40 39 41 40 42 41 class XacmlEvalPdpWithCustomAttrTypes(unittest.TestCase): 43 42 """Evaluate a policy which contains custom XACML Attribute Value Data types 44 43 """ 45 44 AT_LEAST_ONE_SUBJECT_ROLE_RESTRICTED_ID = \ 46 'http://localhost/at-least-of-subject-role-restricted' 47 45 'http://localhost/at-least-one-of-subject-role-restricted' 46 SUBJECT_DOES_NOT_HAVE_ANY_OF_SPECIFIED_ROLES_ID = \ 47 'http://localhost/subject-does-not-have-any-of-specified-roles' 48 48 49 @staticmethod 49 50 def _createRequestCtx(resourceId, … … 121 122 122 123 # Add extra matching and bag functions 124 functionMap['urn:grouprole-bag'] = GroupRoleBag 125 functionMap['urn:grouprole-at-least-one-member-of' 126 ] = GroupRoleAtLeastOneMemberOf 123 127 124 128 # Example policy with custom attribute value type used with ESGF … … 135 139 self.failIf(result.decision != Decision.PERMIT, 136 140 "Expecting Permit decision") 137 141 142 def test02SubjectDoesNotHaveAnyOfSpecifiedRolesForResource(self): 143 # Test at least one member function 144 request = self._createRequestCtx( 145 self.__class__.SUBJECT_DOES_NOT_HAVE_ANY_OF_SPECIFIED_ROLES_ID, 146 action='write') 147 148 response = self.pdp.evaluate(request) 149 self.failIf(response is None, "Null response") 150 for result in response.results: 151 self.failIf(result.decision != Decision.DENY, 152 "Expecting Deny decision") 153 138 154 139 155 if __name__ == "__main__": -
TI12-security/trunk/ndg_xacml/ndg/xacml/test/esgf1.xml
r7666 r7682 45 45 <!-- Pattern match the request URI --> 46 46 <ResourceMatch MatchId="urn:oasis:names:tc:xacml:2.0:function:anyURI-regexp-match"> 47 <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#anyURI">^http://localhost/at-least-o f-subject-role-restricted.*$</AttributeValue>47 <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#anyURI">^http://localhost/at-least-one-of-subject-role-restricted.*$</AttributeValue> 48 48 <ResourceAttributeDesignator 49 49 AttributeId="urn:oasis:names:tc:xacml:1.0:resource:resource-id" … … 83 83 </Condition> 84 84 </Rule> 85 <Rule RuleId="Subject doesn't have any of specified roles" Effect="Permit"> 86 <!-- 87 Example where test subject doesn't have the required roles 88 --> 89 <Target> 90 <Resources> 91 <Resource> 92 <!-- Pattern match the request URI --> 93 <ResourceMatch MatchId="urn:oasis:names:tc:xacml:2.0:function:anyURI-regexp-match"> 94 <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#anyURI">^http://localhost/subject-does-not-have-any-of-specified-roles.*$</AttributeValue> 95 <ResourceAttributeDesignator 96 AttributeId="urn:oasis:names:tc:xacml:1.0:resource:resource-id" 97 DataType="http://www.w3.org/2001/XMLSchema#anyURI"/> 98 </ResourceMatch> 99 </Resource> 100 </Resources> 101 </Target> 102 103 <!-- 104 The condition narrows down the constraints layed down in the target to 105 something more specific 106 107 The user must have at least one of the roles set - in this 108 case 'staff' 109 --> 110 <Condition> 111 <Apply FunctionId="urn:grouprole-at-least-one-member-of"> 112 <SubjectAttributeDesignator 113 AttributeId="urn:esg:attr" 114 DataType="urn:grouprole"/> 115 <Apply FunctionId="urn:grouprole-bag"> 116 <AttributeValue DataType="urn:grouprole"> 117 <esg:groupRole> 118 <esg:group>ACME</esg:group> 119 <esg:role>PrincipalInvestigator</esg:role> 120 </esg:groupRole> 121 </AttributeValue> 122 <AttributeValue DataType="urn:grouprole"> 123 <esg:groupRole> 124 <esg:group>Staff</esg:group> 125 <esg:role>Administrator</esg:role> 126 </esg:groupRole> 127 </AttributeValue> 128 </Apply> 129 </Apply> 130 </Condition> 131 </Rule> 85 132 </Policy> -
TI12-security/trunk/ndg_xacml/ndg/xacml/test/ndg1.xml
r7445 r7682 131 131 <!-- Pattern match the request URI --> 132 132 <ResourceMatch MatchId="urn:oasis:names:tc:xacml:2.0:function:anyURI-regexp-match"> 133 <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#anyURI">^http://localhost/at-least-o f-subject-role-restricted.*$</AttributeValue>133 <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#anyURI">^http://localhost/at-least-one-of-subject-role-restricted.*$</AttributeValue> 134 134 <ResourceAttributeDesignator 135 135 AttributeId="urn:oasis:names:tc:xacml:1.0:resource:resource-id" -
TI12-security/trunk/ndg_xacml/ndg/xacml/test/policy/test_policy.py
r7666 r7682 17 17 18 18 from ndg.xacml.core.policy import Policy 19 from ndg.xacml.core.functions import functionMap 19 20 from ndg.xacml.core.attributedesignator import SubjectAttributeDesignator 20 21 from ndg.xacml.core.attributeselector import AttributeSelector … … 26 27 from ndg.xacml.test import (XACML_NDGTEST1_FILEPATH, THIS_DIR, 27 28 GroupRoleAttributeValue, 28 ETreeGroupRoleDataTypeReader) 29 ETreeGroupRoleDataTypeReader, 30 GroupRoleBag, 31 GroupRoleAtLeastOneMemberOf) 29 32 30 33 … … 275 278 ETreeGroupRoleDataTypeReader) 276 279 280 # Add extra matching and bag functions 281 functionMap['urn:grouprole-bag'] = GroupRoleBag 282 functionMap['urn:grouprole-at-least-one-member-of' 283 ] = GroupRoleAtLeastOneMemberOf 284 277 285 PolicyReader = ReaderFactory.getReader(Policy) 278 286 policy = PolicyReader.parse(self.__class__.XACML_ESGFTEST1_FILEPATH)
Note: See TracChangeset
for help on using the changeset viewer.