Changeset 7143
- Timestamp:
- 01/07/10 08:53:38 (11 years ago)
- Location:
- TI12-security/trunk/ndg_saml/ndg/saml
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
TI12-security/trunk/ndg_saml/ndg/saml/saml2/binding/soap/__init__.py
r7130 r7143 12 12 __contact__ = "Philip.Kershaw@stfc.ac.uk" 13 13 __revision__ = "$Id$" 14 class SOAPBindingError(Exception): 15 '''Base exception type for client SAML SOAP Binding''' 16 17 18 class SOAPBindingInvalidResponse(SOAPBindingError): 19 '''Raise if the response is invalid''' 20 def __init__(self, *arg, **kw): 21 SOAPBindingInvalidResponse.__init__(self, *arg, **kw) 22 self.__response = None 23 24 def _getResponse(self): 25 '''Gets the response corresponding to this error 26 27 @return the response 28 ''' 29 return self.__response 30 31 def _setResponse(self, value): 32 '''Sets the response corresponding to this error. 33 34 @param value: the response 35 ''' 36 if not isinstance(value, Response): 37 raise TypeError('"response" must be a %r, got %r' % (Response, 38 type(value))) 39 self.__response = value 40 41 response = property(fget=_getResponse, fset=_setResponse, 42 doc="SAML Response associated with this exception") -
TI12-security/trunk/ndg_saml/ndg/saml/saml2/binding/soap/client/__init__.py
r7130 r7143 24 24 from ndg.soap.client import (UrlLib2SOAPClient, UrlLib2SOAPRequest) 25 25 26 27 class SOAPBindingError(Exception): 28 '''Base exception type for client SAML SOAP Binding for Attribute Query''' 29 30 31 class SOAPBindingInvalidResponse(SOAPBindingError): 32 '''Raise if the response is invalid''' 26 from ndg.saml.saml2.binding.soap import SOAPBindingInvalidResponse 33 27 34 28 -
TI12-security/trunk/ndg_saml/ndg/saml/saml2/binding/soap/client/subjectquery.py
r7130 r7143 27 27 class SubjectQueryResponseError(SOAPBindingInvalidResponse): 28 28 """SAML Response error from Subject Query""" 29 def __init__(self, *arg, **kw):30 SOAPBindingInvalidResponse.__init__(self, *arg, **kw)31 self.__response = None32 33 def _getResponse(self):34 '''Gets the response corresponding to this error35 36 @return the response37 '''38 return self.__response39 40 def _setResponse(self, value):41 '''Sets the response corresponding to this error.42 43 @param value: the response44 '''45 if not isinstance(value, Response):46 raise TypeError('"response" must be a %r, got %r' % (Response,47 type(value)))48 self.__response = value49 50 response = property(fget=_getResponse, fset=_setResponse,51 doc="SAML Response associated with this exception")52 29 53 30 -
TI12-security/trunk/ndg_saml/ndg/saml/saml2/binding/soap/server/wsgi/queryinterface.py
r7142 r7143 19 19 from ndg.soap.server.wsgi.middleware import SOAPMiddleware 20 20 from ndg.soap.etree import SOAPEnvelope 21 from ndg.soap.utils import str2Bool 22 21 22 from ndg.saml.utils import str2Bool 23 23 from ndg.saml.utils.factory import importModuleObject 24 24 from ndg.saml.xml import UnknownAttrProfile … … 27 27 from ndg.saml.saml2.core import (Response, Status, StatusCode, StatusMessage, 28 28 Issuer) 29 from ndg.saml.saml2.binding.soap import SOAPBindingInvalidResponse 29 30 30 31 … … 37 38 38 39 40 class QueryIssueInstantInvalid(SOAPBindingInvalidResponse): 41 """Invalid timestamp for incoming query""" 42 43 39 44 class SOAPQueryInterfaceMiddleware(SOAPMiddleware): 40 45 """Implementation of SAML 2.0 SOAP Binding for Query/Request Binding … … 81 86 @param app: next middleware application in the chain 82 87 ''' 83 super(SOAPQueryInterfaceMiddleware, self).__init__( app, None)88 super(SOAPQueryInterfaceMiddleware, self).__init__() 84 89 85 90 self._app = app … … 89 94 self.__queryInterfaceKeyName = cls.DEFAULT_QUERY_INTERFACE_KEYNAME 90 95 self.__mountPath = None 91 self.mountPath = ['/']96 self.mountPath = '/' 92 97 self.__requestEnvelopeClass = None 93 98 self.__responseEnvelopeClass = None … … 354 359 355 360 # Ignore non-matching path 356 if not self.pathMatch: 361 if environ['PATH_INFO'] not in (self.mountPath, 362 self.mountPath + '/'): 357 363 return self._app(environ, start_response) 358 364 … … 394 400 log.exception("%r raised parsing incoming query: %s" % 395 401 (type(e), traceback.format_exc())) 396 samlResponse.statusCode.value = StatusCode.UNKNOWN_ATTR_PROFILE_URI 402 samlResponse.status.statusCode.value = \ 403 StatusCode.UNKNOWN_ATTR_PROFILE_URI 397 404 else: 398 405 # Check for Query Interface in environ -
TI12-security/trunk/ndg_saml/ndg/saml/test/binding/soap/__init__.py
r7142 r7143 10 10 __license__ = "http://www.apache.org/licenses/LICENSE-2.0" 11 11 __contact__ = "Philip.Kershaw@stfc.ac.uk" 12 __revision__ = '$Id :$'12 __revision__ = '$Id$' 13 13 import os 14 14 import unittest … … 42 42 self.app = paste.fixture.TestApp(wsgiapp) 43 43 44 BaseTestCase.__init__(self, *args, **kwargs)44 unittest.TestCase.__init__(self, *args, **kwargs) -
TI12-security/trunk/ndg_saml/ndg/saml/test/binding/soap/attribute-interface.ini
r7140 r7143 18 18 19 19 [app:TestApp] 20 paste.app_factory = ndg.s ecurity.test.unit.wsgi.saml:TestApp20 paste.app_factory = ndg.saml.test.binding.soap.test_soapattributeinterface:TestApp 21 21 22 22 [filter:SAMLSoapAttributeInterfaceFilter] 23 paste.filter_app_factory = ndg.s ecurity.server.wsgi.saml:SOAPQueryInterfaceMiddleware.filter_app_factory23 paste.filter_app_factory = ndg.saml.saml2.binding.soap.server.wsgi.queryinterface:SOAPQueryInterfaceMiddleware.filter_app_factory 24 24 prefix = saml. 25 25 saml.pathMatchList = /attributeauthority/saml -
TI12-security/trunk/ndg_saml/ndg/saml/test/binding/soap/authz-decision-interface.ini
r7142 r7143 1 1 # 2 2 # INI file for testing the SAML Authorisation Query interface. It uses a 3 # test stub for the Authorisation Service rather than 4 # ndg.security.server.wsgi.authzservice.AuthzServiceMiddleware. See, 5 # authz-service.ini to compare 3 # test stub for the Authorisation Service 6 4 # 7 5 # The %(here)s variable will be replaced with the parent directory of this file -
TI12-security/trunk/ndg_saml/ndg/saml/test/binding/soap/authz-service.ini
r7140 r7143 18 18 19 19 [app:TestApp] 20 paste.app_factory = ndg.s ecurity.test.unit.wsgi.saml:TestApp20 paste.app_factory = ndg.saml.test.binding.soap:TestApp 21 21 22 22 [filter:SAMLSoapAuthzDecisionInterfaceFilter] 23 paste.filter_app_factory = ndg.s ecurity.server.wsgi.saml:SOAPQueryInterfaceMiddleware.filter_app_factory23 paste.filter_app_factory = ndg.saml.saml2.binding.server.wsgi:SOAPQueryInterfaceMiddleware.filter_app_factory 24 24 prefix = saml. 25 25 saml.pathMatchList = /authorisationservice -
TI12-security/trunk/ndg_saml/ndg/saml/test/binding/soap/test_soapauthzdecisioninterface.py
r7142 r7143 64 64 65 65 authzDecisionStatement = AuthzDecisionStatement() 66 authzDecisionStatement.decision = DecisionType.PERMIT 67 authzDecisionStatement.resource = \ 68 TestAuthorisationServiceMiddleware.RESOURCE_URI 66 67 # Make some simple logic to simulate a full access policy 68 if query.resource == self.__class__.RESOURCE_URI: 69 if query.actions[0].value == Action.HTTP_GET_ACTION: 70 authzDecisionStatement.decision = DecisionType.PERMIT 71 else: 72 authzDecisionStatement.decision = DecisionType.DENY 73 else: 74 authzDecisionStatement.decision = DecisionType.INDETERMINATE 75 76 authzDecisionStatement.resource = query.resource 77 69 78 authzDecisionStatement.actions.append(Action()) 70 79 authzDecisionStatement.actions[-1].namespace = Action.GHPP_NS_URI … … 101 110 issuer="/O=Site A/CN=PEP", 102 111 subject="https://openid.localhost/philip.kershaw", 103 resource= None,112 resource=RESOURCE_URI, 104 113 action=Action.HTTP_GET_ACTION, 105 114 actionNs=Action.GHPP_NS_URI): … … 117 126 query.subject.nameID.format = "urn:ndg:saml:test:openid" 118 127 query.subject.nameID.value = subject 119 120 if resource is None: 121 query.resource = self.__class__.RESOURCE_URI 122 else: 123 query.resource = resource 128 129 query.resource = resource 124 130 125 131 query.actions.append(Action()) … … 162 168 return response 163 169 164 def test01 ValidQuery(self):170 def test01AccessGranted(self): 165 171 query = self._createAuthzDecisionQuery() 166 172 request = self._makeRequest(query=query) … … 187 193 self.assert_(samlResponse.assertions[0].authzDecisionStatements[0 188 194 ].decision == DecisionType.PERMIT) 189 190 191 class SOAPAuthzServiceMiddlewareTestCase( 192 SOAPAuthzDecisionInterfaceMiddlewareTestCase): 193 """Test the actual server side middleware 194 ndg.security.server.wsgi.authzservice.AuthzServiceMiddleware 195 rather than a test stub 196 """ 197 CONFIG_FILENAME = 'authz-service.ini' 198 RESOURCE_URI = 'http://localhost/dap/data/my.nc.dods?time[0:1:0]&lat' 199 ACCESS_DENIED_RESOURCE_URI = \ 200 'http://localhost/dap/data/test_accessDeniedToSecuredURI' 201 202 def __init__(self, *arg, **kw): 203 """Extend base init to include SAML Attribute Authority required by 204 Authorisation Service""" 205 super(SOAPAuthzDecisionInterfaceMiddlewareTestCase, self).__init__( 206 *arg, **kw) 207 self.startSiteAAttributeAuthority(withSSL=True, port=5443) 208 195 209 196 def test02AccessDenied(self): 210 cls = SOAPAuthzServiceMiddlewareTestCase 211 query = self._createAuthzDecisionQuery( 212 resource=cls.ACCESS_DENIED_RESOURCE_URI) 197 query = self._createAuthzDecisionQuery(action=Action.HTTP_POST_ACTION) 213 198 request = self._makeRequest(query=query) 214 199 … … 223 208 status=200) 224 209 print("Response status=%d" % response.status) 210 225 211 samlResponse = self._getSAMLResponse(response.body) 226 212 … … 233 219 self.assert_(samlResponse.assertions[0].authzDecisionStatements[0]) 234 220 self.assert_(samlResponse.assertions[0].authzDecisionStatements[0 235 ].decision == DecisionType.DENY) 236 237 221 ].decision == DecisionType.DENY) 222 223 def test03IndeterminateResponse(self): 224 query = self._createAuthzDecisionQuery( 225 resource=self.__class__.RESOURCE_URI + 'invalid') 226 request = self._makeRequest(query=query) 227 228 header = { 229 'soapAction': "http://www.oasis-open.org/committees/security", 230 'Content-length': str(len(request)), 231 'Content-type': 'text/xml' 232 } 233 response = self.app.post('/authorisationservice/', 234 params=request, 235 headers=header, 236 status=200) 237 print("Response status=%d" % response.status) 238 239 samlResponse = self._getSAMLResponse(response.body) 240 241 self.assert_(samlResponse.status.statusCode.value == \ 242 StatusCode.SUCCESS_URI) 243 self.assert_(samlResponse.inResponseTo == query.id) 244 self.assert_(samlResponse.assertions[0].subject.nameID.value == \ 245 query.subject.nameID.value) 246 self.assert_(samlResponse.assertions[0]) 247 self.assert_(samlResponse.assertions[0].authzDecisionStatements[0]) 248 self.assert_(samlResponse.assertions[0].authzDecisionStatements[0 249 ].decision == DecisionType.INDETERMINATE) 250 251 238 252 if __name__ == "__main__": 239 253 unittest.main() -
TI12-security/trunk/ndg_saml/ndg/saml/utils/__init__.py
r7130 r7143 34 34 format)[0:6])) 35 35 from datetime import datetime, timedelta 36 36 37 37 38 # Interpret a string as a boolean 39 str2Bool = lambda str: str.lower() in ("yes", "true", "t", "1") 40 41 38 42 class SAMLDateTime(object): 39 43 """Generic datetime formatting utility for SAML timestamps - XMLSchema
Note: See TracChangeset
for help on using the changeset viewer.