Changeset 6751


Ignore:
Timestamp:
18/03/10 16:09:25 (9 years ago)
Author:
pjkersha
Message:

Working rule1 example parsing, working on rule2 which contains a target resource.

Location:
TI12-security/trunk/NDG_XACML/ndg/xacml
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • TI12-security/trunk/NDG_XACML/ndg/xacml/parsers/etree/policyreader.py

    r6750 r6751  
    6565             
    6666            if localName == cls.DESCRIPTION_LOCAL_NAME: 
    67                 if elem.text is not None: 
    68                     policy.description = elem.text.strip() 
     67                if childElem.text is not None: 
     68                    policy.description = childElem.text.strip() 
    6969                     
    7070            elif localName == cls.POLICY_DEFAULTS_LOCAL_NAME: 
  • TI12-security/trunk/NDG_XACML/ndg/xacml/parsers/etree/resourcereader.py

    r6746 r6751  
    1 ''' 
    2 Created on 16 Mar 2010 
     1"""NDG XACML ElementTree based Resource Element reader  
    32 
    4 @author: pjkersha 
    5 ''' 
    6  
    7 class ResourceReader(object): 
    8     ''' 
    9     classdocs 
    10     ''' 
     3NERC DataGrid Project 
     4""" 
     5__author__ = "P J Kershaw" 
     6__date__ = "18/03/10" 
     7__copyright__ = "(C) 2010 Science and Technology Facilities Council" 
     8__contact__ = "Philip.Kershaw@stfc.ac.uk" 
     9__license__ = "BSD - see LICENSE file in top-level directory" 
     10__contact__ = "Philip.Kershaw@stfc.ac.uk" 
     11__revision__ = "$Id: $" 
     12from ndg.xacml.core.resource import Resource 
     13from ndg.xacml.parsers.etree.subjectreader import AbstractTargetChildReader 
    1114 
    1215 
    13     def __init__(selfparams): 
    14         ''' 
    15         Constructor 
    16         ''' 
    17          
     16class ResourceReader(AbstractTargetChildReader): 
     17    '''ElementTree based XACML Rule parser 
     18    @cvar TYPE: XACML type to instantiate from parsed object 
     19    @type string: type 
     20    ''' 
     21    TYPE = Resource 
     22      
  • TI12-security/trunk/NDG_XACML/ndg/xacml/parsers/etree/rulereader.py

    r6750 r6751  
    5959             
    6060            if localName == cls.DESCRIPTION_LOCAL_NAME: 
    61                 if elem.text is not None: 
    62                     rule.description = elem.text.strip() 
     61                if childElem.text is not None: 
     62                    rule.description = childElem.text.strip() 
    6363                     
    6464            elif localName == Condition.ELEMENT_LOCAL_NAME: 
  • TI12-security/trunk/NDG_XACML/ndg/xacml/parsers/etree/subjectreader.py

    r6750 r6751  
    1717 
    1818 
    19 class SubjectReader(ETreeAbstractReader): 
    20     '''ElementTree based XACML Rule parser 
     19class AbstractTargetChildReader(ETreeAbstractReader): 
     20    '''ElementTree based XACML generic target child element parser 
    2121    @cvar TYPE: XACML type to instantiate from parsed object 
    2222    @type string: type 
    2323    ''' 
    24     TYPE = Subject 
    2524 
    2625    def __call__(self, obj): 
    2726        """Parse subject object""" 
    28         elem = super(SubjectReader, self)._parse(obj) 
     27        elem = super(AbstractTargetChildReader, self)._parse(obj) 
    2928         
    30         cls = SubjectReader.TYPE 
    31         subject = cls() 
     29        cls = self.__class__.TYPE 
     30        targetChild = cls() 
    3231         
    3332        localName = QName.getLocalPart(elem.tag) 
     
    4140             
    4241            if localName == cls.MATCH_TYPE.ELEMENT_LOCAL_NAME: 
    43                 subject.matches.append(SubjectMatchReader.parse(childElem)) 
     42                targetChild.matches.append(self.__class__.parse(childElem)) 
    4443             
    4544            else: 
    46                 raise XMLParseError("XACML Subject child element name %r not " 
    47                                     "recognised" % localName)        
    48         return subject  
     45                raise XMLParseError("XACML %r child element name %r not " 
     46                                    "recognised" % (cls.ELEMENT_LOCAL_NAME,  
     47                                                    localName)) 
     48                        
     49        return targetChild  
     50     
     51 
     52class SubjectReader(AbstractTargetChildReader): 
     53    '''ElementTree based XACML Rule parser 
     54    @cvar TYPE: XACML type to instantiate from parsed object 
     55    @type string: type 
     56    ''' 
     57    TYPE = Subject 
  • TI12-security/trunk/NDG_XACML/ndg/xacml/test/test_xacml.py

    r6750 r6751  
    1818class XACMLTestCase(unittest.TestCase): 
    1919    THIS_DIR = path.dirname(__file__) 
    20     XACML_FILENAME = "rule1.xml" 
    21     XACML_FILEPATH = path.join(THIS_DIR, XACML_FILENAME) 
    22      
     20    XACML_TEST1_FILENAME = "rule1.xml" 
     21    XACML_TEST1_FILEPATH = path.join(THIS_DIR, XACML_TEST1_FILENAME) 
     22    XACML_TEST2_FILENAME = "rule2.xml" 
     23    XACML_TEST2_FILEPATH = path.join(THIS_DIR, XACML_TEST2_FILENAME) 
     24    
    2325    def test01ETreeParseRule1Policy(self): 
    24         policy = PolicyReader.parse(XACMLTestCase.XACML_FILEPATH) 
     26        policy = PolicyReader.parse(XACMLTestCase.XACML_TEST1_FILEPATH) 
    2527        self.assert_(policy) 
    2628         
     
    4547            policy.rules[0].description) 
    4648         
    47         self.assert_(len(policy.rules[0].subjects) == 1) 
    48         self.assert_(len(policy.rules[0].actions) == 0) 
    49         self.assert_(len(policy.rules[0].resources) == 0) 
    50         self.assert_(len(policy.rules[0].environments) == 0) 
     49        self.assert_(len(policy.rules[0].target.subjects) == 1) 
     50        self.assert_(len(policy.rules[0].target.actions) == 0) 
     51        self.assert_(len(policy.rules[0].target.resources) == 0) 
     52        self.assert_(len(policy.rules[0].target.environments) == 0) 
    5153         
    52         self.assert_(len(policy.rules[0].subjects[0].subjectMatches) == 1) 
     54        self.assert_(len(policy.rules[0].target.subjects[0].subjectMatches) == 1) 
    5355         
    54         self.assert_(policy.rules[0].subjects[0].subjectMatches[0].id == \ 
    55                      "urn:oasis:names:tc:xacml:1.0:function:rfc822Name-match") 
     56        self.assert_(policy.rules[0].target.subjects[0].subjectMatches[0 
     57            ].matchId == \ 
     58            "urn:oasis:names:tc:xacml:1.0:function:rfc822Name-match") 
    5659         
    57         self.assert_(policy.rules[0].subjects[0].subjectMatches[0 
     60        self.assert_(policy.rules[0].target.subjects[0].subjectMatches[0 
    5861            ].attributeValue.dataType == \ 
    5962            "urn:oasis:names:tc:xacml:1.0:data-type:rfc822Name") 
    6063         
    61         self.assert_(policy.rules[0].subjects[0].subjectMatches[0 
     64        self.assert_(policy.rules[0].target.subjects[0].subjectMatches[0 
    6265            ].attributeDesignator.dataType == \ 
    6366            "urn:oasis:names:tc:xacml:1.0:data-type:rfc822Name") 
    6467         
    6568        # Attribute ID 
    66         self.assert_(policy.rules[0].subjects[0].subjectMatches[0 
     69        self.assert_(policy.rules[0].target.subjects[0].subjectMatches[0 
    6770            ].attributeDesignator.attributeId == \ 
    6871            "urn:oasis:names:tc:xacml:1.0:subject:subject-id") 
    69          
     72          
     73    def test02ETreeParseRule2Policy(self): 
     74        policy = PolicyReader.parse(XACMLTestCase.XACML_TEST2_FILEPATH) 
     75        self.assert_(policy) 
    7076 
    7177 
Note: See TracChangeset for help on using the changeset viewer.