source: TI12-security/trunk/NDG_XACML/ndg/xacml/core/functions/v1/and.py @ 7064

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

Incomplete - task 2: XACML-Security Integration

  • added and and function and placeholders fro xpath-node-* functions
Line 
1"""NDG XACML one and only functions module
2
3NERC DataGrid Project
4"""
5__author__ = "P J Kershaw"
6__date__ = "01/04/10"
7__copyright__ = ""
8__license__ = "BSD - see LICENSE file in top-level directory"
9__contact__ = "Philip.Kershaw@stfc.ac.uk"
10__revision__ = '$Id: $'
11from ndg.xacml.core.functions import (AbstractFunction, 
12                                      FunctionClassFactoryInterface)
13from ndg.xacml.core.context.exceptions import XacmlContextTypeError
14from ndg.xacml.utils import TypedList as Bag
15
16
17class And(AbstractFunction):
18    """Base class for XACML <type>-and functions"""
19    FUNCTION_NS = AbstractFunction.V1_0_FUNCTION_NS + 'and'
20    BAG_TYPE = bool
21   
22    def evaluate(self, bag):
23        """perform AND function on the elements in the bag ref.
24       
25        access_control-xacml-2.0-core-spec-os, Fe 2005 - A.3.5 Logical functions
26       
27        @param bag: bag containing elements to be AND'ed
28        @rtype: bool
29        """
30        if not isinstance(bag, Bag):
31            raise XacmlContextTypeError('Expecting %r derived type for "bag"; '
32                                    'got %r' % (Bag, type(bag)))
33           
34        if bag.elementType != self.__class__.BAG_TYPE:
35            raise XacmlContextTypeError('Expecting %r type elements for "bag"; '
36                                        'got %r' %
37                                        (self.__class__.BAG_TYPE, 
38                                         bag.elementType))
39                       
40        nBagElems = len(bag)
41        if nBagElems == 0:
42            return True
43        else:
44            for elem in bag:
45                if not elem:
46                    return False
47           
48        return True
49
50   
51class FunctionClassFactory(FunctionClassFactoryInterface):
52    """Class Factory for and XACML function class
53    """
54    def __call__(self, identifier):
55        '''Create class for the And XACML function identifier
56       
57        @param identifier: XACML and function identifier
58        @type identifier: basestring
59        @return: and function class or None if identifier doesn't match
60        @rtype: ndg.xacml.core.functions.v1.and.And / NoneType
61        '''
62        if identifier == And.FUNCTION_NS:
63            return And
64        else:
65            return None
Note: See TracBrowser for help on using the repository browser.