Changeset 6731
- Timestamp:
- 16/03/10 10:45:01 (11 years ago)
- Location:
- TI12-security/trunk/NDGSecurity/python
- Files:
-
- 10 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
TI12-security/trunk/NDGSecurity/python/ndg_security_common/ndg/security/common/authz/xacml/environment.py
r6643 r6731 9 9 10 10 class Environment(RequestPropertyBase): 11 MATCH_TYPE = Envi ornmentMatch11 MATCH_TYPE = EnvironmentMatch 12 12 ELEMENT_LOCAL_NAME = 'Environment' 13 13 -
TI12-security/trunk/NDGSecurity/python/ndg_security_common/ndg/security/common/authz/xacml/etree/__init__.py
r6730 r6731 1 from xml.etree import ElementTree 2 1 3 # Generic ElementTree Helper classes 2 4 class QName(ElementTree.QName): -
TI12-security/trunk/NDGSecurity/python/ndg_security_common/ndg/security/common/authz/xacml/etree/reader.py
r6730 r6731 6 6 import logging 7 7 log = logging.getLogger(__name__) 8 from abc import ABCMeta, abstractmethod 8 9 9 10 from xml.etree import ElementTree 10 11 11 from ndg.security.common.authz.xacml import PolicyComponent, XMLParseError12 from ndg.security.common.authz.xacml.policy import Policy13 from ndg.security.common.authz.xacml.etree import QName14 12 15 16 class AbstractReader(object): 17 """ElementTree implementation of XACML reader"""18 13 class AbstractReader: 14 """Abstract base class for ElementTree implementation of XACML reader""" 15 __metaclass__ = ABCMeta 16 19 17 def __init__(self): 20 18 self.__namespace_map_backup = ElementTree._namespace_map.copy() … … 25 23 ElementTree._namespace_map = self.__namespace_map_backup 26 24 25 @classmethod 26 def __subclasshook__(cls, C): 27 """Derived class must implement __call__""" 28 if cls is AbstractReader: 29 if any("__call__" in B.__dict__ for B in C.__mro__): 30 return True 31 32 return NotImplemented 33 34 @abstractmethod 27 35 def __call__(self, obj): 28 36 """Abstract Parse XACML method … … 31 39 raise NotImplementedError() 32 40 33 def _parse(self, obj): 41 @classmethod 42 def parse(cls, obj): 43 """Parse from input object and return new XACML object""" 44 reader = cls() 45 return reader(obj) 46 47 @staticmethod 48 def _parse(obj): 34 49 """Parse helper method 35 50 @param obj: input object to parse … … 45 60 46 61 return elem 62 47 63 48 49 class PolicyReader(AbstractReader): 50 """Parse a Polciy Document using ElementTree 51 """ 64 class RuleReader(object): 52 65 def __call__(self, obj): 53 """Parse policy object""" 54 elem = self._parse(obj) 55 56 policy = Policy() 57 cls = Policy 58 59 localName = QName.getLocalPart(elem.tag) 60 if localName != cls.DEFAULT_ELEMENT_LOCAL_NAME: 61 raise XMLParseError("No \"%s\" element found" % 62 cls.DEFAULT_ELEMENT_LOCAL_NAME) 63 64 # Unpack attributes from top-level element 65 attributeValues = [] 66 for attributeName in (cls.POLICY_ID_ATTRIB_NAME, 67 cls.RULE_COMBINING_ALG_ID_ATTRIB_NAME): 68 attributeValue = elem.attrib.get(attributeName) 69 if attributeValue is None: 70 raise XMLParseError('No "%s" attribute found in "%s" ' 71 'element' % 72 (attributeName, 73 cls.DEFAULT_ELEMENT_LOCAL_NAME)) 74 75 attributeValues.append(attributeValue) 76 77 # Parse element attributes 78 policy.id, policy.ruleCombiningAlg = attributeValues 79 80 # Parse sub-elements 81 for childElem in elem: 82 localName = QName.getLocalPart(childElem.tag) 83 84 if localName == cls.DESCRIPTION_LOCALNAME: 85 policy.description = 86 elif localName == cls.TARGET_LOCALNAME: 87 pass 88 else: 89 raise XMLParseError("XACML Policy child element name %r not " 90 "recognised" % localName) 66 pass 91 67 92 93 return policy 68 #AbstractReader.register(RuleReader) 69 70 class VariableDefinitionReader(object): 71 def __call__(self, obj): 72 pass -
TI12-security/trunk/NDGSecurity/python/ndg_security_common/ndg/security/common/authz/xacml/policy.py
r6730 r6731 40 40 class Policy(PolicyComponent): 41 41 """NDG MSI Policy.""" 42 DEFAULT_XACML_VERSION = "1.0" 43 ELEMENT_LOCAL_NAME = "Policy" 42 44 POLICY_ID_ATTRIB_NAME = "PolicyId" 43 45 RULE_COMBINING_ALG_ID_ATTRIB_NAME = "RuleCombiningAlgId" 44 45 DESCRIPTION_LOCALNAME = "Description" 46 TARGET_LOCALNAME = "Target" 47 POLICY_DEFAULTS_LOCALNAME = "PolicyDefaults" 48 OBLIGATIONS_LOCALNAME = "Obligations" 49 RULE_LOCALNAME = "Rule" 46 VERSION_ATTRIB_NAME = "Version" 47 48 DESCRIPTION_LOCAL_NAME = "Description" 49 POLICY_DEFAULTS_LOCAL_NAME = "PolicyDefaults" 50 COMBINER_PARAMETERS_LOCAL_NAME = "CombinerParameters" 51 RULE_COMBINER_PARAMETERS_LOCAL_NAME = "RuleCombinerParameters" 52 OBLIGATIONS_LOCAL_NAME = "Obligations" 50 53 51 54 # Plan to support permit overrides in a future release -
TI12-security/trunk/NDGSecurity/python/ndg_security_common/ndg/security/common/authz/xacml/resource.py
r6643 r6731 4 4 @author: pjkersha 5 5 ''' 6 from ndg.security.common.authz.xacml import PolicyComponent6 from ndg.security.common.authz.xacml import RequestPropertyBase 7 7 from ndg.security.common.authz.xacml.match import ResourceMatch 8 8 -
TI12-security/trunk/NDGSecurity/python/ndg_security_common/ndg/security/common/authz/xacml/subject.py
r6643 r6731 4 4 @author: pjkersha 5 5 ''' 6 from ndg.security.common.authz.xacml import PolicyComponent6 from ndg.security.common.authz.xacml import RequestPropertyBase 7 7 from ndg.security.common.authz.xacml.match import SubjectMatch 8 8 -
TI12-security/trunk/NDGSecurity/python/ndg_security_common/ndg/security/common/authz/xacml/target.py
r6643 r6731 13 13 14 14 class Target(PolicyComponent): 15 ELEMENT_LOCAL_NAME = "Target" 16 15 17 __slots__ = ('__actions', '_resources', '__actions', '__environments') 16 18
Note: See TracChangeset
for help on using the changeset viewer.