Ticket #2310: web.auth.py.diff
| File web.auth.py.diff, 4.4 KB (added by anonymous, 3 years ago) |
|---|
-
\\rio-fs\p$\Python23\Lib\site-packages\trac\web\auth.py
old new 20 20 21 21 from trac.core import * 22 22 from trac.web.api import IAuthenticator, IRequestHandler 23 23 from trac.web.chrome import INavigationContributor 24 24 from trac.util import escape, hex_entropy, TRUE 25 25 26 LOWER = ['l', 'lo', 'lower'] 27 UPPER = ['u', 'up', 'upper'] 26 28 27 29 class LoginModule(Component): 28 30 """Implements user authentication based on HTTP authentication provided by 29 31 the web-server, combined with cookies for communicating the login 30 32 information across the whole site. 31 33 … … 48 50 elif req.incookie.has_key('trac_auth'): 49 51 authname = self._get_name_for_cookie(req, req.incookie['trac_auth']) 50 52 51 53 if not authname: 52 54 return None 53 55 54 ignore_case = self.env.config.get('trac', 'ignore_auth_case') 55 ignore_case = ignore_case.strip().lower() in TRUE 56 if ignore_case: 57 authname = authname.lower() 58 return authname 56 return self._fix_auth_id_case(req, authname) 59 57 60 58 # INavigationContributor methods 61 59 62 60 def get_active_navigation_item(self, req): 63 61 return 'login' 64 62 … … 82 80 elif req.path_info.startswith('/logout'): 83 81 self._do_logout(req) 84 82 self._redirect_back(req) 85 83 86 84 # Internal methods 87 85 86 def _fix_auth_id_case(self, req, auth_id): 87 fixed_id = auth_id 88 89 ignore_case = self.env.config.get('trac', 'ignore_auth_case') 90 ignore_case = ignore_case.strip().lower() in TRUE 91 if ignore_case: 92 fixed_id = fixed_id.lower() 93 94 auth_domain_case = self.env.config.get('trac', 'auth_domain_case') 95 lower_auth_domain_case = auth_domain_case.strip().lower() in LOWER 96 upper_auth_domain_case = auth_domain_case.strip().lower() in UPPER 97 change_domain_case = lower_auth_domain_case or upper_auth_domain_case 98 99 auth_username_case = self.env.config.get('trac', 'auth_username_case') 100 lower_auth_username_case = auth_username_case.strip().lower() in LOWER 101 upper_auth_username_case = auth_username_case.strip().lower() in UPPER 102 change_username_case = lower_auth_username_case or upper_auth_username_case 103 104 change_auth_case = change_domain_case or change_username_case 105 if change_domain_case: 106 expected_pair = fixed_id.split('\\') 107 has_domain_in_id = (len(expected_pair) == 2) 108 if has_domain_in_id: 109 domain_part = expected_pair[0] 110 username_part = expected_pair[1] 111 112 if lower_auth_domain_case: 113 domain_part = domain_part.lower() 114 if upper_auth_domain_case: 115 domain_part = domain_part.upper() 116 117 if lower_auth_username_case: 118 username_part = username_part.lower() 119 if upper_auth_username_case: 120 username_part = username_part.upper() 121 122 fixed_id = '%s\\%s' % (domain_part, username_part) 123 124 return fixed_id 125 88 126 def _do_login(self, req): 89 127 """Log the remote user in. 90 128 91 129 This function expects to be called when the remote user name is 92 130 available. The user name is inserted into the `auth_cookie` table and a 93 131 cookie identifying the user on subsequent requests is sent back to the … … 98 136 will be converted to lower case before being used. This is to avoid 99 137 problems on installations authenticating against Windows which is not 100 138 case sensitive regarding user names and domain names 101 139 """ 102 140 assert req.remote_user, 'Authentication information not available.' 103 141 104 remote_user = req.remote_user 105 ignore_case = self.env.config.get('trac', 'ignore_auth_case') 106 ignore_case = ignore_case.strip().lower() in TRUE 107 if ignore_case: 108 remote_user = remote_user.lower() 142 remote_user = self._fix_auth_id_case(req, req.remote_user) 109 143 110 144 assert req.authname in ('anonymous', remote_user), \ 111 145 'Already logged in as %s.' % req.authname 112 146 113 147 cookie = hex_entropy() 114 148 db = self.env.get_db_cnx()
