source: TI12-security/trunk/NDG_XACML/ndg/xacml/core/match.py @ 6774

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI12-security/trunk/NDG_XACML/ndg/xacml/core/match.py@6793
Revision 6774, 3.6 KB checked in by pjkersha, 10 years ago (diff)

Work on test PDP currently in unittests but will be moved into context package.

Line 
1"""NDG Security Match type definition
2
3NERC DataGrid Project
4"""
5__author__ = "P J Kershaw"
6__date__ = "25/02/10"
7__copyright__ = "(C) 2010 Science and Technology Facilities Council"
8__contact__ = "Philip.Kershaw@stfc.ac.uk"
9__license__ = "BSD - see LICENSE file in top-level directory"
10__contact__ = "Philip.Kershaw@stfc.ac.uk"
11__revision__ = "$Id: $"
12from ndg.xacml.core import XacmlCoreBase
13from ndg.xacml.core.attributedesignator import AttributeDesignator
14from ndg.xacml.core.attributeselector import AttributeSelector
15from ndg.xacml.core.attributevalue import AttributeValue
16
17
18class MatchBase(XacmlCoreBase):
19    ELEMENT_LOCAL_NAME = None
20    MATCH_ID_ATTRIB_NAME = 'MatchId'
21    ATTRIBUTE_VALUE_ELEMENT_LOCAL_NAME = 'AttributeValue'
22
23    __slots__ = (
24        '__attributeValue', 
25        '__attributeDesignator', 
26        '__attributeSelector',
27        '__matchId'
28    )
29   
30    def __init__(self):
31        self.__attributeValue = None
32         
33        # Either/or in schema
34        self.__attributeDesignator = None
35        self.__attributeSelector = None
36       
37        self.__matchId = None
38
39
40    @property
41    def attributeDesignator(self):
42        return self.__attributeDesignator
43   
44    @attributeDesignator.setter
45    def attributeDesignator(self, value):
46        """Set match attribute designator.  Match may have an
47        attributeDesignator or an attributeSelector setting a designator DELETES
48        any attributeSelector previously set
49        """
50        if not isinstance(value, AttributeDesignator):
51            raise TypeError('Expecting %r type for "attributeDesignator" '
52                            'attribute; got %r' % 
53                            (AttributeDesignator, type(value)))
54           
55        self.__attributeDesignator = value
56        self.__attributeSelector = None
57 
58    @property
59    def attributeSelector(self):
60        return self.__attributeSelector
61   
62    @attributeSelector.setter
63    def attributeSelector(self, value):
64        """Set match attribute selector.  Match may have an
65        attributeDesignator or an attributeSelector setting a selector DELETES
66        any attributeDesignator previously set
67        """
68        if not isinstance(value, AttributeSelector):
69            raise TypeError('Expecting %r type for "matchId" '
70                            'attribute; got %r' % 
71                            (AttributeSelector, type(value)))
72           
73        self.__attributeSelector = value
74        self.__attributeDesignator = None
75                       
76    def _getMatchId(self):
77        return self.__matchId
78
79    def _setMatchId(self, value):
80        if not isinstance(value, basestring):
81            raise TypeError('Expecting string type for "matchId" '
82                            'attribute; got %r' % type(value))
83           
84        self.__matchId = value
85
86    matchId = property(_getMatchId, _setMatchId, None, "Match Id")
87   
88   
89class SubjectMatch(MatchBase):
90    "Subject Match Type"
91    ELEMENT_LOCAL_NAME = 'SubjectMatch'
92    ATTRIBUTE_DESIGNATOR_ELEMENT_LOCAL_NAME = 'SubjectAttributeDesignator'   
93   
94   
95class ResourceMatch(MatchBase):
96    "Resource Match"
97    ELEMENT_LOCAL_NAME = 'ResourceMatch'
98    ATTRIBUTE_DESIGNATOR_ELEMENT_LOCAL_NAME = 'ResourceAttributeDesignator'
99   
100   
101class ActionMatch(MatchBase):
102    "Action match"
103    ELEMENT_LOCAL_NAME = 'ActionMatch'
104    ATTRIBUTE_DESIGNATOR_ELEMENT_LOCAL_NAME = 'ActionAttributeDesignator'   
105   
106   
107class EnvironmentMatch(MatchBase):
108    "Environment Match"
109    ELEMENT_LOCAL_NAME = 'EnvironmentMatch'
110    ATTRIBUTE_DESIGNATOR_ELEMENT_LOCAL_NAME = 'EnvironmentAttributeDesignator'
Note: See TracBrowser for help on using the repository browser.