Changeset 7147
- Timestamp:
- 01/07/10 12:24:22 (11 years ago)
- Location:
- TI12-security/trunk/ndg_saml/ndg/saml
- Files:
-
- 1 deleted
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
TI12-security/trunk/ndg_saml/ndg/saml/saml2/binding/soap/server/wsgi/queryinterface.py
r7143 r7147 404 404 else: 405 405 # Check for Query Interface in environ 406 queryInterface = environ.get(self.queryInterfaceKeyName) 407 if queryInterface is None: 406 queryInterface = environ.get(self.queryInterfaceKeyName, 407 NotImplemented) 408 if queryInterface == NotImplemented: 408 409 raise SOAPQueryInterfaceMiddlewareConfigError( 409 'No query interface "%s"key found in environ' %410 'No query interface %r key found in environ' % 410 411 self.queryInterfaceKeyName) 412 413 elif not callable(queryInterface): 414 raise SOAPQueryInterfaceMiddlewareConfigError( 415 'Query interface %r set in %r environ key is not callable' % 416 (queryInterface, self.queryInterfaceKeyName)) 411 417 412 418 # Basic validation -
TI12-security/trunk/ndg_saml/ndg/saml/test/binding/soap/attribute-interface.ini
r7143 r7147 18 18 19 19 [app:TestApp] 20 paste.app_factory = ndg.saml.test.binding.soap .test_soapattributeinterface:TestApp20 paste.app_factory = ndg.saml.test.binding.soap:TestApp 21 21 22 22 [filter:SAMLSoapAttributeInterfaceFilter] 23 23 paste.filter_app_factory = ndg.saml.saml2.binding.soap.server.wsgi.queryinterface:SOAPQueryInterfaceMiddleware.filter_app_factory 24 24 prefix = saml. 25 saml. pathMatchList = /attributeauthority/saml25 saml.mountPath = /attributeauthority 26 26 saml.queryInterfaceKeyName = attributeQueryInterface 27 27 saml.deserialise = ndg.saml.xml.etree:AttributeQueryElementTree.fromXML 28 29 # Specialisation to incorporate ESG Group/Role type 30 saml.serialise = ndg.security.common.saml_utils.esg.xml.etree:EsgResponseElementTree.toXML 28 saml.serialise = ndg.saml.xml.etree:ResponseElementTree.toXML 31 29 32 30 #______________________________________________________________________________ 33 # Attribute Authority WSGI settings31 # Test Attribute Authority WSGI settings 34 32 # 35 33 [filter:AttributeAuthorityFilter] 36 34 # This filter is a container for a binding to a SOAP based interface to the 37 35 # Attribute Authority 38 paste.filter_app_factory = ndg.security.server.wsgi.attributeauthority:AttributeAuthorityMiddleware.filter_app_factory 39 40 prefix = attributeAuthority. 41 42 attributeAuthority.environKeyName: attributeauthority 43 attributeAuthority.environKeyNameAttributeQueryInterface: attributeQueryInterface 44 45 # Attribute Authority settings 46 # 'name' setting MUST agree with map config file 'thisHost' name attribute 47 attributeAuthority.name: Site A 48 49 # Lifetime is measured in seconds 50 attributeAuthority.attCertLifetime: 28800 51 52 # Allow an offset for clock skew between servers running 53 # security services. NB, measured in seconds - use a minus sign for time in the 54 # past 55 attributeAuthority.attCertNotBeforeOff: 0 56 57 # All Attribute Certificates issued are recorded in this dir 58 attributeAuthority.attCertDir: %(testConfigDir)s/attributeauthority/sitea/attributeCertificateLog 59 60 # Files in attCertDir are stored using a rotating file handler 61 # attCertFileLogCnt sets the max number of files created before the first is 62 # overwritten 63 attributeAuthority.attCertFileName: ac.xml 64 attributeAuthority.attCertFileLogCnt: 16 65 attributeAuthority.dnSeparator:/ 66 67 # Location of role mapping file 68 attributeAuthority.mapConfigFilePath: %(testConfigDir)s/attributeauthority/sitea/siteAMapConfig.xml 69 70 # Settings for custom AttributeInterface derived class to get user roles for given 71 # user ID 72 attributeAuthority.attributeInterface.modFilePath: %(testConfigDir)s/attributeauthority/sitea 73 attributeAuthority.attributeInterface.modName: ndg.security.test.config.attributeauthority.sitea.siteAUserRoles 74 attributeAuthority.attributeInterface.className: TestUserRoles 75 76 # Config for XML signature of Attribute Certificate 77 attributeAuthority.signingPriKeyFilePath: %(testConfigDir)s/attributeauthority/sitea/siteA-aa.key 78 attributeAuthority.signingCertFilePath: %(testConfigDir)s/attributeauthority/sitea/siteA-aa.crt 79 attributeAuthority.caCertFilePathList: %(testConfigDir)s/ca/d573507a.0 36 paste.filter_app_factory = ndg.saml.test.binding.soap.test_soapattributeinterface:TestAttributeServiceMiddleware 37 queryInterfaceKeyName = attributeQueryInterface -
TI12-security/trunk/ndg_saml/ndg/saml/test/binding/soap/test_samlinterface.py
r7140 r7147 35 35 from ndg.soap.etree import SOAPEnvelope 36 36 from ndg.soap.utils.etree import QName, prettyPrint 37 38 from ndg.security.common.saml_utils.esg import (EsgSamlNamespaces,39 XSGroupRoleAttributeValue)40 from ndg.security.common.saml_utils.esg.xml.etree import (41 XSGroupRoleAttributeValueElementTree)42 37 43 38 -
TI12-security/trunk/ndg_saml/ndg/saml/test/binding/soap/test_soapattributeinterface.py
r7140 r7147 12 12 import unittest 13 13 from uuid import uuid4 14 from datetime import datetime 14 from datetime import datetime, timedelta 15 15 from cStringIO import StringIO 16 16 17 from ndg.saml.saml2.core import (Attribute, SAMLVersion, Subject, NameID, 18 Issuer, AttributeQuery, XSStringAttributeValue, 19 StatusCode) 17 from ndg.soap.etree import SOAPEnvelope 18 19 from ndg.saml.saml2.core import (Assertion, Attribute, AttributeStatement, 20 SAMLVersion, Subject, NameID, Issuer, 21 AttributeQuery, XSStringAttributeValue, 22 Conditions, Status, StatusCode) 20 23 from ndg.saml.xml import XMLConstants 21 24 from ndg.saml.xml.etree import AttributeQueryElementTree, ResponseElementTree 22 23 from ndg.soap.etree import SOAPEnvelope 24 from ndg.security.common.saml_utils.esg import EsgSamlNamespaces 25 from ndg.security.test.unit.wsgi.saml import SoapSamlInterfaceMiddlewareTestCase 25 from ndg.saml.test.binding.soap import SoapSamlInterfaceMiddlewareTestCase 26 27 28 class TestAttributeServiceMiddleware(object): 29 """Test Attribute Service interface stub""" 30 QUERY_INTERFACE_KEYNAME_OPTNAME = 'queryInterfaceKeyName' 31 ISSUER_DN = '/O=Test/OU=Attribute Service/CN=Service Stub' 32 33 FIRSTNAME_ATTRNAME = "urn:ndg:saml:firstname" 34 LASTNAME_ATTRNAME = "urn:ndg:saml:lastname" 35 EMAILADDRESS_ATTRNAME = "urn:ndg:saml:emailaddress" 36 37 VALID_QUERY_ISSUERS = ( 38 "/O=Site A/CN=Authorisation Service", 39 "/O=Site B/CN=Authorisation Service" 40 ) 41 VALID_SUBJECTS = ("https://openid.localhost/philip.kershaw", ) 42 VALID_ATTR_NAME_URIS = ( 43 FIRSTNAME_ATTRNAME, LASTNAME_ATTRNAME, EMAILADDRESS_ATTRNAME 44 ) 45 46 def __init__(self, app, global_conf, **app_conf): 47 self.queryInterfaceKeyName = app_conf[ 48 self.__class__.QUERY_INTERFACE_KEYNAME_OPTNAME] 49 self._app = app 50 51 self.firstName = "Philip" 52 self.lastName = "Kershaw" 53 self.emailAddress = "pkershaw@somewhere.ac.uk" 54 55 def __call__(self, environ, start_response): 56 environ[self.queryInterfaceKeyName] = self.attributeQueryFactory() 57 return self._app(environ, start_response) 58 59 def attributeQueryFactory(self): 60 """Makes the attribute query method""" 61 62 def attributeQuery(query, response): 63 """Attribute Query interface called by the next middleware in the 64 stack the SAML SOAP Query interface middleware instance 65 (ndg.saml.saml2.binding.soap.server.wsgi.queryinterface.SOAPQueryInterfaceMiddleware) 66 """ 67 response.issueInstant = datetime.utcnow() 68 response.id = str(uuid4()) 69 response.issuer = Issuer() 70 71 # SAML 2.0 spec says format must be omitted 72 #response.issuer.format = Issuer.X509_SUBJECT 73 response.issuer.value = \ 74 "/O=NDG/OU=BADC/CN=attributeauthority.badc.rl.ac.uk" 75 76 response.inResponseTo = query.id 77 78 if query.issuer.value not in self.__class__.VALID_QUERY_ISSUERS: 79 response.status.statusCode.value = \ 80 StatusCode.REQUEST_DENIED_URI 81 return response 82 83 if query.subject.nameID.value not in self.__class__.VALID_SUBJECTS: 84 response.status.statusCode.value = \ 85 StatusCode.UNKNOWN_PRINCIPAL_URI 86 return response 87 88 assertion = Assertion() 89 90 assertion.version = SAMLVersion(SAMLVersion.VERSION_20) 91 assertion.id = str(uuid4()) 92 assertion.issueInstant = response.issueInstant 93 94 assertion.conditions = Conditions() 95 assertion.conditions.notBefore = assertion.issueInstant 96 assertion.conditions.notOnOrAfter = \ 97 assertion.conditions.notBefore + timedelta(seconds=60*60*8) 98 99 assertion.subject = Subject() 100 assertion.subject.nameID = NameID() 101 assertion.subject.nameID.format = query.subject.nameID.format 102 assertion.subject.nameID.value = query.subject.nameID.value 103 104 assertion.attributeStatements.append(AttributeStatement()) 105 106 for attribute in query.attributes: 107 if attribute.name == self.__class__.FIRSTNAME_ATTRNAME: 108 # special case handling for 'FirstName' attribute 109 fnAttribute = Attribute() 110 fnAttribute.name = attribute.name 111 fnAttribute.nameFormat = attribute.nameFormat 112 fnAttribute.friendlyName = attribute.friendlyName 113 114 firstName = XSStringAttributeValue() 115 firstName.value = self.firstName 116 fnAttribute.attributeValues.append(firstName) 117 118 assertion.attributeStatements[0].attributes.append( 119 fnAttribute) 120 121 elif attribute.name == self.__class__.LASTNAME_ATTRNAME: 122 lnAttribute = Attribute() 123 lnAttribute.name = attribute.name 124 lnAttribute.nameFormat = attribute.nameFormat 125 lnAttribute.friendlyName = attribute.friendlyName 126 127 lastName = XSStringAttributeValue() 128 lastName.value = self.lastName 129 lnAttribute.attributeValues.append(lastName) 130 131 assertion.attributeStatements[0].attributes.append( 132 lnAttribute) 133 134 elif (attribute.name == self.__class__.EMAILADDRESS_ATTRNAME and 135 query.issuer.value == 136 self.__class__.VALID_QUERY_ISSUERS[0]): 137 emailAddressAttribute = Attribute() 138 emailAddressAttribute.name = attribute.name 139 emailAddressAttribute.nameFormat = attribute.nameFormat 140 emailAddressAttribute.friendlyName = attribute.friendlyName 141 142 emailAddress = XSStringAttributeValue() 143 emailAddress.value = self.emailAddress 144 emailAddressAttribute.attributeValues.append(emailAddress) 145 146 assertion.attributeStatements[0].attributes.append( 147 emailAddressAttribute) 148 else: 149 response.status.statusCode.value = \ 150 StatusCode.INVALID_ATTR_NAME_VALUE_URI 151 return response 152 153 154 response.assertions.append(assertion) 155 response.status.statusCode.value = StatusCode.SUCCESS_URI 156 157 return response 158 159 return attributeQuery 26 160 27 161 … … 29 163 SoapSamlInterfaceMiddlewareTestCase): 30 164 CONFIG_FILENAME = 'attribute-interface.ini' 165 SERVICE_URI = '/attributeauthority' 31 166 32 167 def _createAttributeQuery(self, … … 44 179 attributeQuery.subject = Subject() 45 180 attributeQuery.subject.nameID = NameID() 46 attributeQuery.subject.nameID.format = EsgSamlNamespaces.NAMEID_FORMAT181 attributeQuery.subject.nameID.format = "urn:ndg:saml:test:openid" 47 182 attributeQuery.subject.nameID.value = subject 48 183 … … 50 185 # special case handling for 'FirstName' attribute 51 186 fnAttribute = Attribute() 52 fnAttribute.name = EsgSamlNamespaces.FIRSTNAME_ATTRNAME187 fnAttribute.name = TestAttributeServiceMiddleware.FIRSTNAME_ATTRNAME 53 188 fnAttribute.nameFormat = "http://www.w3.org/2001/XMLSchema#string" 54 189 fnAttribute.friendlyName = "FirstName" … … 58 193 # special case handling for 'LastName' attribute 59 194 lnAttribute = Attribute() 60 lnAttribute.name = EsgSamlNamespaces.LASTNAME_ATTRNAME195 lnAttribute.name = TestAttributeServiceMiddleware.LASTNAME_ATTRNAME 61 196 lnAttribute.nameFormat = "http://www.w3.org/2001/XMLSchema#string" 62 197 lnAttribute.friendlyName = "LastName" … … 66 201 # special case handling for 'LastName' attribute 67 202 emailAddressAttribute = Attribute() 68 emailAddressAttribute.name = EsgSamlNamespaces.EMAILADDRESS_ATTRNAME 203 emailAddressAttribute.name = \ 204 TestAttributeServiceMiddleware.EMAILADDRESS_ATTRNAME 69 205 emailAddressAttribute.nameFormat = XMLConstants.XSD_NS+"#"+\ 70 206 XSStringAttributeValue.TYPE_LOCAL_NAME … … 117 253 'Content-type': 'text/xml' 118 254 } 119 response = self.app.post( '/attributeauthority/saml',255 response = self.app.post(self.__class__.SERVICE_URI, 120 256 params=request, 121 257 headers=header, … … 139 275 } 140 276 141 response = self.app.post( '/attributeauthority/saml',277 response = self.app.post(self.__class__.SERVICE_URI, 142 278 params=request, 143 279 headers=header, … … 170 306 } 171 307 172 response = self.app.post( '/attributeauthority/saml',308 response = self.app.post(self.__class__.SERVICE_URI, 173 309 params=request, 174 310 headers=header, … … 191 327 } 192 328 193 response = self.app.post( '/attributeauthority/saml',329 response = self.app.post(self.__class__.SERVICE_URI, 194 330 params=request, 195 331 headers=header, … … 212 348 } 213 349 214 response = self.app.post( '/attributeauthority/saml',350 response = self.app.post(self.__class__.SERVICE_URI, 215 351 params=request, 216 352 headers=header, -
TI12-security/trunk/ndg_saml/ndg/saml/test/binding/soap/test_soapauthzdecisioninterface.py
r7143 r7147 42 42 43 43 def authzDecisionQueryFactory(self): 44 """Makes the authorisation decision""" 45 44 46 def authzDecisionQuery(query, response): 47 """Authorisation Decision Query interface called by the next 48 middleware in the stack the SAML SOAP Query interface middleware 49 instance 50 (ndg.saml.saml2.binding.soap.server.wsgi.queryinterface.SOAPQueryInterfaceMiddleware) 51 """ 45 52 now = datetime.utcnow() 46 53 response.issueInstant = now
Note: See TracChangeset
for help on using the changeset viewer.