comparison rhodecode/lib/auth.py @ 3173:db0871d942b6 beta

adde cleanup username flag into get_container_username function
author Marcin Kuzminski <marcin@python-works.com>
date Sat, 19 Jan 2013 16:35:06 +0100
parents 264d9c930c17
children cd50d1b5f35b 6c28533d122c
comparison
equal deleted inserted replaced
3172:264d9c930c17 3173:db0871d942b6
268 log.debug('User %s is now logged in by container authentication', 268 log.debug('User %s is now logged in by container authentication',
269 user.username) 269 user.username)
270 return user 270 return user
271 271
272 272
273 def get_container_username(environ, config): 273 def get_container_username(environ, config, clean_username=False):
274 """
275 Get's the container_auth username (or email). It tries to get username
276 from REMOTE_USER if container_auth_enabled is enabled, if that fails
277 it tries to get username from HTTP_X_FORWARDED_USER if proxypass_auth_enabled
278 is enabled. clean_username extracts the username from this data if it's
279 having @ in it.
280
281 :param environ:
282 :param config:
283 :param clean_username:
284 """
274 username = None 285 username = None
275 286
276 if str2bool(config.get('container_auth_enabled', False)): 287 if str2bool(config.get('container_auth_enabled', False)):
277 from paste.httpheaders import REMOTE_USER 288 from paste.httpheaders import REMOTE_USER
278 username = REMOTE_USER(environ) 289 username = REMOTE_USER(environ)
280 291
281 if not username and str2bool(config.get('proxypass_auth_enabled', False)): 292 if not username and str2bool(config.get('proxypass_auth_enabled', False)):
282 username = environ.get('HTTP_X_FORWARDED_USER') 293 username = environ.get('HTTP_X_FORWARDED_USER')
283 log.debug('extracted HTTP_X_FORWARDED_USER:%s' % (username)) 294 log.debug('extracted HTTP_X_FORWARDED_USER:%s' % (username))
284 295
285 if username: 296 if username and clean_username:
286 # Removing realm and domain from username 297 # Removing realm and domain from username
287 username = username.partition('@')[0] 298 username = username.partition('@')[0]
288 username = username.rpartition('\\')[2] 299 username = username.rpartition('\\')[2]
289 log.debug('Received username %s from container' % username) 300 log.debug('Received username %s from container' % username)
290 301