Subject: Patch for Bug #6832

From: Florian Sabonchi <[email-masked]>
Date: Sat, 9 Oct 2021 11:02:48 +0000

Hello I have written a patch for the bug #6832

From 40a72af814c34080883f069fd239047df48b2b7b Mon Sep 17 00:00:00 2001
From: Florian Sabonchi <[email-masked]>
Date: Sat, 9 Oct 2021 12:57:49 +0200
Subject: [PATCH] fixe for Bug #6832

---
 web/pgAdmin4.py         | 5 ++++-
 web/pgadmin/__init__.py | 6 ++----
 2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/web/pgAdmin4.py b/web/pgAdmin4.py
index dc1924cbd..5618ec245 100644
--- a/web/pgAdmin4.py
+++ b/web/pgAdmin4.py
@@ -103,7 +103,10 @@ if config.SERVER_MODE:
     app.wsgi_app = ReverseProxied(app.wsgi_app)
 
 # Authentication sources
-if len(config.AUTHENTICATION_SOURCES) > 0:
+if len(config.AUTHENTICATION_SOURCES) > 1 and \
+        config.AUTHENTICATION_SOURCES[1] != INTERNAL:
+    app.PGADMIN_EXTERNAL_AUTH_SOURCE = config.AUTHENTICATION_SOURCES[1]
+elif len(config.AUTHENTICATION_SOURCES) > 0:
     app.PGADMIN_EXTERNAL_AUTH_SOURCE = config.AUTHENTICATION_SOURCES[0]
 else:
     app.PGADMIN_EXTERNAL_AUTH_SOURCE = INTERNAL
diff --git a/web/pgadmin/__init__.py b/web/pgadmin/__init__.py
index 37eb26ccc..0fa8c4c83 100644
--- a/web/pgadmin/__init__.py
+++ b/web/pgadmin/__init__.py
@@ -777,10 +777,8 @@ def create_app(app_name=None):
         # but the user session may still be active. Logout the user
         # to get the key again when login
         if config.SERVER_MODE and current_user.is_authenticated and \
-                app.PGADMIN_EXTERNAL_AUTH_SOURCE != \
-                KERBEROS and app.PGADMIN_EXTERNAL_AUTH_SOURCE != \
-                OAUTH2 and\
-                current_app.keyManager.get() is None and \
+            app.PGADMIN_EXTERNAL_AUTH_SOURCE == INTERNAL and \
+            current_app.keyManager.get() is None and \
                 request.endpoint not in ('security.login', 'security.logout'):
             logout_user()
 
-- 
2.25.1

---

From: Akshay Joshi <[email-masked]>
Date: Wed, 13 Oct 2021 16:51:30 +0530

Khushboo,

Can you please review the patch?

-- 
*Thanks & Regards*
*Akshay Joshi*
*pgAdmin Hacker | Principal Software Architect*
*EDB Postgres <http://edbpostgres.com>*

*Mobile: +91 976-788-8246*

---

From: Khushboo Vashi <[email-masked]>
Date: Mon, 18 Oct 2021 11:44:56 +0530

Hi Florian,

The patch will fail if we have AUTHENTICATION_SOURCES = ['ldap', 'oauth2']
settings.
Also, please rebase your patch.

Thanks,
Khushboo