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

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@3914
Revision 3914, 2.5 KB checked in by pjkersha, 12 years ago (diff)
  • New ndg.security.common.zsi_util.httpproxy.ProxyHTTPConnection class replaces urllib2client - easier to fit into existing ZSI client framework.
  • Further OpenID integration into Single Sign On Service. User now authenticates OK but patches needed to AuthKit? + need to handle return_to URL dynamically according to page visited before WAYF call.
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
14from sso.config.ssoServiceMiddleware import SSOMiddleware
15import logging
16log = logging.getLogger(__name__)
17
18def make_app(global_conf, full_stack=True, **app_conf):
19    """Create a Pylons WSGI application and return it
20
21    ``global_conf``
22        The inherited configuration for this application. Normally from
23        the [DEFAULT] section of the Paste ini file.
24
25    ``full_stack``
26        Whether or not this application provides a full WSGI stack (by
27        default, meaning it handles its own exceptions and errors).
28        Disable full_stack when this application is "managed" by
29        another WSGI middleware.
30
31    ``app_conf``
32        The application's local configuration. Normally specified in the
33        [app:<name>] section of the Paste ini file (where <name>
34        defaults to main).
35    """
36    # Configure the Pylons environment
37    load_environment(global_conf, app_conf)
38
39    # The Pylons WSGI app
40    app = PylonsApp()
41
42    # CUSTOM MIDDLEWARE HERE (filtered by error handling middlewares)
43    app = SSOMiddleware(app, app_conf['configfile'], app.globals)
44   
45    # OpenID Middleware
46    if app.globals.ndg.security.server.ssoservice.cfg.enableOpenID:
47        import authkit.authenticate
48        from beaker.middleware import SessionMiddleware
49       
50        app = authkit.authenticate.middleware(app, app_conf)
51        app = SessionMiddleware(app)#,key='authkit.open_id',secret='some secret')
52        log.info('OpenID is enabled')
53
54    if asbool(full_stack):
55        # Handle Python exceptions
56        app = ErrorHandler(app, global_conf, error_template=error_template,
57                           **config['pylons.errorware'])
58
59        # Display error documents for 401, 403, 404 status codes (and
60        # 500 when debug is disabled)
61        app = ErrorDocuments(app, global_conf, mapper=error_mapper, **app_conf)
62
63    # Establish the Registry for this application
64    app = RegistryManager(app)
65
66    # Static files
67    javascripts_app = StaticJavascripts()
68    static_app = StaticURLParser(config['pylons.paths']['static_files'])
69    app = Cascade([static_app, javascripts_app, app])
70    return app
Note: See TracBrowser for help on using the repository browser.