source: TI12-security/trunk/ndg_xacml/ndg/xacml/core/condition.py @ 7101

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg-security/TI12-security/trunk/ndg_xacml/ndg/xacml/core/condition.py@7108
Revision 7101, 2.3 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 Condition type definition
2
3NERC DataGrid
4"""
5__author__ = "P J Kershaw"
6__date__ = "25/02/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 import XacmlCoreBase
13from ndg.xacml.core.expression import Expression
14
15
16class Condition(XacmlCoreBase):
17    """XACML 2.0 Rule Condition Note the difference to XACML 1.0: the Condition
18    element is its own type and not an Apply type.  It expects a single
19    Expression derived type child element
20
21    @cvar ELEMENT_LOCAL_NAME: XML local name for this element
22    @type ELEMENT_LOCAL_NAME: string
23
24    @cvar APPLY_ELEMENT_LOCAL_NAME: XML local name for the apply element
25    @type APPLY_ELEMENT_LOCAL_NAME: string
26
27    @ivar __expression: expression in this condition
28    @type __expression: ndg.xacml.core.expression.Expression
29    """
30    ELEMENT_LOCAL_NAME = 'Condition'
31    APPLY_ELEMENT_LOCAL_NAME = 'Apply'
32   
33    __slots__ = ('__expression', )
34   
35    def __init__(self):
36        super(Condition, self).__init__()
37        self.__expression = None
38       
39    @property
40    def expression(self):
41        """Get expression
42       
43        @return: expression for this condition
44        @rtype: ndg.xacml.core.expression.Expression / NoneType
45        """
46        return self.__expression
47       
48    @expression.setter
49    def expression(self, value):
50        """Set expression
51       
52        @param value: expression for this condition
53        @type value: ndg.xacml.core.expression.Expression
54        @raise TypeError: incorrect input type set
55        """
56        if not isinstance(value, Expression):
57            raise TypeError('Expecting Expression or Expression derived type '
58                            'for "expression" attribute; got %r' %
59                            type(value))
60        self.__expression = value
61   
62    def evaluate(self, context):
63        """Evaluate this rule condition
64        @param context: the request context
65        @type context: ndg.xacml.core.request.Request
66        @return: True/False status for whether the rule condition matched or
67        not
68        @rtype: bool
69        """
70        result = self.expression.evaluate(context)
71       
72        return result
Note: See TracBrowser for help on using the repository browser.