Changeset 6913
- Timestamp:
- 01/06/10 11:25:08 (11 years ago)
- Location:
- TI12-security/trunk/ndg_saml/ndg/saml
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
TI12-security/trunk/ndg_saml/ndg/saml/saml2/core.py
r6911 r6913 3390 3390 @raise TypeError: incorrect type for attributes list 3391 3391 ''' 3392 if not isinstance(value, TypedList): 3393 raise TypeError('Expecting %r type for "attributes"; got %r' % 3394 (TypedList, (type))) 3395 3396 if not issubclass(value.elementType, Attribute): 3392 if isinstance(value, TypedList) and not issubclass(value.elementType, 3393 Attribute): 3397 3394 raise TypeError('Expecting %r derived type for "attributes" ' 3398 3395 'elements; got %r' % (Attribute, value.elementType)) 3399 3400 self.__attributes = value 3401 3396 else: 3397 self.__attributes = TypedList(Attribute) 3398 for i in value: 3399 self.__attributes.append(i) 3400 3402 3401 attributes = property(fget=_getAttributes, 3403 3402 fset=_setAttributes, … … 4015 4014 @type TYPE_LOCAL_NAME: string 4016 4015 @cvar TYPE_NAME: QName of the XSI type. 4017 @type TYPE_NAME: string4016 @type TYPE_NAME: ndg.saml.common.xml.QName 4018 4017 @cvar ID_ATTRIB_NAME: ID attribute name 4019 4018 @type ID_ATTRIB_NAME: string … … 4043 4042 @type INAPPLICABLE_CONSENT: string 4044 4043 4044 @ivar __version: SAML version 4045 @type __version: string 4046 @ivar __id: response identifier 4047 @type __id: string 4048 @ivar __inResponseTo: identifier corresponding to the query this response is 4049 responding to 4050 @type __inResponseTo: string 4051 @ivar __issueInstant: issue instant for the response 4052 @type __issueInstant: datetime.datetime 4053 @ivar __destination: destination for the response 4054 @type __destination: string 4055 @ivar __consent: consent information 4056 @type __consent: string 4057 @ivar __issuer: issuer identifier 4058 @type __issuer: ndg.saml.saml2.core.Issuer 4059 @ivar __status: status of the response 4060 @type __status: ndg.saml.saml2.core.Status 4061 @ivar __extensions: response extensions 4062 @type __extensions: list or tuple 4045 4063 ''' 4046 4064 … … 4105 4123 4106 4124 def __init__(self, **kw): 4125 ''' 4126 @param **kw: keywords for initialisation of superclass 4127 @type **kw: dict 4128 ''' 4107 4129 super(StatusResponseType, self).__init__(**kw) 4108 4130 … … 4136 4158 4137 4159 def _get_version(self): 4138 '''@return: the SAML Version of this response. 4160 '''@return: the SAML Version of this response 4161 @rtype: string 4139 4162 ''' 4140 4163 return self.__version … … 4142 4165 def _set_version(self, version): 4143 4166 '''@param version: the SAML Version of this response 4167 @type version: basestring 4168 @raise TypeError: incorrect type for input version 4144 4169 ''' 4145 4170 if not isinstance(version, SAMLVersion): … … 4157 4182 4158 4183 @return: the ID of this response 4184 @rtype: basestring 4159 4185 ''' 4160 4186 return self.__id … … 4164 4190 4165 4191 @param value: the ID of this response 4192 @type value: basestring 4193 @raise TypeError: incorrect type for input value 4166 4194 ''' 4167 4195 if not isinstance(value, basestring): … … 4177 4205 @return: the unique identifier of the originating 4178 4206 request 4207 @rtype: basestring 4179 4208 ''' 4180 4209 return self.__inResponseTo … … 4185 4214 @param value: the unique identifier of the originating 4186 4215 request 4216 @type value: basestring 4217 @raise TypeError: incorrect type for input value 4187 4218 ''' 4188 4219 if not isinstance(value, basestring): … … 4197 4228 4198 4229 def _get_issueInstant(self): 4199 '''Gets the issue instance of this response. 4200 4201 @return: the issue instance of this response''' 4230 '''Gets the issue instant of this response. 4231 4232 @return: the issue instant of this response 4233 @rtype: datetime.datetime''' 4202 4234 return self.__issueInstant 4203 4235 4204 4236 def _set_issueInstant(self, issueInstant): 4205 '''Sets the issue instance of this response. 4206 4207 @param newIssueInstance: the issue instance of this response 4237 '''Set the issue instant of this response 4238 4239 @param issueInstant: the issue instance of this response 4240 @type issueInstant: datetime.datetime 4241 @raise TypeError: incorrect type for input value 4208 4242 ''' 4209 4243 if not isinstance(issueInstant, datetime): … … 4221 4255 4222 4256 @return: the URI of the destination of the response 4257 @rtype: basestring 4223 4258 ''' 4224 4259 return self.__destination … … 4227 4262 '''Sets the URI of the destination of the response. 4228 4263 4229 @param value: the URI of the destination of the response''' 4264 @param value: the URI of the destination of the response 4265 @type value: basestring 4266 @raise TypeError: incorrect type for input value 4267 ''' 4230 4268 if not isinstance(value, basestring): 4231 4269 raise TypeError('Expecting basestring derived type for ' … … 4238 4276 4239 4277 def _get_consent(self): 4240 '''Get sthe consent obtained from the principal for sending this4241 response .4278 '''Get the consent obtained from the principal for sending this 4279 response 4242 4280 4243 4281 @return: the consent obtained from the principal for sending this 4244 4282 response 4283 @rtype: basestring 4245 4284 ''' 4246 4285 return self.__consent … … 4252 4291 @param value: the new consent obtained from the principal for 4253 4292 sending this response 4293 @type value: basestring 4294 @raise TypeError: incorrect type for input value 4254 4295 ''' 4255 4296 if not isinstance(value, basestring): … … 4263 4304 4264 4305 def _set_issuer(self, issuer): 4265 """Set issuer of response""" 4306 """Set issuer of response 4307 4308 @param value: issuer of this response 4309 sending this response 4310 @type value: ndg.saml.saml2.core.Issuer 4311 @raise TypeError: incorrect type for input value 4312 """ 4266 4313 if not isinstance(issuer, Issuer): 4267 4314 raise TypeError('"issuer" must be a %r, got %r' % (Issuer, … … 4270 4317 4271 4318 def _get_issuer(self): 4272 """Get the issuer name """ 4319 """Get the issuer name 4320 4321 @return: issuer of this response 4322 sending this response 4323 @rtype: ndg.saml.saml2.core.Issuer 4324 """ 4273 4325 return self.__issuer 4274 4326 … … 4281 4333 4282 4334 @return: the Status of this response 4335 @rtype: ndg.saml.saml2.core.Status 4283 4336 ''' 4284 4337 return self.__status … … 4287 4340 '''Sets the Status of this response. 4288 4341 4289 @param newStatus: the Status of this response 4342 @param value: the Status of this response 4343 @type value: ndg.saml.saml2.core.Status 4344 @raise TypeError: incorrect type for input value 4290 4345 ''' 4291 4346 if not isinstance(value, Status): … … 4300 4355 4301 4356 @return: the Status of this response 4357 @rtype: tuple/list/NoneType 4302 4358 ''' 4303 4359 return self.__extensions … … 4307 4363 4308 4364 @param value: the Extensions of this response 4365 @type value: tuple or list 4366 @raise TypeError: incorrect type for input value 4309 4367 ''' 4310 4368 if not isinstance(value, (list, tuple)): … … 4319 4377 4320 4378 class Response(StatusResponseType): 4321 '''SAML2 Core Response''' 4379 '''SAML2 Core Response 4380 4381 @cvar DEFAULT_ELEMENT_LOCAL_NAME: Element local name. 4382 @type DEFAULT_ELEMENT_LOCAL_NAME: ndg.saml.common.xml.QName 4383 @cvar DEFAULT_ELEMENT_NAME: Default element name. 4384 @type DEFAULT_ELEMENT_NAME: string 4385 @cvar TYPE_LOCAL_NAME: Local name of the XSI type. 4386 @type TYPE_LOCAL_NAME: string 4387 @cvar TYPE_NAME: QName of the XSI type. 4388 @type TYPE_NAME: ndg.saml.common.xml.QName 4389 4390 @ivar __indexedChildren: response elements 4391 @type __indexedChildren: list 4392 ''' 4322 4393 4323 4394 # Element local name. … … 4340 4411 4341 4412 def __init__(self, **kw): 4342 '''''' 4413 ''' 4414 @param **kw: keywords to initialise superclass instance 4415 @type **kw: dict 4416 ''' 4343 4417 super(Response, self).__init__(**kw) 4344 4418 … … 4366 4440 @property 4367 4441 def assertions(self): 4368 "Assertions contained in this response" 4442 """Assertions contained in this response 4443 4444 @return: list of assertion for this response 4445 @rtype: list 4446 """ 4369 4447 return self.__indexedChildren -
TI12-security/trunk/ndg_saml/ndg/saml/test/test_saml.py
r6901 r6913 714 714 self.assert_(query2.actions[0].namespace == Action.GHPP_NS_URI) 715 715 716 717 718 716 def test16PickleAuthzDecisionResponse(self): 719 717 response = self._createAuthzDecisionQueryResponse() -
TI12-security/trunk/ndg_saml/ndg/saml/utils.py
r6900 r6913 39 39 """Generic datetime formatting utility for SAML timestamps - XMLSchema 40 40 Datetime format 41 42 @cvar DATETIME_FORMAT: date/time format string for SAML timestamps 43 @type DATETIME_FORMAT: string 41 44 """ 42 45 DATETIME_FORMAT = "%Y-%m-%dT%H:%M:%S" … … 45 48 def toString(cls, dtValue): 46 49 """Convert issue instant datetime to correct string type for output 50 47 51 @type dtValue: datetime.datetime 48 52 @param dtValue: issue instance as a datetime … … 61 65 def fromString(cls, strDateTime): 62 66 """Convert issue instant string to datetime type 67 63 68 @type strDateTime: basestring 64 69 @param strDateTime: issue instance as a string … … 95 100 96 101 def _getElementType(self): 102 """@return: element type for this list 103 @rtype: type 104 """ 97 105 return self.__elementType 98 106 … … 101 109 102 110 def extend(self, iter): 111 """Extend an existing list with the input iterable 112 @param iter: iterable to extend list with 113 @type iter: iterable 114 """ 103 115 for i in iter: 104 116 if not isinstance(i, self.__elementType): … … 109 121 110 122 def __iadd__(self, iter): 123 """Extend an existing list with the input iterable with += operator 124 125 @param iter: iterable to extend list with 126 @type iter: iterable 127 """ 111 128 for i in iter: 112 129 if not isinstance(i, self.__elementType): … … 117 134 118 135 def append(self, item): 136 """Append a list with the given item 137 138 @param item: item to extend list 139 @type item: must agree witj "elementType" attribute of this list 140 """ 119 141 if not isinstance(item, self.__elementType): 120 142 raise TypeError("List items must be of type %s" % -
TI12-security/trunk/ndg_saml/ndg/saml/xml/etree.py
r6900 r6913 39 39 40 40 from ndg.saml.saml2.core import (SAMLObject, Attribute, AttributeStatement, 41 AuthnStatement, AuthzDecisionStatement, Assertion,42 Conditions, AttributeValue, AttributeQuery,43 AuthzDecisionQuery, Subject, NameID, Issuer,44 Response, Status, StatusCode, StatusMessage,45 StatusDetail, Advice, Action, Evidence,46 DecisionType, XSStringAttributeValue)41 AuthnStatement, AuthzDecisionStatement, 42 Assertion, Conditions, AttributeValue, 43 AttributeQuery, AuthzDecisionQuery, Subject, 44 NameID, Issuer, Response, Status, StatusCode, 45 StatusMessage, StatusDetail, Advice, Action, 46 Evidence, DecisionType, XSStringAttributeValue) 47 47 48 48 from ndg.saml.common import SAMLVersion … … 92 92 93 93 def _getPrefix(self): 94 """@return: NS prefix 95 @rtype: basestring 96 """ 94 97 return self.__prefix 95 98 96 99 def _setPrefix(self, value): 100 """@param value: NS prefix 101 @type value: basestring 102 """ 97 103 self.__prefix = value 98 104 … … 100 106 101 107 def _getLocalPart(self): 108 """@return: NS local name 109 @rtype: basestring 110 """ 102 111 return self.__localPart 103 112 104 113 def _setLocalPart(self, value): 114 """@param value: NS local name 115 @type value: basestring 116 """ 105 117 self.__localPart = value 106 118 … … 108 120 109 121 def _getNamespaceURI(self): 122 """@return: NS URI 123 @rtype: basestring 124 """ 110 125 return self.__namespaceURI 111 126 112 127 def _setNamespaceURI(self, value): 128 """@param value: NS URI 129 @type value: basestring 130 """ 113 131 self.__namespaceURI = value 114 132 … … 122 140 @type qname: ndg.security.common.utils.etree.QName 123 141 @param qname: Qualified Name to compare with self 142 143 @return: True if the qualified names match, False otherwise 144 @rtype: bool 124 145 """ 125 146 if not isinstance(qname, QName): … … 136 157 @type qname: ndg.security.common.utils.etree.QName 137 158 @param qname: Qualified Name to compare with self 159 @return: True if the qualified names don't match, False otherwise 160 @rtype: bool 138 161 """ 139 162 return not self.__eq__(qname) … … 141 164 @classmethod 142 165 def fromGeneric(cls, genericQName): 143 '''Cast the generic QName type in saml.common.xml to the 144 ElementTree specific implementation''' 166 '''Cast the generic QName type in ndg.saml.common.xml to this 167 ElementTree specific implementation 168 169 @param genericQName: SAML core qualified name type 170 @type genericQName: ndg.saml.common.xml.QName 171 @return: ElementTree specific qualified name type 172 @rtype: ndg.saml.xml.etree.QName 173 ''' 145 174 if not isinstance(genericQName, GenericQName): 146 175 raise TypeError("Expecting %r for QName, got %r" % (GenericQName, … … 154 183 155 184 def prettyPrint(*arg, **kw): 156 '''Lightweight pretty printing of ElementTree elements''' 185 '''Lightweight pretty printing of ElementTree elements. This function 186 wraps the PrettyPrint class 187 188 @param *arg: arguments to pretty print function 189 @type *arg: tuple 190 @param **kw: keyword arguments to pretty print function 191 @type **kw: dict 192 ''' 157 193 158 194 # Keep track of namespace declarations made so they're not repeated … … 164 200 165 201 class PrettyPrint(object): 202 '''Class for lightweight pretty printing of ElementTree elements''' 166 203 def __init__(self, declaredNss): 204 """ 205 @param declaredNss: declared namespaces 206 @type declaredNss: iterable of string elements 207 """ 167 208 self.declaredNss = declaredNss 168 209 169 210 @staticmethod 170 211 def estrip(elem): 171 ''' Just want to get rid of unwanted whitespace ''' 212 '''Utility to remove unwanted leading and trailing whitespace 213 214 @param elem: ElementTree element 215 @type elem: ElementTree.Element 216 @return: element content with whitespace removed 217 @rtype: basestring''' 172 218 if elem is None: 173 219 return '' … … 180 226 '''Most of the work done in this wrapped function - wrapped so that 181 227 state can be maintained for declared namespace declarations during 182 recursive calls using "declaredNss" above''' 228 recursive calls using "declaredNss" above 229 230 @param elem: ElementTree element 231 @type elem: ElementTree.Element 232 @param indent: set indent for output 233 @type indent: basestring 234 @param space: set output spacing 235 @type space: basestring 236 @return: pretty print format for doc 237 @rtype: basestring 238 ''' 183 239 strAttribs = [] 184 240 for attr, attrVal in elem.attrib.items(): … … 247 303 """Make a tree of a XML elements based on the assertion conditions 248 304 249 @type assertion: saml.saml2.core.Conditions250 @param assertion: Assertion conditions to be represented as an305 @type conditions: saml.saml2.core.Conditions 306 @param conditions: Assertion conditions to be represented as an 251 307 ElementTree Element 252 308 @rtype: ElementTree.Element … … 284 340 @param elem: ElementTree element containing the conditions 285 341 @rtype: saml.saml2.core.Conditions 286 @return: Conditions object""" 342 @return: Conditions object 343 """ 287 344 288 345 if not ElementTree.iselement(elem): … … 393 450 @param attributeValueElementTreeFactoryKw: keywords for AttributeValue 394 451 @rtype: saml.saml2.core.Assertion 395 @return: Assertion object""" 452 @return: Assertion object 453 """ 396 454 if not ElementTree.iselement(elem): 397 455 raise TypeError("Expecting %r input type for parsing; got %r" % … … 513 571 factory 514 572 @rtype: saml.saml2.core.AttributeStatement 515 @return: Attribute Statement""" 573 @return: Attribute Statement 574 """ 516 575 517 576 if not ElementTree.iselement(elem): … … 587 646 @type elem: ElementTree.Element 588 647 @param elem: ElementTree element containing the AuthzDecisionStatement 589 @type authzDecisionValueElementTreeFactoryKw: dict590 @param authzDecisionValueElementTreeFactoryKw: keywords for AuthzDecisionValue591 factory592 648 @rtype: saml.saml2.core.AuthzDecisionStatement 593 649 @return: AuthzDecision Statement""" … … 645 701 """Make a tree of a XML elements based on the Attribute 646 702 647 @type a ssertion: saml.saml2.core.Attribute648 @param a ssertion: Attribute to be represented as an ElementTree Element703 @type attribute: saml.saml2.core.Attribute 704 @param attribute: Attribute to be represented as an ElementTree Element 649 705 @type attributeValueElementTreeFactoryKw: dict 650 706 @param attributeValueElementTreeFactoryKw: keywords for AttributeValue … … 745 801 """Make a tree of a XML elements based on the Attribute value 746 802 747 @type assertion: saml.saml2.core.Assertion 748 @param assertion: Assertion to be represented as an ElementTree Element 803 @type attributeValue: saml.saml2.core.AttributeValue 804 @param attributeValue: Assertion to be represented as an ElementTree 805 Element 749 806 @rtype: ElementTree.Element 750 807 @return: ElementTree Element … … 770 827 """Create an XML representation of the input SAML Attribute Value 771 828 772 @type assertion: saml.saml2.core.XSStringAttributeValue 773 @param assertion: xs:string to be represented as an ElementTree Element 829 @type attributeValue: saml.saml2.core.XSStringAttributeValue 830 @param attributeValue: xs:string to be represented as an ElementTree 831 Element 774 832 @rtype: ElementTree.Element 775 833 @return: ElementTree Element … … 850 908 ElementTree handler class 851 909 @type toSAMLTypeMap: dict 852 @cvar toSAMLTypeMap: mapping between SAML AttributeValue string identifier and853 its ElementTree handler class910 @cvar toSAMLTypeMap: mapping between SAML AttributeValue string identifier 911 and its ElementTree handler class 854 912 """ 855 913 toXMLTypeMap = { … … 859 917 def xsstringMatch(elem): 860 918 """Match function for xs:string type attribute. 919 861 920 @type elem: ElementTree.Element 862 921 @param elem: Attribute Value element to be checked … … 885 944 def __init__(self, customToXMLTypeMap={}, customToSAMLTypeMap=[]): 886 945 """Set-up a SAML class to ElementTree mapping 946 887 947 @type customToXMLTypeMap: dict 888 948 @param customToXMLTypeMap: mapping for custom SAML AttributeValue … … 923 983 @type input: saml.saml2.core.AttributeValue or basestring 924 984 @param input: pass an AttributeValue derived type or a string. If 925 an AttributeValue type, then self.__toXMLTypeMap is checked for a matching926 AttributeValue class entry, if a string is passed, self.__toSAMLTypeMap is927 checked for a matching string ID. In both cases, if a match is928 found an ElementTree class is returned which can render or parse929 the relevant AttributeValue class985 an AttributeValue type, then self.__toXMLTypeMap is checked for a 986 matching AttributeValue class entry, if a string is passed, 987 self.__toSAMLTypeMap is checked for a matching string ID. In both 988 cases, if a match is found an ElementTree class is returned which can 989 render or parse the relevant AttributeValue class 930 990 """ 931 991 if isinstance(input, AttributeValue): … … 970 1030 @classmethod 971 1031 def toXML(cls, issuer): 972 """Create an XML representation of the input SAML issuer object""" 1032 """Create an XML representation of the input SAML issuer object 1033 1034 @type issuer: saml.saml2.core.Issuer 1035 @param issuer: Assertion object 1036 @rtype: ElementTree.Element 1037 @return: ElementTree element containing the assertion 1038 """ 973 1039 if not isinstance(issuer, Issuer): 974 1040 raise TypeError("Expecting %r class got %r" % (Issuer, … … 1032 1098 @param nameID: SAML name ID 1033 1099 @rtype: ElementTree.Element 1034 @return: Name ID as ElementTree XML element""" 1100 @return: Name ID as ElementTree XML element 1101 """ 1035 1102 1036 1103 if not isinstance(nameID, NameID): … … 1144 1211 @param statusCode: SAML Status Code 1145 1212 @rtype: ElementTree.Element 1146 @return: Status Code as ElementTree XML element""" 1213 @return: Status Code as ElementTree XML element 1214 """ 1147 1215 1148 1216 if not isinstance(statusCode, StatusCode): … … 1200 1268 @param statusMessage: SAML Status Message 1201 1269 @rtype: ElementTree.Element 1202 @return: Status Code as ElementTree XML element""" 1270 @return: Status Code as ElementTree XML element 1271 """ 1203 1272 1204 1273 if not isinstance(statusMessage, StatusMessage): … … 1579 1648 @param action: SAML subject 1580 1649 @rtype: ElementTree.Element 1581 @return: Name ID as ElementTree XML element""" 1650 @return: Name ID as ElementTree XML element 1651 """ 1582 1652 1583 1653 if not isinstance(action, Action):
Note: See TracChangeset
for help on using the changeset viewer.