source: TI12-security/trunk/python/ndg.security.server/ndg/security/server/sso/sso/config/middleware.py @ 3754

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI12-security/trunk/python/ndg.security.server/ndg/security/server/sso/sso/config/middleware.py@3754
Revision 3754, 2.1 KB checked in by pjkersha, 12 years ago (diff)
Line 
1"""Pylons middleware initialization"""
2from paste.cascade import Cascade
3from paste.registry import RegistryManager
4from paste.urlparser import StaticURLParser
5from paste.deploy.converters import asbool
6
7from pylons import config
8from pylons.error import error_template
9from pylons.middleware import error_mapper, ErrorDocuments, ErrorHandler, \
10    StaticJavascripts
11from pylons.wsgiapp import PylonsApp
12
13from sso.config.environment import load_environment
14
15from sso.config.ssoServiceMiddleware import SSOMiddleware
16
17def make_app(global_conf, full_stack=True, **app_conf):
18    """Create a Pylons WSGI application and return it
19
20    ``global_conf``
21        The inherited configuration for this application. Normally from
22        the [DEFAULT] section of the Paste ini file.
23
24    ``full_stack``
25        Whether or not this application provides a full WSGI stack (by
26        default, meaning it handles its own exceptions and errors).
27        Disable full_stack when this application is "managed" by
28        another WSGI middleware.
29
30    ``app_conf``
31        The application's local configuration. Normally specified in the
32        [app:<name>] section of the Paste ini file (where <name>
33        defaults to main).
34    """
35    # Configure the Pylons environment
36    load_environment(global_conf, app_conf)
37
38    # The Pylons WSGI app
39    app = PylonsApp()
40
41    # CUSTOM MIDDLEWARE HERE (filtered by error handling middlewares)
42    app = SSOMiddleware(app, app_conf['configfile'], app.globals)
43
44
45    if asbool(full_stack):
46        # Handle Python exceptions
47        app = ErrorHandler(app, global_conf, error_template=error_template,
48                           **config['pylons.errorware'])
49
50        # Display error documents for 401, 403, 404 status codes (and
51        # 500 when debug is disabled)
52        app = ErrorDocuments(app, global_conf, mapper=error_mapper, **app_conf)
53
54    # Establish the Registry for this application
55    app = RegistryManager(app)
56
57    # Static files
58    javascripts_app = StaticJavascripts()
59    static_app = StaticURLParser(config['pylons.paths']['static_files'])
60    app = Cascade([static_app, javascripts_app, app])
61    return app
Note: See TracBrowser for help on using the repository browser.