source: TI12-security/trunk/ndg_xacml/ndg/xacml/parsers/etree/targetchildreader.py @ 7087

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

Incomplete - task 2: XACML-Security Integration

  • updating epydoc ready for release.
  • Property svn:keywords set to Id
Line 
1"""NDG XACML ElementTree based Generic Target Child Element reader - for
2Reosurce, Subject, Action and Environment
3
4NERC DataGrid
5"""
6__author__ = "P J Kershaw"
7__date__ = "18/03/10"
8__copyright__ = "(C) 2010 Science and Technology Facilities Council"
9__contact__ = "Philip.Kershaw@stfc.ac.uk"
10__license__ = "BSD - see LICENSE file in top-level directory"
11__contact__ = "Philip.Kershaw@stfc.ac.uk"
12__revision__ = "$Id$"
13from ndg.xacml.core.subject import Subject
14from ndg.xacml.parsers import XMLParseError
15from ndg.xacml.parsers.etree import QName
16from ndg.xacml.parsers.etree.reader import ETreeAbstractReader
17from ndg.xacml.parsers.etree.factory import ReaderFactory
18
19
20class TargetChildReader(ETreeAbstractReader):
21    '''ElementTree based XACML generic target child element parser
22    @cvar TYPE: XACML type to instantiate from parsed object
23    @type string: type
24    '''
25
26    def __call__(self, obj):
27        """Parse subject object"""
28        elem = super(TargetChildReader, self)._parse(obj)
29       
30        xacmlType = self.__class__.TYPE
31        targetChild = xacmlType()
32       
33        localName = QName.getLocalPart(elem.tag)
34        if localName != xacmlType.ELEMENT_LOCAL_NAME:
35            raise XMLParseError("No \"%s\" element found" % 
36                                xacmlType.ELEMENT_LOCAL_NAME)
37           
38        # Parse match elements
39        for childElem in elem:
40            localName = QName.getLocalPart(childElem.tag)
41           
42            if localName == xacmlType.MATCH_TYPE.ELEMENT_LOCAL_NAME:
43                # Get reader for the match type
44                matchReader = ReaderFactory.getReader(xacmlType.MATCH_TYPE)
45                targetChild.matches.append(matchReader.parse(childElem))
46           
47            else:
48                raise XMLParseError("XACML %r child element name %r not "
49                                    "recognised" % (xacmlType.ELEMENT_LOCAL_NAME, 
50                                                    localName))
51                       
52        return targetChild
Note: See TracBrowser for help on using the repository browser.