Skip to content

Commit c6fbf68

Browse files
author
Alexander Smishlajev
committed
prefer http authorization over cookie sessions [SF#1396134]
1 parent 8b6fae1 commit c6fbf68

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

roundup/cgi/client.py

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $Id: client.py,v 1.217 2005-12-03 09:35:06 a1s Exp $
1+
# $Id: client.py,v 1.218 2006-01-09 09:14:27 a1s Exp $
22

33
"""WWW request handler (also used in the stand-alone server).
44
"""
@@ -415,22 +415,20 @@ def determine_language(self):
415415

416416
def determine_user(self):
417417
"""Determine who the user is"""
418-
# determine the uid to use
419418
self.opendb('admin')
420419

421420
# make sure we have the session Class
422421
self.clean_sessions()
423422
sessions = self.db.getSessionManager()
424423

425-
# first up, try the REMOTE_USER var (from HTTP Basic Auth handled
426-
# by a front-end HTTP server)
427-
use_http_auth = self.instance.config['WEB_HTTP_AUTH'] == 'yes'
428-
user = 'anonymous'
429-
if use_http_auth:
424+
user = None
425+
# first up, try http authorization if enabled
426+
if self.instance.config['WEB_HTTP_AUTH']:
430427
if self.env.has_key('REMOTE_USER'):
428+
# we have external auth (e.g. by Apache)
431429
user = self.env['REMOTE_USER']
432-
# try handling Basic Auth ourselves
433430
elif self.env.get('HTTP_AUTHORIZATION', ''):
431+
# try handling Basic Auth ourselves
434432
auth = self.env['HTTP_AUTHORIZATION']
435433
scheme, challenge = auth.split(' ', 1)
436434
if scheme.lower() == 'basic':
@@ -450,13 +448,11 @@ def determine_user(self):
450448

451449
user = username
452450

453-
# look up the user session cookie (may override the HTTP Basic Auth)
454-
cookie = self.cookie
455-
if (cookie.has_key(self.cookie_name) and
456-
cookie[self.cookie_name].value != 'deleted'):
457-
451+
# if user was not set by http authorization, try session cookie
452+
if (not user) and self.cookie.has_key(self.cookie_name) \
453+
and (self.cookie[self.cookie_name].value != 'deleted'):
458454
# get the session key from the cookie
459-
self.session = cookie[self.cookie_name].value
455+
self.session = self.cookie[self.cookie_name].value
460456
# get the user from the session
461457
try:
462458
# update the lifetime datestamp
@@ -466,8 +462,13 @@ def determine_user(self):
466462
# not valid, ignore id
467463
pass
468464

469-
# sanity check on the user still being valid, getting the userid
470-
# at the same time
465+
# if no user name set by http authorization or session cookie
466+
# the user is anonymous
467+
if not user:
468+
user = 'anonymous'
469+
470+
# sanity check on the user still being valid,
471+
# getting the userid at the same time
471472
try:
472473
self.userid = self.db.user.lookup(user)
473474
except (KeyError, TypeError):

0 commit comments

Comments
 (0)