source: TI12-security/trunk/python/ndg.security.saml/saml/__init__.py @ 5597

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI12-security/trunk/python/ndg.security.saml/saml/__init__.py@5597
Revision 5597, 5.3 KB checked in by pjkersha, 11 years ago (diff)

Refactored SAML package structure into saml2, core and common sub-packages

Line 
1"""Implementation of SAML 2.0 for NDG Security
2
3NERC DataGrid Project
4
5This implementation is adapted from the Java OpenSAML implementation.  The
6copyright and licence information are included here:
7
8Copyright [2005] [University Corporation for Advanced Internet Development, Inc.]
9
10Licensed under the Apache License, Version 2.0 (the "License");
11you may not use this file except in compliance with the License.
12You may obtain a copy of the License at
13
14http://www.apache.org/licenses/LICENSE-2.0
15
16Unless required by applicable law or agreed to in writing, software
17distributed under the License is distributed on an "AS IS" BASIS,
18WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19See the License for the specific language governing permissions and
20limitations under the License.
21"""
22__author__ = "P J Kershaw"
23__date__ = "22/07/08"
24__copyright__ = "(C) 2009 Science and Technology Facilities Council"
25__contact__ = "Philip.Kershaw@stfc.ac.uk"
26__license__ = "BSD - see LICENSE file in top-level directory"
27__contact__ = "Philip.Kershaw@stfc.ac.uk"
28__revision__ = "$Id$"
29
30import logging
31log = logging.getLogger(__name__)
32
33# Time module for use with validity times
34from time import strftime, strptime
35from datetime import datetime
36   
37# TODO: remove ElementTree dependency - package should XML implementation
38# independent
39from saml.utils import TypedList
40from saml.xml import QName
41from saml.common.xml import SAMLConstants, XMLConstants
42from saml.saml2.core import AttributeValue
43   
44   
45class XSStringAttributeValue(AttributeValue):
46
47    # Local name of the XSI type
48    TYPE_LOCAL_NAME = "string"
49       
50    # QName of the XSI type
51    TYPE_NAME = QName(XMLConstants.XSD_NS, 
52                      TYPE_LOCAL_NAME, 
53                      XMLConstants.XSD_PREFIX)
54 
55    def __init__(self):
56        self.__value = None
57       
58    def _getValue(self):
59        return self.__value
60       
61    def _setValue(self, value):
62        if not isinstance(value, basestring):
63            raise TypeError("Input must be a basestring derived type, got %r" %
64                            value.__class__)
65           
66        self.__value = value
67
68    value = property(fget=_getValue, fset=_setValue, doc="string value") 
69   
70
71class XSGroupRoleAttributeValue(AttributeValue): 
72    '''ESG Specific Group/Role attribute value.  ESG attribute permissions are
73    organised into group/role pairs
74    '''
75    DEFAULT_NS = "http://www.esg.org"
76    DEFAULT_PREFIX = "esg"
77    TYPE_LOCAL_NAME = "groupRole"
78   
79    GROUP_ATTRIB_NAME = "group"
80    ROLE_ATTRIB_NAME = "role"
81   
82    # QName of the XSI type
83    TYPE_NAME = QName(DEFAULT_NS, 
84                      TYPE_LOCAL_NAME, 
85                      DEFAULT_PREFIX)
86     
87    def __init__(self, 
88                 namespaceURI=DEFAULT_NS, 
89                 elementLocalName=TYPE_LOCAL_NAME, 
90                 namespacePrefix=DEFAULT_PREFIX):
91        '''@param namespaceURI: the namespace the element is in
92        @param elementLocalName: the local name of the XML element this Object
93        represents
94        @param namespacePrefix: the prefix for the given namespace'''
95        self.__namespaceURI = namespaceURI
96        self.__elementLocalName = elementLocalName
97        self.__namespacePrefix = namespacePrefix
98        self.__group = None
99        self.__role = None       
100
101    def _getNamespaceURI(self):
102        return self.__namespaceURI
103
104    def _setNamespaceURI(self, value):
105        if not isinstance(value, basestring):
106            raise TypeError("Expecting %r type for namespaceURI got %r" %
107                            (basestring, value.__class__))
108        self.__namespaceURI = value
109
110    def _getElementLocalName(self):
111        return self.__elementLocalName
112
113    def _setElementLocalName(self, value):
114        if not isinstance(value, basestring):
115            raise TypeError("Expecting %r type for elementLocalName got %r" %
116                            (basestring, value.__class__))
117        self.__elementLocalName = value
118
119    def _getNamespacePrefix(self):
120        return self.__namespacePrefix
121
122    def _setNamespacePrefix(self, value):
123        if not isinstance(value, basestring):
124            raise TypeError("Expecting %r type for namespacePrefix got %r" %
125                            (basestring, value.__class__))
126        self.__namespacePrefix = value
127
128    namespaceURI = property(fget=_getNamespaceURI, 
129                            fset=_setNamespaceURI, 
130                            doc="the namespace the element is in")
131
132    elementLocalName = property(fget=_getElementLocalName, 
133                                fset=_setElementLocalName, 
134                                doc="the local name of the XML element this "
135                                    "Object represents")
136
137    namespacePrefix = property(fget=_getNamespacePrefix, 
138                               fset=_setNamespacePrefix, 
139                               doc="the prefix for the given namespace")
140
141    def _getGroup(self):
142        return self.__group
143     
144    def _setGroup(self, group): 
145        self.__group = group
146     
147    group = property(fget=_getGroup, fset=_setGroup)
148     
149    def _getRole(self):
150        return self.__role
151     
152    def _setRole(self, role):
153        self.__role = role
154     
155    role = property(fget=_getRole, fset=_setRole)
156
157    def getOrderedChildren(self):
158        # no children
159        return None
Note: See TracBrowser for help on using the repository browser.