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

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

Added Context Handler and Attribute classes.

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        if not isinstance(value, AttributeDesignator):
47            raise TypeError('Expecting %r type for "attributeDesignator" '
48                            'attribute; got %r' % 
49                            (AttributeDesignator, type(value)))
50           
51        self.__attributeDesignator = value
52 
53    @property
54    def attributeSelector(self):
55        return self.__attributeSelector
56   
57    @attributeSelector.setter
58    def attributeSelector(self, value):
59        if not isinstance(value, AttributeSelector):
60            raise TypeError('Expecting %r type for "matchId" '
61                            'attribute; got %r' % 
62                            (AttributeSelector, type(value)))
63           
64        self.__attributeSelector = value
65                       
66    def _getMatchId(self):
67        return self.__matchId
68
69    def _setMatchId(self, value):
70        if not isinstance(value, basestring):
71            raise TypeError('Expecting string type for "matchId" '
72                            'attribute; got %r' % type(value))
73           
74        self.__matchId = value
75
76    matchId = property(_getMatchId, _setMatchId, None, "Match Id")
77   
78   
79class SubjectMatch(MatchBase):
80    "Subject Match Type"
81    ELEMENT_LOCAL_NAME = 'SubjectMatch'
82    ATTRIBUTE_DESIGNATOR_ELEMENT_LOCAL_NAME = 'SubjectAttributeDesignator'   
83   
84   
85class ResourceMatch(MatchBase):
86    "Resource Match"
87    ELEMENT_LOCAL_NAME = 'ResourceMatch'
88    ATTRIBUTE_DESIGNATOR_ELEMENT_LOCAL_NAME = 'ResourceAttributeDesignator'
89   
90   
91class ActionMatch(MatchBase):
92    "Action match"
93    ELEMENT_LOCAL_NAME = 'ActionMatch'
94    ATTRIBUTE_DESIGNATOR_ELEMENT_LOCAL_NAME = 'ActionAttributeDesignator'   
95   
96   
97class EnvironmentMatch(MatchBase):
98    "Environment Match"
99    ELEMENT_LOCAL_NAME = 'EnvironmentMatch'
100    ATTRIBUTE_DESIGNATOR_ELEMENT_LOCAL_NAME = 'EnvironmentAttributeDesignator'
Note: See TracBrowser for help on using the repository browser.