1 """NDG XACML URI equal matching function module
2
3 NERC 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: at_least_one_member_of.py 7955 2011-12-21 18:29:45Z rwilkinson $'
11 from ndg.xacml.core.functions import AbstractFunction, FunctionClassFactoryBase
12 from ndg.xacml.core.context.exceptions import XacmlContextTypeError
13 from ndg.xacml.utils import TypedList as Bag
14
15
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
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 _set1 = set([attr.value for attr in set1])
58 _set2 = set([attr.value for attr in set2])
59
60 return len(list(_set1 & _set2)) > 0
61
62
64 """Class Factory for *-at-least-one-member-of XACML function classes
65
66 @cvar FUNCTION_NAMES: list of at least one member of function URNs
67 @type FUNCTION_NAMES: tuple
68
69 @cvar FUNCTION_NS_SUFFIX: generic suffix for at least one member of function
70 URNs
71 @type FUNCTION_NS_SUFFIX: string
72
73 @cvar FUNCTION_BASE_CLASS: base class for all at least one member of
74 function classes
75 @type FUNCTION_BASE_CLASS: ndg.xacml.core.functions.v1.AtLeastOneMemberOfBase
76 """
77 FUNCTION_NAMES = (
78 'urn:oasis:names:tc:xacml:1.0:function:string-at-least-one-member-of',
79 'urn:oasis:names:tc:xacml:1.0:function:boolean-at-least-one-member-of',
80 'urn:oasis:names:tc:xacml:1.0:function:integer-at-least-one-member-of',
81 'urn:oasis:names:tc:xacml:1.0:function:double-at-least-one-member-of',
82 'urn:oasis:names:tc:xacml:1.0:function:time-at-least-one-member-of',
83 'urn:oasis:names:tc:xacml:1.0:function:date-at-least-one-member-of',
84 'urn:oasis:names:tc:xacml:1.0:function:dateTime-at-least-one-member-of',
85 'urn:oasis:names:tc:xacml:1.0:function:anyURI-at-least-one-member-of',
86 'urn:oasis:names:tc:xacml:1.0:function:hexBinary-at-least-one-member-of',
87 'urn:oasis:names:tc:xacml:1.0:function:base64Binary-at-least-one-member-of',
88 'urn:oasis:names:tc:xacml:1.0:function:dayTimeDuration-at-least-one-member-of',
89 'urn:oasis:names:tc:xacml:1.0:function:yearMonthDuration-at-least-one-member-of',
90 'urn:oasis:names:tc:xacml:1.0:function:x500Name-at-least-one-member-of',
91 'urn:oasis:names:tc:xacml:1.0:function:rfc822Name-at-least-one-member-of',
92 )
93 FUNCTION_NS_SUFFIX = '-at-least-one-member-of'
94 FUNCTION_BASE_CLASS = AtLeastOneMemberOfBase
95