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

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI12-security/trunk/ndg_xacml/ndg/xacml/core/functions/v1/equal.py@7087
Revision 7087, 3.2 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 equal function module - contains classes to represent XACML 1.0
2*-equal functions
3
4NERC DataGrid
5"""
6__author__ = "P J Kershaw"
7__date__ = "26/03/10"
8__copyright__ = ""
9__license__ = "BSD - see LICENSE file in top-level directory"
10__contact__ = "Philip.Kershaw@stfc.ac.uk"
11__revision__ = '$Id$'
12from ndg.xacml.core.context.exceptions import XacmlContextTypeError
13from ndg.xacml.core.functions import AbstractFunction, FunctionClassFactoryBase
14
15
16class EqualBase(AbstractFunction):
17    """Generic equal function for all types
18   
19    @cvar TYPE: attribute type for the given implementation.  Derived classes
20    should set appropriately
21    @type TYPE: NoneType
22    """
23    TYPE = None
24   
25    def evaluate(self, string1, string2):
26        """Match input strings
27       
28        @param string1: first of two strings to match
29        @type string1: basestring
30        @param string2: second string
31        @type string2: basestring
32        @return: True if strings match, False otherwise
33        @rtype: bool
34        """
35        if not isinstance(string1, basestring):
36            raise XacmlContextTypeError('Expecting %r derived type for '
37                                        '"string1"; got %r' %
38                                        (self.__class__.TYPE, 
39                                         type(string1)))
40           
41        if not isinstance(string2, self.__class__.TYPE):
42            raise XacmlContextTypeError('Expecting %r derived type for '
43                                        '"string2"; got %r' %
44                                        (self.__class__.TYPE, 
45                                         type(string2)))
46           
47        return string1 == string2
48   
49
50class FunctionClassFactory(FunctionClassFactoryBase):
51    """Class Factory for *-equal XACML function classes
52   
53    @cvar FUNCTION_NAMES: equal function URNs
54    @type FUNCTION_NAMES: tuple
55   
56    @cvar FUNCTION_NS_SUFFIX: generic suffix for equal function URNs
57    @type FUNCTION_NS_SUFFIX: string
58   
59    @cvar FUNCTION_BASE_CLASS: base class for all equal function classes
60    @type FUNCTION_BASE_CLASS: ndg.xacml.core.functions.v1.EqualBase
61    """
62    FUNCTION_NAMES = (
63        'urn:oasis:names:tc:xacml:1.0:function:string-equal',
64        'urn:oasis:names:tc:xacml:1.0:function:boolean-equal',
65        'urn:oasis:names:tc:xacml:1.0:function:integer-equal',
66        'urn:oasis:names:tc:xacml:1.0:function:double-equal',
67        'urn:oasis:names:tc:xacml:1.0:function:date-equal',
68        'urn:oasis:names:tc:xacml:1.0:function:time-equal',
69        'urn:oasis:names:tc:xacml:1.0:function:dateTime-equal',
70        'urn:oasis:names:tc:xacml:1.0:function:dayTimeDuration-equal',
71        'urn:oasis:names:tc:xacml:1.0:function:yearMonthDuration-equal',
72        'urn:oasis:names:tc:xacml:1.0:function:anyURI-equal',
73        'urn:oasis:names:tc:xacml:1.0:function:x500Name-equal',
74        'urn:oasis:names:tc:xacml:1.0:function:rfc822Name-equal',
75        'urn:oasis:names:tc:xacml:1.0:function:hexBinary-equal',
76        'urn:oasis:names:tc:xacml:1.0:function:base64Binary-equal',
77        'urn:oasis:names:tc:xacml:1.0:function:xpath-node-equal'
78    )
79    FUNCTION_NS_SUFFIX = '-equal'
80    FUNCTION_BASE_CLASS = EqualBase
Note: See TracBrowser for help on using the repository browser.