From 47179f29568ef14761043392810bc4c5fa4d209b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Mon, 4 Mar 2019 17:29:00 +0100 Subject: [PATCH] =?UTF-8?q?=E2=98=94=20forcelogin:=20Never=20handle=20the?= =?UTF-8?q?=20UI=20if=20ACL=20is=20disabled?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The following `passive_login` should always succeed if ACL is disabled and hence this *should* not have caused issues, but considering https://community.octoprint.org/t/cant-login-to-the-web-interface/7908/3 it might have after all, so better be safe than sorry here. --- src/octoprint/plugins/forcelogin/__init__.py | 37 ++++++++------------ 1 file changed, 15 insertions(+), 22 deletions(-) diff --git a/src/octoprint/plugins/forcelogin/__init__.py b/src/octoprint/plugins/forcelogin/__init__.py index ceee6d608..27c9b6642 100644 --- a/src/octoprint/plugins/forcelogin/__init__.py +++ b/src/octoprint/plugins/forcelogin/__init__.py @@ -23,14 +23,19 @@ class ForceLoginPlugin(octoprint.plugin.UiPlugin, self._message_backlog = defaultdict(list) self._message_backlog_mutex = threading.RLock() + @property + def active(self): + # we are only active if ACL is enabled AND configured + return self._user_manager.enabled and self._user_manager.hasBeenCustomized() + def get_assets(self): return dict( js=["js/viewmodel.js"] ) def will_handle_ui(self, request): - if self._user_manager.enabled and not self._user_manager.hasBeenCustomized(): - # ACL hasn't been configured yet, make an exception + if not self.active: + # not active, not responsible return False from octoprint.server.util import loginUserFromApiKey, loginUserFromAuthorizationHeader, InvalidApiKeyException @@ -113,11 +118,8 @@ class ForceLoginPlugin(octoprint.plugin.UiPlugin, def get_before_request_handlers(self): def check_login_required(): - if self._user_manager.enabled and not self._user_manager.hasBeenCustomized(): - # ACL hasn't been configured yet, make an exception - return - elif not self._user_manager.enabled: - # ACL isn't enabled + if not self.active: + # not active, no handling return if flask.request.endpoint in ("api.login",): @@ -130,11 +132,8 @@ class ForceLoginPlugin(octoprint.plugin.UiPlugin, return [check_login_required] def access_validator(self, request): - if self._user_manager.enabled and not self._user_manager.hasBeenCustomized(): - # ACL hasn't been configured yet, make an exception - return - elif not self._user_manager.enabled: - # ACL isn't enabled + if not self.active: + # not active, no handling return import tornado.web @@ -145,11 +144,8 @@ class ForceLoginPlugin(octoprint.plugin.UiPlugin, raise tornado.web.HTTPError(403) def socket_register_validator(self, socket, user): - if self._user_manager.enabled and not self._user_manager.hasBeenCustomized(): - # ACL hasn't been configured yet, make an exception - return True - elif not self._user_manager.enabled: - # ACL isn't enabled + if not self.active: + # not active, no limitation return True return user is not None and not user.is_anonymous() and user.is_active() @@ -164,11 +160,8 @@ class ForceLoginPlugin(octoprint.plugin.UiPlugin, self._logger.debug("Sent backlog of {} message(s) via socket".format(len(backlog))) def socket_emit_validator(self, socket, user, message, payload): - if self._user_manager.enabled and not self._user_manager.hasBeenCustomized(): - # ACL hasn't been configured yet, make an exception - return True - elif not self._user_manager.enabled: - # ACL isn't enabled + if not self.active: + # not active, no limitation return True if message in ("connected", "reauthRequired"):