source: TI12-security/trunk/NDG_XACML/ndg/xacml/parsers/etree/subjectreader.py @ 6751

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI12-security/trunk/NDG_XACML/ndg/xacml/parsers/etree/subjectreader.py@6751
Revision 6751, 2.0 KB checked in by pjkersha, 10 years ago (diff)

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

Line 
1"""NDG XACML ElementTree based Subject Element reader
2
3NERC DataGrid Project
4"""
5__author__ = "P J Kershaw"
6__date__ = "16/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.subject import Subject
13from ndg.xacml.parsers import XMLParseError
14from ndg.xacml.parsers.etree import QName
15from ndg.xacml.parsers.etree.reader import ETreeAbstractReader
16from ndg.xacml.parsers.etree.matchreader import SubjectMatchReader
17
18
19class AbstractTargetChildReader(ETreeAbstractReader):
20    '''ElementTree based XACML generic target child element parser
21    @cvar TYPE: XACML type to instantiate from parsed object
22    @type string: type
23    '''
24
25    def __call__(self, obj):
26        """Parse subject object"""
27        elem = super(AbstractTargetChildReader, self)._parse(obj)
28       
29        cls = self.__class__.TYPE
30        targetChild = cls()
31       
32        localName = QName.getLocalPart(elem.tag)
33        if localName != cls.ELEMENT_LOCAL_NAME:
34            raise XMLParseError("No \"%s\" element found" % 
35                                cls.ELEMENT_LOCAL_NAME)
36           
37        # Parse match elements
38        for childElem in elem:
39            localName = QName.getLocalPart(childElem.tag)
40           
41            if localName == cls.MATCH_TYPE.ELEMENT_LOCAL_NAME:
42                targetChild.matches.append(self.__class__.parse(childElem))
43           
44            else:
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
Note: See TracBrowser for help on using the repository browser.