|
1 | | -# $Id: client.py,v 1.211.2.1 2005-01-05 22:02:05 richard Exp $ |
| 1 | +# $Id: client.py,v 1.211.2.2 2005-06-24 05:28:24 richard Exp $ |
2 | 2 |
|
3 | 3 | """WWW request handler (also used in the stand-alone server). |
4 | 4 | """ |
@@ -396,32 +396,33 @@ def determine_user(self): |
396 | 396 |
|
397 | 397 | # first up, try the REMOTE_USER var (from HTTP Basic Auth handled |
398 | 398 | # by a front-end HTTP server) |
399 | | - if self.env.has_key('REMOTE_USER'): |
400 | | - user = self.env['REMOTE_USER'] |
401 | | - else: |
402 | | - user = 'anonymous' |
| 399 | + use_http_auth = self.instance.config['WEB_HTTP_AUTH'] == 'yes' |
| 400 | + user = 'anonymous' |
| 401 | + if use_http_auth: |
| 402 | + if self.env.has_key('REMOTE_USER'): |
| 403 | + user = self.env['REMOTE_USER'] |
| 404 | + # try handling Basic Auth ourselves |
| 405 | + elif self.env.get('HTTP_AUTHORIZATION', ''): |
| 406 | + auth = self.env['HTTP_AUTHORIZATION'] |
| 407 | + scheme, challenge = auth.split(' ', 1) |
| 408 | + if scheme.lower() == 'basic': |
| 409 | + try: |
| 410 | + decoded = base64.decodestring(challenge) |
| 411 | + except TypeError: |
| 412 | + # invalid challenge |
| 413 | + pass |
| 414 | + username, password = decoded.split(':') |
| 415 | + try: |
| 416 | + login = self.get_action_class('login')(self) |
| 417 | + login.verifyLogin(username, password) |
| 418 | + except LoginError, err: |
| 419 | + self.make_user_anonymous() |
| 420 | + self.response_code = 403 |
| 421 | + raise Unauthorised, err |
| 422 | + |
| 423 | + user = username |
403 | 424 |
|
404 | | - # try handling Basic Auth ourselves |
405 | | - if (user == 'anonymous') and self.env.get('HTTP_AUTHORIZATION', ''): |
406 | | - scheme, challenge = self.env['HTTP_AUTHORIZATION'].split(' ', 1) |
407 | | - if scheme.lower() == 'basic': |
408 | | - try: |
409 | | - decoded = base64.decodestring(challenge) |
410 | | - except TypeError: |
411 | | - # invalid challenge |
412 | | - pass |
413 | | - username, password = decoded.split(':') |
414 | | - try: |
415 | | - self.get_action_class('login')(self).verifyLogin( |
416 | | - username, password) |
417 | | - except LoginError, err: |
418 | | - self.make_user_anonymous() |
419 | | - self.response_code = 403 |
420 | | - raise Unauthorised, err |
421 | | - |
422 | | - user = username |
423 | | - |
424 | | - # look up the user session cookie (may override the REMOTE_USER) |
| 425 | + # look up the user session cookie (may override the HTTP Basic Auth) |
425 | 426 | cookie = self.cookie |
426 | 427 | if (cookie.has_key(self.cookie_name) and |
427 | 428 | cookie[self.cookie_name].value != 'deleted'): |
|
0 commit comments