Skip to content

Commit 3f59d17

Browse files
committed
handle allow_all variation for JupyterHub 4/5
1 parent bb8474b commit 3f59d17

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

ldapauthenticator/ldapauthenticator.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -556,11 +556,19 @@ async def authenticate(self, handler, data):
556556
return {"name": username, "auth_state": auth_state}
557557

558558
async def check_allowed(self, username, auth_model):
559-
allowed = super().check_allowed(username, auth_model)
560-
if isawaitable(allowed):
561-
allowed = await allowed
562-
if allowed is True:
563-
return True
559+
if not hasattr(self, "allow_all"):
560+
# super for JupyterHub < 5
561+
# default behavior: no allow config => allow all
562+
if not self.allowed_users and not self.allowed_groups:
563+
return True
564+
if self.allowed_users and username in self.allowed_users:
565+
return True
566+
else:
567+
allowed = super().check_allowed(username, auth_model)
568+
if isawaitable(allowed):
569+
allowed = await allowed
570+
if allowed is True:
571+
return True
564572
if self.allowed_groups:
565573
# check allowed groups
566574
in_groups = set((auth_model.get("auth_state") or {}).get("ldap_groups", []))

ldapauthenticator/tests/test_ldapauthenticator.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,12 @@ async def test_allow_config(authenticator):
153153
)
154154
assert authorized is None
155155
# allow_all grants access
156-
authenticator.allow_all = True
156+
if hasattr(authenticator, "allow_all"):
157+
authenticator.allow_all = True
158+
else:
159+
# clear allow config for JupyterHub < 5
160+
authenticator.allowed_groups = []
161+
authenticator.allowed_users = set()
157162
authorized = await authenticator.get_authenticated_user(
158163
None, {"username": "professor", "password": "professor"}
159164
)

0 commit comments

Comments
 (0)