Skip to content

Commit deb3d90

Browse files
authored
allow handlers to work without an authorizer in the Tornado settings (#717)
1 parent 07a1e7d commit deb3d90

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

jupyter_server/auth/decorator.py

+20-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"""
33
# Copyright (c) Jupyter Development Team.
44
# Distributed under the terms of the Modified BSD License.
5+
import warnings
56
from functools import wraps
67
from typing import Callable
78
from typing import Optional
@@ -13,6 +14,20 @@
1314
from .utils import HTTP_METHOD_TO_AUTH_ACTION
1415

1516

17+
def raise_no_authorizer_warning():
18+
warnings.warn(
19+
"The Tornado web application does not have an 'authorizer' defined "
20+
"in its settings. In future releases of jupyter_server, this will "
21+
"be a required key for all subclasses of `JupyterHandler`. For an "
22+
"example, see the jupyter_server source code for how to "
23+
"add an authorizer to the tornado settings: "
24+
"https://github.com/jupyter-server/jupyter_server/blob/"
25+
"653740cbad7ce0c8a8752ce83e4d3c2c754b13cb/jupyter_server/serverapp.py"
26+
"#L234-L256",
27+
# stacklevel=2
28+
)
29+
30+
1631
def authorized(
1732
action: Optional[Union[str, Callable]] = None,
1833
resource: Optional[str] = None,
@@ -61,7 +76,11 @@ def inner(self, *args, **kwargs):
6176
raise HTTPError(status_code=403, log_message=message)
6277
# If the user is allowed to do this action,
6378
# call the method.
64-
if self.authorizer.is_authorized(self, user, action, resource):
79+
if not self.authorizer:
80+
with warnings.catch_warnings():
81+
warnings.simplefilter("once")
82+
raise_no_authorizer_warning()
83+
elif self.authorizer.is_authorized(self, user, action, resource):
6584
return method(self, *args, **kwargs)
6685
# else raise an exception.
6786
else:

jupyter_server/base/handlers.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ def login_available(self):
193193

194194
@property
195195
def authorizer(self):
196-
return self.settings["authorizer"]
196+
return self.settings.get("authorizer")
197197

198198

199199
class JupyterHandler(AuthenticatedHandler):

0 commit comments

Comments
 (0)