Skip to content

Commit

Permalink
handle allow_all variation for JupyterHub 4/5
Browse files Browse the repository at this point in the history
  • Loading branch information
minrk committed Sep 17, 2024
1 parent bb8474b commit 3f59d17
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
18 changes: 13 additions & 5 deletions ldapauthenticator/ldapauthenticator.py
Original file line number Diff line number Diff line change
Expand Up @@ -556,11 +556,19 @@ async def authenticate(self, handler, data):
return {"name": username, "auth_state": auth_state}

async def check_allowed(self, username, auth_model):
allowed = super().check_allowed(username, auth_model)
if isawaitable(allowed):
allowed = await allowed
if allowed is True:
return True
if not hasattr(self, "allow_all"):
# super for JupyterHub < 5
# default behavior: no allow config => allow all
if not self.allowed_users and not self.allowed_groups:
return True
if self.allowed_users and username in self.allowed_users:
return True
else:
allowed = super().check_allowed(username, auth_model)
if isawaitable(allowed):
allowed = await allowed
if allowed is True:
return True
if self.allowed_groups:
# check allowed groups
in_groups = set((auth_model.get("auth_state") or {}).get("ldap_groups", []))
Expand Down
7 changes: 6 additions & 1 deletion ldapauthenticator/tests/test_ldapauthenticator.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,12 @@ async def test_allow_config(authenticator):
)
assert authorized is None
# allow_all grants access
authenticator.allow_all = True
if hasattr(authenticator, "allow_all"):
authenticator.allow_all = True
else:
# clear allow config for JupyterHub < 5
authenticator.allowed_groups = []
authenticator.allowed_users = set()
authorized = await authenticator.get_authenticated_user(
None, {"username": "professor", "password": "professor"}
)
Expand Down

0 comments on commit 3f59d17

Please sign in to comment.