Package ndg :: Package xacml :: Package core :: Package functions :: Package v1 :: Module match
[hide private]

Source Code for Module ndg.xacml.core.functions.v1.match

  1  """NDG XACML match function module - contains implementations for XACML 1.0 
  2  *-match functions 
  3   
  4  NERC 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: $' 
 12  from ndg.xacml.core.context.exceptions import XacmlContextTypeError 
 13  from ndg.xacml.core.functions import AbstractFunction, FunctionClassFactoryBase 
 14  from ndg.xacml.core.attributevalue import AttributeValueClassFactory 
 15   
 16   
17 -class MatchBase(AbstractFunction):
18 """Generic match function for all types 19 20 @cvar TYPE: attribute type for the given implementation. Derived classes 21 should set appropriately 22 @type TYPE: NoneType 23 """ 24 TYPE = None 25
26 - def evaluate(self, input1, input2):
27 """Match two inputs of type self.__class__.TYPE 28 29 @param input1: first of two inputs to match 30 @type input1: self.__class__.TYPE 31 @param input2: second input 32 @type input2: self.__class__.TYPE 33 @return: True if inputs match, False otherwise 34 @rtype: bool 35 """ 36 if not isinstance(input1, self.__class__.TYPE): 37 raise XacmlContextTypeError('Expecting %r derived type for ' 38 '"input1"; got %r' % 39 (self.__class__.TYPE, 40 type(input1))) 41 42 if not isinstance(input2, self.__class__.TYPE): 43 raise XacmlContextTypeError('Expecting %r derived type for ' 44 '"input2"; got %r' % 45 (self.__class__.TYPE, 46 type(input2))) 47 48 return input1 == input2
49 50 51 attributeValueClassFactory = AttributeValueClassFactory() 52 53
54 -class Rfc822NameMatch(AbstractFunction):
55 """Match RFC 822 type name - e.g. e-mail addresses""" 56 FUNCTION_NS = 'urn:oasis:names:tc:xacml:1.0:function:rfc822Name-match' 57 TYPE = attributeValueClassFactory( 58 'http://www.w3.org/2001/XMLSchema#Rfc822Name') 59 STRING_TYPE = attributeValueClassFactory( 60 'http://www.w3.org/2001/XMLSchema#string') 61
62 - def evaluate(self, string1, rfc822Name):
63 """Match Rfc822 name 64 65 @param string1: string to match to rfc822Name 66 @type string1: basestring 67 @param rfc822Name: RFC822 Name to match 68 @type rfc822Name: basestring 69 @return: True if strings match, False otherwise 70 @rtype: bool 71 """ 72 if not isinstance(string1, self.__class__.STRING_TYPE): 73 raise TypeError('Expecting %r derived type for "string1"; got %r' % 74 (self.__class__.STRING_TYPE, type(string1))) 75 76 if not isinstance(rfc822Name, self.__class__.TYPE): 77 raise TypeError('Expecting %r derived type for "rfc822Name"; got ' 78 '%r' % (self.__class__.TYPE, type(rfc822Name))) 79 80 return string1.lower() == rfc822Name.lower()
81 82
83 -class FunctionClassFactory(FunctionClassFactoryBase):
84 """Class Factory for *-match XACML 1.0 function classes 85 86 @cvar FUNCTION_NAMES: equal function URNs 87 @type FUNCTION_NAMES: tuple 88 89 @cvar FUNCTION_NS_SUFFIX: generic suffix for match function URNs 90 @type FUNCTION_NS_SUFFIX: string 91 92 @cvar FUNCTION_BASE_CLASS: base class for all match function classes (apart 93 from Rfc822NameMatch) 94 @type FUNCTION_BASE_CLASS: ndg.xacml.core.functions.v1.MatchBase 95 """ 96 FUNCTION_NAMES = ( 97 'urn:oasis:names:tc:xacml:1.0:function:x500Name-match', 98 'urn:oasis:names:tc:xacml:1.0:function:rfc822Name-match', 99 'urn:oasis:names:tc:xacml:1.0:function:xpath-node-match' 100 ) 101 FUNCTION_NS_SUFFIX = '-match' 102 FUNCTION_BASE_CLASS = MatchBase
103