##// END OF EJS Templates
update custom auth per review...
Min RK -
Show More
@@ -1,40 +1,21 b''
1 """Tornado handlers logging into the notebook.
1 """Tornado handlers for logging into the notebook."""
2 2
3 Authors:
4
5 * Brian Granger
6 * Phil Elson
7 """
8
9 #-----------------------------------------------------------------------------
10 # Copyright (C) 2014 The IPython Development Team
11 #
12 # Distributed under the terms of the BSD License. The full license is in
13 # the file COPYING, distributed as part of this software.
14 #-----------------------------------------------------------------------------
15
16 #-----------------------------------------------------------------------------
17 # Imports
18 #-----------------------------------------------------------------------------
3 # Copyright (c) IPython Development Team.
4 # Distributed under the terms of the Modified BSD License.
19 5
20 6 import uuid
21 7
22 8 from tornado.escape import url_escape
23 from tornado import web
24 9
25 from IPython.config.configurable import Configurable
26 10 from IPython.lib.security import passwd_check
27 11
28 12 from ..base.handlers import IPythonHandler
29 13
30 #-----------------------------------------------------------------------------
31 # Handler
32 #-----------------------------------------------------------------------------
33 14
34 15 class LoginHandler(IPythonHandler):
35 """ The basic IPythonWebApplication login handler which authenticates with a
36 hashed password from the configuration.
16 """The basic tornado login handler
37 17
18 authenticates with a hashed password from the configuration.
38 19 """
39 20 def _render(self, message=None):
40 21 self.write(self.render_template('login.html',
@@ -47,12 +28,15 b' class LoginHandler(IPythonHandler):'
47 28 self.redirect(self.get_argument('next', default=self.base_url))
48 29 else:
49 30 self._render()
31
32 @property
33 def hashed_password(self):
34 return self.password_from_settings(self.settings)
50 35
51 36 def post(self):
52 hashed_password = self.password_from_configuration(self.application)
53 37 typed_password = self.get_argument('password', default=u'')
54 if self.login_available(self.application):
55 if passwd_check(hashed_password, typed_password):
38 if self.login_available(self.settings):
39 if passwd_check(self.hashed_password, typed_password):
56 40 self.set_secure_cookie(self.cookie_name, str(uuid.uuid4()))
57 41 else:
58 42 self._render(message={'error': 'Invalid password'})
@@ -67,20 +51,20 b' class LoginHandler(IPythonHandler):'
67 51 if ssl_options is None:
68 52 notebook_app.log.critical(warning + " and not using encryption. This "
69 53 "is not recommended.")
70 if not self.password_from_configuration(notebook_app):
54 if not notebook_app.password:
71 55 notebook_app.log.critical(warning + " and not using authentication. "
72 56 "This is highly insecure and not recommended.")
73 57
74 58 @staticmethod
75 def password_from_configuration(webapp):
76 """ Return the hashed password from the given NotebookWebApplication's configuration.
77
78 If there is no configured password, None will be returned.
59 def password_from_settings(settings):
60 """Return the hashed password from the tornado settings.
79 61
62 If there is no configured password, an empty string will be returned.
80 63 """
81 return webapp.settings['config']['NotebookApp'].get('password', None)
64 return settings.get('password', u'')
82 65
83 66 @classmethod
84 def login_available(cls, webapp):
67 def login_available(cls, settings):
85 68 """Whether this LoginHandler is needed - and therefore whether the login page should be displayed."""
86 return bool(cls.password_from_configuration(webapp))
69 return bool(cls.password_from_settings(settings))
70
@@ -88,14 +88,12 b' class AuthenticatedHandler(web.RequestHandler):'
88 88
89 89 @property
90 90 def logged_in(self):
91 """Is a user currently logged in?
92
93 """
91 """Is a user currently logged in?"""
94 92 user = self.get_current_user()
95 93 return (user and not user == 'anonymous')
96 94
97 95 @property
98 def _login_handler(self):
96 def login_handler(self):
99 97 """Return the login handler for this application."""
100 98 return self.settings['login_handler_class']
101 99
@@ -107,7 +105,7 b' class AuthenticatedHandler(web.RequestHandler):'
107 105 whether the user is already logged in or not.
108 106
109 107 """
110 return bool(self._login_handler.login_available(self.application))
108 return bool(self.login_handler.login_available(self.settings))
111 109
112 110
113 111 class IPythonHandler(AuthenticatedHandler):
General Comments 0
You need to be logged in to leave comments. Login now