Skip to content

Commit

Permalink
Move Authorizer to existing jupyter_server.auth
Browse files Browse the repository at this point in the history
since it's a public API packages should import,
let's not nest it deep in services.auth.authorizer
  • Loading branch information
minrk committed Feb 1, 2022
1 parent b0461c7 commit e132169
Show file tree
Hide file tree
Showing 28 changed files with 34 additions and 26 deletions.
4 changes: 2 additions & 2 deletions docs/source/operators/security.rst
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ follows:

.. sourcecode:: python

from jupyter_server.services.auth.authorizer import Authorizer
from jupyter_server.auth import Authorizer

class MyAuthorizationManager(Authorizer):
"""Class for authorizing access to resources in the Jupyter Server.
Expand Down Expand Up @@ -230,7 +230,7 @@ follows:
return True # implement your authorization logic here

The ``is_authorized()`` method will automatically be called whenever a handler is decorated with
``@authorized`` (from ``jupyter_server.services.auth``), similarly to the
``@authorized`` (from ``jupyter_server.auth``), similarly to the
``@authenticated`` decorator for authorization (from ``tornado.web``).

Security in notebook documents
Expand Down
2 changes: 1 addition & 1 deletion examples/authorization/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ To add a custom authorization system to the Jupyter Server, you will need to wri
The examples below demonstrate some basic implementations of an `Authorizer`.

```python
from jupyter_server.services.auth.authorizer import Authorizer
from jupyter_server.auth import Authorizer


class MyCustomAuthorizer(Authorizer):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from jupyter_server.services.auth.authorizer import Authorizer
from jupyter_server.auth import Authorizer


class ReadOnly(Authorizer):
Expand Down
2 changes: 1 addition & 1 deletion examples/authorization/jupyter_nbclassic_rw_config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from jupyter_server.services.auth.authorizer import Authorizer
from jupyter_server.auth import Authorizer


class ReadWriteOnly(Authorizer):
Expand Down
2 changes: 1 addition & 1 deletion examples/authorization/jupyter_temporary_config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from jupyter_server.services.auth.authorizer import Authorizer
from jupyter_server.auth import Authorizer


class TemporaryServerPersonality(Authorizer):
Expand Down
2 changes: 2 additions & 0 deletions jupyter_server/auth/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
from .authorizer import * # noqa
from .decorator import authorized # noqa
from .security import passwd # noqa
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
The default authorizer (AllowAllAuthorizer)
allows all authenticated requests
.. versionadded:: 2.0
"""
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.
Expand All @@ -27,6 +28,8 @@ class Authorizer(LoggingConfigurable):
The authorization check will only be applied to requests
that have already been authenticated.
.. versionadded:: 2.0
"""

def is_authorized(self, handler: JupyterHandler, user: str, action: str, resource: str) -> bool:
Expand Down Expand Up @@ -54,6 +57,8 @@ class AllowAllAuthorizer(Authorizer):
"""A no-op implementation of the Authorizer
This authorizer allows all authenticated requests.
.. versionadded:: 2.0
"""

def is_authorized(self, handler: JupyterHandler, user: str, action: str, resource: str) -> bool:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ def authorized(
Helpful for adding an 'authorization' layer to
a REST API.
.. versionadded:: 2.0
Parameters
----------
action : str
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion jupyter_server/files/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

from tornado import web

from jupyter_server.auth import authorized
from jupyter_server.base.handlers import JupyterHandler
from jupyter_server.services.auth.decorator import authorized
from jupyter_server.utils import ensure_async


Expand Down
2 changes: 1 addition & 1 deletion jupyter_server/kernelspecs/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from ..base.handlers import JupyterHandler
from ..services.kernelspecs.handlers import kernel_name_regex
from jupyter_server.services.auth.decorator import authorized
from jupyter_server.auth import authorized


AUTH_RESOURCE = "kernelspecs"
Expand Down
2 changes: 1 addition & 1 deletion jupyter_server/nbconvert/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from ..base.handlers import FilesRedirectHandler
from ..base.handlers import JupyterHandler
from ..base.handlers import path_regex
from jupyter_server.services.auth.decorator import authorized
from jupyter_server.auth import authorized
from jupyter_server.utils import ensure_async


Expand Down
2 changes: 1 addition & 1 deletion jupyter_server/serverapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
GatewaySessionManager,
GatewayClient,
)
from jupyter_server.services.auth.authorizer import Authorizer, AllowAllAuthorizer
from jupyter_server.auth.authorizer import Authorizer, AllowAllAuthorizer

from jupyter_server.auth.login import LoginHandler
from jupyter_server.auth.logout import LogoutHandler
Expand Down
2 changes: 1 addition & 1 deletion jupyter_server/services/api/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from ...base.handlers import JupyterHandler
from jupyter_server._tz import isoformat
from jupyter_server._tz import utcfromtimestamp
from jupyter_server.services.auth.decorator import authorized
from jupyter_server.auth import authorized
from jupyter_server.utils import ensure_async


Expand Down
1 change: 0 additions & 1 deletion jupyter_server/services/auth/__init__.py

This file was deleted.

2 changes: 1 addition & 1 deletion jupyter_server/services/config/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from tornado import web

from ...base.handlers import APIHandler
from jupyter_server.services.auth.decorator import authorized
from jupyter_server.auth import authorized


AUTH_RESOURCE = "config"
Expand Down
2 changes: 1 addition & 1 deletion jupyter_server/services/contents/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from jupyter_server.utils import ensure_async
from jupyter_server.utils import url_escape
from jupyter_server.utils import url_path_join
from jupyter_server.services.auth.decorator import authorized
from jupyter_server.auth import authorized


AUTH_RESOURCE = "contents"
Expand Down
2 changes: 1 addition & 1 deletion jupyter_server/services/kernels/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from jupyter_server.utils import ensure_async
from jupyter_server.utils import url_escape
from jupyter_server.utils import url_path_join
from jupyter_server.services.auth.decorator import authorized
from jupyter_server.auth import authorized


AUTH_RESOURCE = "kernels"
Expand Down
2 changes: 1 addition & 1 deletion jupyter_server/services/kernelspecs/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

from ...base.handlers import APIHandler
from ...utils import ensure_async, url_path_join, url_unescape
from jupyter_server.services.auth.decorator import authorized
from jupyter_server.auth import authorized


AUTH_RESOURCE = "kernelspecs"
Expand Down
2 changes: 1 addition & 1 deletion jupyter_server/services/nbconvert/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from tornado import web

from ...base.handlers import APIHandler
from jupyter_server.services.auth.decorator import authorized
from jupyter_server.auth import authorized


AUTH_RESOURCE = "nbconvert"
Expand Down
2 changes: 1 addition & 1 deletion jupyter_server/services/security/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from . import csp_report_uri
from ...base.handlers import APIHandler
from jupyter_server.services.auth.decorator import authorized
from jupyter_server.auth import authorized


AUTH_RESOURCE = "csp"
Expand Down
2 changes: 1 addition & 1 deletion jupyter_server/services/sessions/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from ...base.handlers import APIHandler
from jupyter_server.utils import ensure_async
from jupyter_server.utils import url_path_join
from jupyter_server.services.auth.decorator import authorized
from jupyter_server.auth import authorized


AUTH_RESOURCE = "sessions"
Expand Down
2 changes: 1 addition & 1 deletion jupyter_server/services/shutdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
from tornado import ioloop
from tornado import web

from jupyter_server.auth import authorized
from jupyter_server.base.handlers import JupyterHandler
from jupyter_server.services.auth.decorator import authorized


AUTH_RESOURCE = "server"
Expand Down
2 changes: 1 addition & 1 deletion jupyter_server/terminal/api_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from tornado import web

from ..base.handlers import APIHandler
from jupyter_server.services.auth.decorator import authorized
from jupyter_server.auth import authorized


AUTH_RESOURCE = "terminals"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
from tornado.httpclient import HTTPClientError
from tornado.websocket import WebSocketHandler

from jupyter_server.services.auth.authorizer import Authorizer
from jupyter_server.services.auth.utils import HTTP_METHOD_TO_AUTH_ACTION
from jupyter_server.services.auth.utils import match_url_to_resource
from jupyter_server.auth.authorizer import Authorizer
from jupyter_server.auth.utils import HTTP_METHOD_TO_AUTH_ACTION
from jupyter_server.auth.utils import match_url_to_resource
from jupyter_server.services.security import csp_report_uri


Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest

from jupyter_server.services.auth.utils import match_url_to_resource
from jupyter_server.auth.utils import match_url_to_resource


@pytest.mark.parametrize(
Expand Down
Empty file.
2 changes: 1 addition & 1 deletion jupyter_server/view/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from ..utils import ensure_async
from ..utils import url_escape
from ..utils import url_path_join
from jupyter_server.services.auth.decorator import authorized
from jupyter_server.auth import authorized


AUTH_RESOURCE = "contents"
Expand Down

0 comments on commit e132169

Please sign in to comment.