Mercurial > kallithea
comparison rhodecode/lib/base.py @ 2165:dc2584ba5fbc
merged beta into default branch
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Wed, 28 Mar 2012 19:54:16 +0200 |
parents | 79a95f338fd0 9f5582151d53 |
children | a437a986d399 |
comparison
equal
deleted
inserted
replaced
2097:8fd6650bb436 | 2165:dc2584ba5fbc |
---|---|
5 import logging | 5 import logging |
6 import time | 6 import time |
7 import traceback | 7 import traceback |
8 | 8 |
9 from paste.auth.basic import AuthBasicAuthenticator | 9 from paste.auth.basic import AuthBasicAuthenticator |
10 from paste.httpexceptions import HTTPUnauthorized, HTTPForbidden | |
11 from paste.httpheaders import WWW_AUTHENTICATE | |
10 | 12 |
11 from pylons import config, tmpl_context as c, request, session, url | 13 from pylons import config, tmpl_context as c, request, session, url |
12 from pylons.controllers import WSGIController | 14 from pylons.controllers import WSGIController |
13 from pylons.controllers.util import redirect | 15 from pylons.controllers.util import redirect |
14 from pylons.templating import render_mako as render | 16 from pylons.templating import render_mako as render |
15 | 17 |
16 from rhodecode import __version__, BACKENDS | 18 from rhodecode import __version__, BACKENDS |
17 | 19 |
18 from rhodecode.lib import str2bool, safe_unicode | 20 from rhodecode.lib.utils2 import str2bool, safe_unicode |
19 from rhodecode.lib.auth import AuthUser, get_container_username, authfunc,\ | 21 from rhodecode.lib.auth import AuthUser, get_container_username, authfunc,\ |
20 HasPermissionAnyMiddleware, CookieStoreWrapper | 22 HasPermissionAnyMiddleware, CookieStoreWrapper |
21 from rhodecode.lib.utils import get_repo_slug, invalidate_cache | 23 from rhodecode.lib.utils import get_repo_slug, invalidate_cache |
22 from rhodecode.model import meta | 24 from rhodecode.model import meta |
23 | 25 |
24 from rhodecode.model.db import Repository | 26 from rhodecode.model.db import Repository |
25 from rhodecode.model.notification import NotificationModel | 27 from rhodecode.model.notification import NotificationModel |
26 from rhodecode.model.scm import ScmModel | 28 from rhodecode.model.scm import ScmModel |
27 | 29 |
28 log = logging.getLogger(__name__) | 30 log = logging.getLogger(__name__) |
31 | |
32 | |
33 class BasicAuth(AuthBasicAuthenticator): | |
34 | |
35 def __init__(self, realm, authfunc, auth_http_code=None): | |
36 self.realm = realm | |
37 self.authfunc = authfunc | |
38 self._rc_auth_http_code = auth_http_code | |
39 | |
40 def build_authentication(self): | |
41 head = WWW_AUTHENTICATE.tuples('Basic realm="%s"' % self.realm) | |
42 if self._rc_auth_http_code and self._rc_auth_http_code == '403': | |
43 # return 403 if alternative http return code is specified in | |
44 # RhodeCode config | |
45 return HTTPForbidden(headers=head) | |
46 return HTTPUnauthorized(headers=head) | |
29 | 47 |
30 | 48 |
31 class BaseVCSController(object): | 49 class BaseVCSController(object): |
32 | 50 |
33 def __init__(self, application, config): | 51 def __init__(self, application, config): |
34 self.application = application | 52 self.application = application |
35 self.config = config | 53 self.config = config |
36 # base path of repo locations | 54 # base path of repo locations |
37 self.basepath = self.config['base_path'] | 55 self.basepath = self.config['base_path'] |
38 #authenticate this mercurial request using authfunc | 56 #authenticate this mercurial request using authfunc |
39 self.authenticate = AuthBasicAuthenticator('', authfunc) | 57 self.authenticate = BasicAuth('', authfunc, |
58 config.get('auth_ret_code')) | |
40 self.ipaddr = '0.0.0.0' | 59 self.ipaddr = '0.0.0.0' |
41 | 60 |
42 def _handle_request(self, environ, start_response): | 61 def _handle_request(self, environ, start_response): |
43 raise NotImplementedError() | 62 raise NotImplementedError() |
44 | 63 |