# HG changeset patch # User Marcin Kuzminski # Date 1274467803 -7200 # Node ID 93bd77e1f3c1187a37c80b288b19e6ad796006f0 # Parent 8dd7305fbc2d44ce96997799b1d498f363553a95 Changed auth basic handler only for mercurial request. diff -r 8dd7305fbc2d -r 93bd77e1f3c1 pylons_app/config/middleware.py --- a/pylons_app/config/middleware.py Fri May 21 20:37:34 2010 +0200 +++ b/pylons_app/config/middleware.py Fri May 21 20:50:03 2010 +0200 @@ -10,7 +10,6 @@ from paste.auth.basic import AuthBasicHandler from pylons_app.lib.simplehg import SimpleHg from pylons_app.config.environment import load_environment -from pylons_app.lib.auth import authfunc def make_app(global_conf, full_stack=True, static_files=True, **app_conf): """Create a Pylons WSGI application and return it @@ -45,7 +44,6 @@ # CUSTOM MIDDLEWARE HERE (filtered by error handling middlewares) app = SimpleHg(app, config) - app = AuthBasicHandler(app, config['repos_name'] + ' mercurial repository', authfunc) if asbool(full_stack): # Handle Python exceptions diff -r 8dd7305fbc2d -r 93bd77e1f3c1 pylons_app/lib/simplehg.py --- a/pylons_app/lib/simplehg.py Fri May 21 20:37:34 2010 +0200 +++ b/pylons_app/lib/simplehg.py Fri May 21 20:50:03 2010 +0200 @@ -1,19 +1,38 @@ -import os from mercurial.hgweb import hgweb from mercurial.hgweb.request import wsgiapplication -from pylons_app.lib.utils import make_ui, invalidate_cache +from paste.auth.basic import AuthBasicAuthenticator +from paste.httpheaders import REMOTE_USER, AUTH_TYPE from pylons.controllers.util import abort +from pylons_app.lib.auth import authfunc +from pylons_app.lib.utils import make_ui, invalidate_cache from webob.exc import HTTPNotFound +import os + class SimpleHg(object): def __init__(self, application, config): self.application = application self.config = config + #authenticate this mercurial request using + realm = '%s %s' % (config['repos_name'], 'mercurial repository') + self.authenticate = AuthBasicAuthenticator(realm, authfunc) def __call__(self, environ, start_response): if not is_mercurial(environ): return self.application(environ, start_response) else: + #=================================================================== + # AUTHENTICATE THIS MERCURIAL REQUEST + #=================================================================== + username = REMOTE_USER(environ) + if not username: + result = self.authenticate(environ) + if isinstance(result, str): + AUTH_TYPE.update(environ, 'basic') + REMOTE_USER.update(environ, result) + else: + return result.wsgi_application(environ, start_response) + try: repo_name = environ['PATH_INFO'].split('/')[1] except: @@ -50,6 +69,8 @@ hgserve.repo.ui = repoui return hgserve + + def is_mercurial(environ): """