comparison hgext/acl.py @ 8846:b30775386d40

acl: support for getting authenticated user from web server (issue298) Previously, the acl extension just read the current system user, which is fine for direct file system access and SSH, but will not work for HTTP(S) as that would return the web server process user identity rather than the authenticated user. An empty user is returned if the user is not authenticated.
author Henrik Stuart <hg@hstuart.dk>
date Sun, 07 Jun 2009 20:31:38 +0200
parents cc7da5aae4cd
children e872ef2e6758
comparison
equal deleted inserted replaced
8845:296767acbb55 8846:b30775386d40
45 # glob pattern = user4, user5 45 # glob pattern = user4, user5
46 # ** = user6 46 # ** = user6
47 47
48 from mercurial.i18n import _ 48 from mercurial.i18n import _
49 from mercurial import util, match 49 from mercurial import util, match
50 import getpass 50 import getpass, urllib
51 51
52 def buildmatch(ui, repo, user, key): 52 def buildmatch(ui, repo, user, key):
53 '''return tuple of (match function, list enabled).''' 53 '''return tuple of (match function, list enabled).'''
54 if not ui.has_section(key): 54 if not ui.has_section(key):
55 ui.debug(_('acl: %s not enabled\n') % key) 55 ui.debug(_('acl: %s not enabled\n') % key)
70 'incoming changesets') % hooktype) 70 'incoming changesets') % hooktype)
71 if source not in ui.config('acl', 'sources', 'serve').split(): 71 if source not in ui.config('acl', 'sources', 'serve').split():
72 ui.debug(_('acl: changes have source "%s" - skipping\n') % source) 72 ui.debug(_('acl: changes have source "%s" - skipping\n') % source)
73 return 73 return
74 74
75 user = getpass.getuser() 75 user = None
76 if source == 'serve' and 'url' in kwargs:
77 url = kwargs['url'].split(':')
78 if url[0] == 'remote' and url[1].startswith('http'):
79 user = urllib.unquote(url[2])
80
81 if user is None:
82 user = getpass.getuser()
83
76 cfg = ui.config('acl', 'config') 84 cfg = ui.config('acl', 'config')
77 if cfg: 85 if cfg:
78 ui.readconfig(cfg, sections = ['acl.allow', 'acl.deny']) 86 ui.readconfig(cfg, sections = ['acl.allow', 'acl.deny'])
79 allow = buildmatch(ui, repo, user, 'acl.allow') 87 allow = buildmatch(ui, repo, user, 'acl.allow')
80 deny = buildmatch(ui, repo, user, 'acl.deny') 88 deny = buildmatch(ui, repo, user, 'acl.deny')