From 195ea8e15ac3822c1524ee4742ec42ca76638876 Mon Sep 17 00:00:00 2001 From: Guillem Anguera Date: Fri, 12 Feb 2016 23:30:42 +0100 Subject: Send password_manager as a general application setting instead of per handler --- libmproxy/web/app.py | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) (limited to 'libmproxy/web/app.py') diff --git a/libmproxy/web/app.py b/libmproxy/web/app.py index 55711837..2c45a1dc 100644 --- a/libmproxy/web/app.py +++ b/libmproxy/web/app.py @@ -48,23 +48,20 @@ class BasicAuth(object): self._transforms = [] self.finish() - def initialize(self, **kwargs): - self.wauthenticator = kwargs.get("wauthenticator") - def prepare(self): - if self.wauthenticator: + wauthenticator = self.application.settings['wauthenticator'] + if wauthenticator: auth_header = self.request.headers.get('Authorization') if auth_header is None or not auth_header.startswith('Basic '): self.set_auth_headers() else: self.auth_decoded = base64.decodestring(auth_header[6:]) self.username, self.password = self.auth_decoded.split(':', 2) - if not self.wauthenticator.test(self.username, self.password): + if not wauthenticator.test(self.username, self.password): self.set_auth_headers() raise APIError(401, "Invalid username or password.") - class RequestHandler(BasicAuth, tornado.web.RequestHandler): def set_default_headers(self): @@ -311,9 +308,6 @@ class Application(tornado.web.Application): def __init__(self, master, debug, wauthenticator): self.master = master - self.additional_args = dict( - wauthenticator=wauthenticator, - ) handlers = [ (r"/", IndexHandler), (r"/filter-help", FiltHelp), @@ -330,14 +324,12 @@ class Application(tornado.web.Application): (r"/settings", Settings), (r"/clear", ClearAll), ] - for i, handler in enumerate(handlers): - handlers[i] += (self.additional_args,) - settings = dict( template_path=os.path.join(os.path.dirname(__file__), "templates"), static_path=os.path.join(os.path.dirname(__file__), "static"), xsrf_cookies=True, cookie_secret=os.urandom(256), debug=debug, + wauthenticator=wauthenticator, ) super(Application, self).__init__(handlers, **settings) -- cgit v1.2.3