From 83ec0f3d90ee422b80abb40008b487929cb7f674 Mon Sep 17 00:00:00 2001 From: Paul Milbank <37281769+paulmilbank@users.noreply.github.com> Date: Mon, 13 Feb 2023 18:41:05 +1300 Subject: [PATCH] Add additional logging for successful logins and user creation. #5842 --- web/pgadmin/authenticate/internal.py | 2 ++ web/pgadmin/authenticate/kerberos.py | 4 ++++ web/pgadmin/authenticate/ldap.py | 6 ++++++ web/pgadmin/authenticate/oauth2.py | 6 ++++++ web/pgadmin/authenticate/webserver.py | 6 ++++++ 5 files changed, 24 insertions(+) diff --git a/web/pgadmin/authenticate/internal.py b/web/pgadmin/authenticate/internal.py index f9b7c32e3..303137b41 100644 --- a/web/pgadmin/authenticate/internal.py +++ b/web/pgadmin/authenticate/internal.py @@ -78,6 +78,8 @@ class BaseAuthentication(metaclass=AuthSourceRegistry): if not status: current_app.logger.exception(self.messages('LOGIN_FAILED')) return False, self.messages('LOGIN_FAILED') + current_app.logger.info( + "Internal user {0} logged in.".format(username)) return True, None def messages(self, msg_key): diff --git a/web/pgadmin/authenticate/kerberos.py b/web/pgadmin/authenticate/kerberos.py index 381555f47..f7c4a23c2 100644 --- a/web/pgadmin/authenticate/kerberos.py +++ b/web/pgadmin/authenticate/kerberos.py @@ -273,6 +273,10 @@ class KerberosAuthentication(BaseAuthentication): user = User.query.filter_by( username=username, auth_source=KERBEROS).first() if user is None: + create_msg = ("Creating user {0} with email {1} " + "from auth source KERBEROS.") + current_app.logger.info(create_msg.format(username, + username)) return create_user({ 'username': username, 'email': username, diff --git a/web/pgadmin/authenticate/ldap.py b/web/pgadmin/authenticate/ldap.py index 902040513..b9953e926 100644 --- a/web/pgadmin/authenticate/ldap.py +++ b/web/pgadmin/authenticate/ldap.py @@ -175,6 +175,8 @@ class LDAPAuthentication(BaseAuthentication): if not status: current_app.logger.exception(self.messages('LOGIN_FAILED')) return False, self.messages('LOGIN_FAILED') + current_app.logger.info( + "LDAP user {0} logged in.".format(user)) return True, None def __auto_create_user(self, user_email): @@ -188,6 +190,10 @@ class LDAPAuthentication(BaseAuthentication): self.username)).first() if user is None: + create_msg = ("Creating user {0} with email {1} " + "from auth source LDAP.") + current_app.logger.info(create_msg.format(self.username, + user_email)) return create_user({ 'username': self.username, 'email': user_email, diff --git a/web/pgadmin/authenticate/oauth2.py b/web/pgadmin/authenticate/oauth2.py index 3b62ccbf1..8922e9923 100644 --- a/web/pgadmin/authenticate/oauth2.py +++ b/web/pgadmin/authenticate/oauth2.py @@ -157,6 +157,8 @@ class OAuth2Authentication(BaseAuthentication): username=username, auth_source=OAUTH2).first() current_app.login_manager.logout_view = \ OAuth2Authentication.LOGOUT_VIEW + current_app.logger.info( + "OAUTH2 user {0} logged in.".format(username)) return login_user(user), None return False, msg @@ -189,6 +191,10 @@ class OAuth2Authentication(BaseAuthentication): user = User.query.filter_by(username=username, auth_source=OAUTH2).first() if not user: + create_msg = ("Creating user {0} with email {1} " + "from auth source OAUTH2.") + current_app.logger.info(create_msg.format(username, + email)) return create_user({ 'username': username, 'email': email, diff --git a/web/pgadmin/authenticate/webserver.py b/web/pgadmin/authenticate/webserver.py index 31a541df6..0766113f6 100644 --- a/web/pgadmin/authenticate/webserver.py +++ b/web/pgadmin/authenticate/webserver.py @@ -104,6 +104,8 @@ class WebserverAuthentication(BaseAuthentication): if not status: current_app.logger.exception(self.messages('LOGIN_FAILED')) return False, self.messages('LOGIN_FAILED') + current_app.logger.info( + "Webserver user {0} logged in.".format(username)) return True, None return False, self.messages('LOGIN_FAILED') @@ -112,6 +114,10 @@ class WebserverAuthentication(BaseAuthentication): if config.WEBSERVER_AUTO_CREATE_USER: user = User.query.filter_by(username=username).first() if not user: + create_msg = ("Creating user {0} with email {1} " + "from auth source Webserver.") + current_app.logger.info(create_msg.format(username, + useremail)) return create_user({ 'username': username, 'email': useremail,