1 """Pylons middleware initialization"""
3 from beaker.middleware import SessionMiddleware
4 from paste.cascade import Cascade
5 from paste.registry import RegistryManager
6 from paste.urlparser import StaticURLParser
7 from paste.deploy.converters import asbool
8 from pylons.middleware import ErrorHandler, StatusCodeRedirect
9 from pylons.wsgiapp import PylonsApp
10 from routes.middleware import RoutesMiddleware
12 from ocsmanager.config.environment import load_environment
14 # from paste.auth.basic import AuthBasicHandler
15 # from ocsmanager.model.OCSAuthenticator import *
17 from NTLMAuthHandler import NTLMAuthHandler
19 def make_app(global_conf, full_stack=True, static_files=True, **app_conf):
20 """Create a Pylons WSGI application and return it
23 The inherited configuration for this application. Normally from
24 the [DEFAULT] section of the Paste ini file.
27 Whether this application provides a full WSGI stack (by default,
28 meaning it handles its own exceptions and errors). Disable
29 full_stack when this application is "managed" by another WSGI
33 Whether this application serves its own static files; disable
34 when another web server is responsible for serving them.
37 The application's local configuration. Normally specified in
38 the [app:<name>] section of the Paste ini file (where <name>
42 # Configure the Pylons environment
43 config = load_environment(global_conf, app_conf)
46 app = PylonsApp(config=config)
48 # Routing/Session Middleware
49 app = RoutesMiddleware(app, config['routes.map'])
50 app = SessionMiddleware(app, config)
52 # CUSTOM MIDDLEWARE HERE (filtered by error handling middlewares)
54 if asbool(full_stack):
55 # Handle Python exceptions
56 app = ErrorHandler(app, global_conf, **config['pylons.errorware'])
58 # Display error documents for 401, 403, 404 status codes (and
59 # 500 when debug is disabled)
60 if asbool(config['debug']):
61 app = StatusCodeRedirect(app, [417])
63 app = StatusCodeRedirect(app, [400, 401, 403, 404, 417, 500])
65 # authenticator = OCSAuthenticator(config)
66 # app = AuthBasicHandler(app, "OCSManager", authenticator)
67 app = NTLMAuthHandler(app)
69 # Establish the Registry for this application
70 app = RegistryManager(app)
72 if asbool(static_files):
74 static_app = StaticURLParser(config['pylons.paths']['static_files'])
75 app = Cascade([static_app, app])