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

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

Incomplete - task 2: XACML-Security Integration

  • updating epydoc ready for release.
Line 
1"""NDG XACML one and only functions module
2
3NERC DataGrid
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   
20    @cvar FUNCTION_NS: namespace for this function
21    @type FUNCTION_NS: string
22    @cvar BAG_TYPE: type for
23    @type BAG_TYPE:
24    """
25    FUNCTION_NS = AbstractFunction.V1_0_FUNCTION_NS + 'and'
26    BAG_TYPE = bool
27   
28    def evaluate(self, bag):
29        """perform AND function on the elements in the bag ref.
30       
31        access_control-xacml-2.0-core-spec-os, Fe 2005 - A.3.5 Logical functions
32       
33        @param bag: bag containing elements to be AND'ed
34        @type bag: ndg.xacml.utils.TypedList
35       
36        @return: result of AND operation on the inputs
37        @rtype: bool
38        """
39        if not isinstance(bag, Bag):
40            raise XacmlContextTypeError('Expecting %r derived type for "bag"; '
41                                    'got %r' % (Bag, type(bag)))
42           
43        if bag.elementType != self.__class__.BAG_TYPE:
44            raise XacmlContextTypeError('Expecting %r type elements for "bag"; '
45                                        'got %r' %
46                                        (self.__class__.BAG_TYPE, 
47                                         bag.elementType))
48                       
49        nBagElems = len(bag)
50        if nBagElems == 0:
51            return True
52        else:
53            for elem in bag:
54                if not elem:
55                    return False
56           
57        return True
58
59   
60class FunctionClassFactory(FunctionClassFactoryInterface):
61    """Class Factory for and XACML function class
62   
63    @cvar FUNCTION_NS: URN for and function
64    @type FUNCTION_NS: string
65    """
66    FUNCTION_NS = 'urn:oasis:names:tc:xacml:1.0:function:and'
67   
68    def __call__(self, identifier):
69        '''Create class for the And XACML function identifier
70       
71        @param identifier: XACML and function identifier
72        @type identifier: basestring
73        @return: and function class or None if identifier doesn't match
74        @rtype: ndg.xacml.core.functions.v1.and.And / NoneType
75        '''
76        if identifier == And.FUNCTION_NS:
77            return And
78        else:
79            return None
Note: See TracBrowser for help on using the repository browser.