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

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg-security/TI12-security/trunk/ndg_xacml/ndg/xacml/parsers/etree/conditionreader.py@7087
Revision 7087, 2.2 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 Target Element reader
2
3NERC DataGrid
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.condition import Condition
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.applyreader import ApplyReader
17
18
19class ConditionReader(ETreeAbstractReader):
20    '''ElementTree based XACML 2.0 Condition parser.  Note the difference to
21    XACML 1.0: the Condition element is its own type and not an Apply type.
22    It expects a single Expression derived type child element
23   
24    @cvar TYPE: XACML type to instantiate from parsed object
25    @type string: type
26    '''
27    TYPE = Condition
28   
29    def __call__(self, obj):
30        """Parse policy object"""
31        elem = super(ConditionReader, self)._parse(obj)
32       
33        xacmlType = self.__class__.TYPE
34        condition = xacmlType()
35       
36        localName = QName.getLocalPart(elem.tag)
37        if localName != xacmlType.ELEMENT_LOCAL_NAME:
38            raise XMLParseError("No \"%s\" element found" % 
39                                xacmlType.ELEMENT_LOCAL_NAME)
40           
41        # Parse expression sub-element
42        nSubElem = len(elem)
43        if nSubElem != 1:
44            raise XMLParseError('XACML 2.0 policy schema expects only one '
45                                'expression sub-element in the Condition '
46                                'element; policy file has %d' % nSubElem)
47       
48        subElemlocalName = QName.getLocalPart(elem[0].tag)
49        if subElemlocalName == xacmlType.APPLY_ELEMENT_LOCAL_NAME:
50            condition.expression = ApplyReader.parse(elem[0])
51        else:
52            raise XMLParseError('Expecting %r Condition sub-element not '
53                                'recognised' %
54                                xacmlType.EXPRESSION_ELEMENT_LOCAL_NAME)
55           
56       
57   
58        return condition
Note: See TracBrowser for help on using the repository browser.