source: TI12-security/trunk/NDGSecurity/python/ndg_security_common/ndg/security/common/authz/xacml/parsers/etree/targetreader.py @ 6734

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI12-security/trunk/NDGSecurity/python/ndg_security_common/ndg/security/common/authz/xacml/parsers/etree/targetreader.py@6734
Revision 6734, 2.3 KB checked in by pjkersha, 11 years ago (diff)

Added XACML Target ElementTree based parser.

Line 
1"""NDG Security XACML ElementTree based Target 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.security.common.authz.xacml import XMLParseError
13from ndg.security.common.authz.xacml.target import Target
14from ndg.security.common.authz.xacml.action import Action
15from ndg.security.common.authz.xacml.resource import Resource
16from ndg.security.common.authz.xacml.subject import Subject
17from ndg.security.common.authz.xacml.environment import Environment
18from ndg.security.common.authz.xacml.parsers.etree import QName
19from ndg.security.common.authz.xacml.parsers.etree.reader import \
20    EtreeAbstractReader
21
22
23class TargetReader(EtreeAbstractReader):
24    """ElementTree based parser for XACML Target elements"""
25   
26    def __call__(self, obj):
27        elem = super(TargetReader, self)._parse(obj)
28       
29        target = Target()
30        cls = Target
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 sub-elements
38        for childElem in elem:
39            localName = QName.getLocalPart(childElem.tag)
40           
41            if localName == Subject.ELEMENT_LOCAL_NAME:
42                target.subjects.append(SubjectReader.parse(childElem))
43                               
44            elif localName == Resource.ELEMENT_LOCAL_NAME:
45                target.resources.append(ResourceReader.parse(childElem))
46               
47            elif localName == Action.ELEMENT_LOCAL_NAME:
48                target.actions.append(ActionReader.parse(childElem))
49               
50            elif localName == Environment.ELEMENT_LOCAL_NAME:
51                target.environments.append(EnvironmentReader.parse(childElem))
52               
53            else:
54                raise XMLParseError("XACML Target child element name %r not "
55                                    "recognised" % localName)     
56               
57        return target
Note: See TracBrowser for help on using the repository browser.