Changeset 1261
- Timestamp:
- 09/08/06 22:30:28 (2 years ago)
- Files:
-
- tracforgeplugin/0.10/tracforge/linker/auth.py (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
tracforgeplugin/0.10/tracforge/linker/auth.py
r1260 r1261 6 6 from trac.web.auth import LoginModule 7 7 from trac.web.main import _open_environment 8 from trac.env import Environment9 8 from trac.web.href import Href 10 9 from trac.util.html import escape, html … … 12 11 13 12 from urlparse import urlsplit 14 import inspect15 13 16 14 class TracForgeLoginModule(LoginModule): … … 45 43 doc='The smallest common URI for the whole TracForge setup') 46 44 47 real_get_header = Request.get_header48 49 45 implements(IRequestFilter) 50 46 51 def __init__(self):52 #Request.get_header = self._my_get_header53 pass54 55 47 def pre_process_request(self, req, handler): 56 #self.log.debug('TracForgeCookieMunger: Running')57 48 if req.path_info.startswith('/login') or req.path_info.startswith('/logout'): 58 #self.log.debug('TracForgeCookieMunger: Path match')59 49 def my_redirect(*args, **kwords): 60 #self.log.debug('TracForgeCookieMunger: Captured redirect!') 61 #self.log.debug('TracForgeCookieMunger: Pre munging\n%s'%req.outcookie) 50 # Munge the cookie path 62 51 if 'trac_auth' in req.outcookie: 63 52 assert not self.uri_root.startswith('http'), 'The tracforge uri_root must be set to relative path' 64 53 req.outcookie['trac_auth']['path'] = self.uri_root 65 #self.log.debug('TracForgeCookieMunger: Post munging\n%s'%req.outcookie)66 54 55 # Check to see if we should refer back to sibling Trac 67 56 referer = req.args.get('referer') 68 57 self.log.debug('TracForgeCookieMunger: Got referer as %r'%referer) … … 75 64 Request.redirect(req, *args, **kwords) 76 65 77 assert repr(req.redirect).startswith('<bound method') 66 assert repr(req.redirect).startswith('<bound method'), 'Someone else changed req.redirect first' 78 67 req.redirect = my_redirect 79 68 … … 81 70 82 71 def post_process_request(self, req, template, content_type): 83 #if req.path_info.startswith('/login'):84 # if 'trac_auth' in req.outcookie:85 # req.outcookie['trac_auth']['path'] = self.uri_root86 72 return (template, content_type) 87 73 88 # Internal methods89 def _my_redirect_back(self, req):90 """Modified version of LoginModule._redirect_back that checks91 to see if the target is in the tracforge URI."""92 self.log.debug('TracForgeCookieMunger: In evil redirect captor')93 referer = req.get_header('Referer')94 parts = urlsplit(referer)95 if referer and (not parts[2].startswith(self.uri_root) or not parts[1].startswith(req.server_name)):96 referer = None97 req.redirect(referer or req.abs_href())98 99 def _my_get_header(self, name):100 """Severe evil. Contact Noah Kantrowitz if you need to know what this does."""101 if name == 'Referer':102 try:103 stack = inspect.stack()104 for s in stack:105 if 'redirect' in s[3]:106 pass107 108 finally:109 del stack110 111 return TracForgeCookieMunger.real_get_header(self, name)
