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

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

Parsing functionality near complete for rule1.xml

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