2022-02-06 23:55:08 -06:00
|
|
|
##########################################################################
|
|
|
|
#
|
|
|
|
# pgAdmin 4 - PostgreSQL Tools
|
|
|
|
#
|
2023-01-02 00:23:55 -06:00
|
|
|
# Copyright (C) 2013 - 2023, The pgAdmin Development Team
|
2022-02-06 23:55:08 -06:00
|
|
|
# This software is released under the PostgreSQL Licence
|
|
|
|
#
|
|
|
|
##########################################################################
|
|
|
|
|
|
|
|
"""
|
|
|
|
Kerberos Environment Locker class
|
|
|
|
"""
|
|
|
|
|
|
|
|
from threading import Lock
|
|
|
|
from os import environ
|
|
|
|
from flask import session, current_app
|
|
|
|
|
|
|
|
import config
|
|
|
|
from pgadmin.utils.constants import KERBEROS
|
|
|
|
|
|
|
|
|
|
|
|
class ConnectionLocker:
|
|
|
|
"""Implementing lock while setting/unsetting
|
|
|
|
the Kerberos environ variables."""
|
|
|
|
lock = Lock()
|
|
|
|
|
|
|
|
def __init__(self, _is_kerberos_conn=False):
|
|
|
|
self.is_kerberos_conn = _is_kerberos_conn
|
|
|
|
|
|
|
|
def __enter__(self):
|
|
|
|
if config.SERVER_MODE:
|
|
|
|
current_app.logger.info("Waiting for a lock.")
|
|
|
|
self.lock.acquire()
|
|
|
|
current_app.logger.info("Acquired a lock.")
|
|
|
|
|
2023-04-18 07:24:21 -05:00
|
|
|
if 'auth_source_manager' in session and \
|
|
|
|
session['auth_source_manager']['current_source'] == \
|
2022-02-06 23:55:08 -06:00
|
|
|
KERBEROS and 'KRB5CCNAME' in session \
|
|
|
|
and self.is_kerberos_conn:
|
|
|
|
environ['KRB5CCNAME'] = session['KRB5CCNAME']
|
|
|
|
else:
|
|
|
|
environ.pop('KRB5CCNAME', None)
|
|
|
|
|
|
|
|
return self
|
|
|
|
|
|
|
|
def __exit__(self, type, value, traceback):
|
|
|
|
if config.SERVER_MODE:
|
|
|
|
environ.pop('KRB5CCNAME', None)
|
|
|
|
if self.lock.locked():
|
|
|
|
current_app.logger.info("Released a lock.")
|
|
|
|
self.lock.release()
|