source: TI12-security/trunk/NDG_XACML/ndg/xacml/core/condition.py @ 6806

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI12-security/trunk/NDG_XACML/ndg/xacml/core/condition.py@6806
Revision 6806, 1.7 KB checked in by pjkersha, 10 years ago (diff)

Moving matching and rule evaluation code out of the PDP class and into the relevant classes they pertain to e.g. target matching moved to Target class match method and so on.

Line 
1"""NDG Security Condition type definition
2
3NERC DataGrid Project
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    ELEMENT_LOCAL_NAME = 'Condition'
22    APPLY_ELEMENT_LOCAL_NAME = 'Apply'
23   
24    __slots__ = ('__expression', )
25   
26    def __init__(self):
27        super(Condition, self).__init__()
28        self.__expression = None
29       
30    @property
31    def expression(self):
32        return self.__expression
33   
34    @expression.setter
35    def expression(self, value):
36        if not isinstance(value, Expression):
37            raise TypeError('Expecting Expression or Expression derived type '
38                            'for "expression" attribute; got %r' %
39                            type(value))
40        self.__expression = value
41   
42    def evaluate(self, context):
43        """Evaluate this rule condition
44        @param context: the request context
45        @type context: ndg.xacml.core.request.Request
46        @return: True/False status for whether the rule condition matched or
47        not
48        @rtype: bool
49        """
50        result = self.expression.evaluate(context)
51       
52        return result
Note: See TracBrowser for help on using the repository browser.