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

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

Incomplete - task 2: XACML-Security Integration

  • updating epydoc ready for release.
  • Property svn:keywords set to Id
Line 
1"""NDG XACML URI equal matching function module
2
3NERC DataGrid
4"""
5__author__ = "P J Kershaw"
6__date__ = "30/03/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, FunctionClassFactoryBase
12from ndg.xacml.core.context.exceptions import XacmlContextTypeError
13from ndg.xacml.utils import TypedList as Bag
14
15
16class AtLeastOneMemberOfBase(AbstractFunction):
17    """Base class implementation for at least one member of XACML function -
18    check at least one item in one set is contained in the second set
19   
20    urn:oasis:names:tc:xacml:1.0:function:<type>-at-least-one-member-of
21   
22    @cvar TYPE: attribute type for the given implementation.  Derived classes
23    should set appropriately
24    @type TYPE: NoneType
25    """
26    TYPE = None
27   
28    def evaluate(self, set1, set2):
29        """Check input is contained in the bag
30       
31        @param set1: check to see if at least one item in this set is contained
32        in the second set
33        @type set1: TypedList(self.__class__.TYPE)
34        @param set2: bag of self.__class__.TYPE values
35        @type set2: TypedList(self.__class__.TYPE)
36        @return: True if str is in bag, False otherwise
37        @rtype: bool
38        """
39        if not isinstance(set1, Bag):
40            raise XacmlContextTypeError('Expecting %r derived type for "set1"; '
41                                        'got %r' % (Bag, type(set1)))
42           
43        if set1.elementType != self.__class__.TYPE:
44            raise XacmlContextTypeError('Expecting %r type elements for '
45                                        '"set1"; got %r' %
46                                        (self.__class__.TYPE, set1.elementType))
47           
48        if not isinstance(set2, Bag):
49            raise XacmlContextTypeError('Expecting %r derived type for "set2"; '
50                                        'got %r' % (Bag, type(set2)))
51           
52        if set2.elementType != self.__class__.TYPE:
53            raise XacmlContextTypeError('Expecting %r type elements for '
54                                        '"set2"; got %r' %
55                                        (self.__class__.TYPE, set2.elementType))
56       
57        set2Values = [attr.value for attr in set2]
58        for i in set1:
59            if i.value in set2Values:
60                return True
61           
62        return False
63   
64
65class FunctionClassFactory(FunctionClassFactoryBase):
66    """Class Factory for *-at-least-one-member-of XACML function classes
67   
68    @cvar FUNCTION_NAMES: list of at least one member of function URNs
69    @type FUNCTION_NAMES: tuple
70   
71    @cvar FUNCTION_NS_SUFFIX: generic suffix for at least one member of function
72    URNs
73    @type FUNCTION_NS_SUFFIX: string
74   
75    @cvar FUNCTION_BASE_CLASS: base class for all at least one member of
76    function classes
77    @type FUNCTION_BASE_CLASS: ndg.xacml.core.functions.v1.AtLeastOneMemberOfBase
78    """
79    FUNCTION_NAMES = (
80'urn:oasis:names:tc:xacml:1.0:function:string-at-least-one-member-of',
81'urn:oasis:names:tc:xacml:1.0:function:boolean-at-least-one-member-of',
82'urn:oasis:names:tc:xacml:1.0:function:integer-at-least-one-member-of',
83'urn:oasis:names:tc:xacml:1.0:function:double-at-least-one-member-of',
84'urn:oasis:names:tc:xacml:1.0:function:time-at-least-one-member-of',
85'urn:oasis:names:tc:xacml:1.0:function:date-at-least-one-member-of',
86'urn:oasis:names:tc:xacml:1.0:function:dateTime-at-least-one-member-of',
87'urn:oasis:names:tc:xacml:1.0:function:anyURI-at-least-one-member-of',
88'urn:oasis:names:tc:xacml:1.0:function:hexBinary-at-least-one-member-of',
89'urn:oasis:names:tc:xacml:1.0:function:base64Binary-at-least-one-member-of',
90'urn:oasis:names:tc:xacml:1.0:function:dayTimeDuration-at-least-one-member-of',
91'urn:oasis:names:tc:xacml:1.0:function:yearMonthDuration-at-least-one-member-of',
92'urn:oasis:names:tc:xacml:1.0:function:x500Name-at-least-one-member-of',
93'urn:oasis:names:tc:xacml:1.0:function:rfc822Name-at-least-one-member-of',
94    )
95    FUNCTION_NS_SUFFIX = '-at-least-one-member-of'
96    FUNCTION_BASE_CLASS = AtLeastOneMemberOfBase
Note: See TracBrowser for help on using the repository browser.