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