def get_container_username(environ, config, clean_username=False): """ Get's the container_auth username (or email). It tries to get username from REMOTE_USER if container_auth_enabled is enabled, if that fails it tries to get username from HTTP_X_FORWARDED_USER if proxypass_auth_enabled is enabled. clean_username extracts the username from this data if it's having @ in it. :param environ: :param config: :param clean_username: """ username = None if str2bool(config.get('container_auth_enabled', False)): from paste.httpheaders import REMOTE_USER username = REMOTE_USER(environ) log.debug('extracted REMOTE_USER:%s' % (username)) if not username and str2bool(config.get('proxypass_auth_enabled', False)): username = environ.get('HTTP_X_FORWARDED_USER') log.debug('extracted HTTP_X_FORWARDED_USER:%s' % (username)) if username and clean_username: # Removing realm and domain from username username = username.partition('@')[0] username = username.rpartition('\\')[2] log.debug('Received username %s from container' % username) return username
def get_container_username(environ, config): username = None if str2bool(config.get('container_auth_enabled', False)): from paste.httpheaders import REMOTE_USER username = REMOTE_USER(environ) if not username and str2bool(config.get('proxypass_auth_enabled', False)): username = environ.get('HTTP_X_FORWARDED_USER') if username: # Removing realm and domain from username username = username.partition('@')[0] username = username.rpartition('\\')[2] log.debug('Received username %s from container' % username) return username