source: TI12-security/trunk/ndg_saml/ndg/soap/server/wsgi/middleware.py @ 7560

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI12-security/trunk/ndg_saml/ndg/soap/server/wsgi/middleware.py@7560
Revision 7560, 2.9 KB checked in by pjkersha, 9 years ago (diff)

Merged ndg.soap back into ndg_saml package - simpler to keep it together.

Line 
1"""NDG Security SOAP Service Middleware
2
3NERC DataGrid Project
4
5"""
6__author__ = "P J Kershaw"
7__date__ = "27/05/08"
8__copyright__ = "(C) 2009 Science and Technology Facilities Council"
9__contact__ = "Philip.Kershaw@stfc.ac.uk"
10__license__ = "BSD - see LICENSE file in top-level directory"
11__revision__ = "$Id: $"
12import logging
13log = logging.getLogger(__name__)
14
15     
16class SOAPMiddlewareError(Exception):
17    """Base error handling exception class for the SOAP WSGI middleware module
18    """
19    _log = log
20    def __init__(self, *arg, **kw):
21        '''Extend to enable logging of errors'''
22        if len(arg) > 0:
23            self.__class__._log.error(arg[0])
24        Exception.__init__(self, *arg, **kw)
25
26
27class SOAPMiddlewareReadError(SOAPMiddlewareError):
28    """SOAP Middleware read error"""
29
30
31class SOAPMiddlewareConfigError(SOAPMiddlewareError):
32    """SOAP Middleware configuration error"""
33
34
35class SOAPMiddleware(object):
36    """SOAP WSGI base class"""
37    SOAP_FAULT_SET_KEYNAME = 'ndg.security.server.wsgi.soap.soapFault'
38    SOAP_ACTION_ENVIRON_KEYNAME = 'HTTP_SOAPACTION'
39   
40    _str2Bool = lambda str: str.lower() in ["yes", "true", "t", "1"]
41    str2Bool = staticmethod(_str2Bool)
42       
43    @classmethod
44    def isSOAPMessage(cls, environ):
45        '''Generic method to filter out non-soap messages
46       
47        TODO: is HTTP_SOAPACTION only set for WSDL doc-literal wrapped style
48        generated content? - If so this test should be moved'''
49        return environ.get('REQUEST_METHOD', '') == 'POST' and \
50               environ.get(cls.SOAP_ACTION_ENVIRON_KEYNAME) is not None
51
52    @classmethod
53    def isSOAPFaultSet(cls, environ):
54        '''Check environment for SOAP fault flag set.  This variable is set
55        from exception2SOAPFault'''
56        return environ.get(cls.SOAP_FAULT_SET_KEYNAME, False) == True
57       
58    @classmethod
59    def filter_app_factory(cls, app, global_conf, **app_conf):
60        """Set-up using a Paste app factory pattern. 
61       
62        @type app: callable following WSGI interface
63        @param app: next middleware application in the chain     
64        @type global_conf: dict       
65        @param global_conf: PasteDeploy global configuration dictionary
66        @type app_conf: dict       
67        @param app_conf: PasteDeploy application specific configuration
68        dictionary
69        """
70        app = cls(app)
71        app.initialise(global_conf, **app_conf)
72       
73        return app
74   
75    def initialise(self, global_conf, **app_conf):
76        """Set attributes from keyword dictionaries global and or app_conf
77        @type global_conf: dict       
78        @param global_conf: PasteDeploy global configuration dictionary
79        @type prefix: basestring
80        @param prefix: prefix for configuration items
81        @type app_conf: dict       
82        @param app_conf: PasteDeploy application specific configuration
83        """
84        raise NotImplementedError()
Note: See TracBrowser for help on using the repository browser.