diff --git a/Nagstamon/QUI/__init__.py b/Nagstamon/QUI/__init__.py index a07266fac..f446bba8a 100644 --- a/Nagstamon/QUI/__init__.py +++ b/Nagstamon/QUI/__init__.py @@ -107,6 +107,28 @@ except ImportError: ECP_AVAILABLE = False +# flag to keep track of Kerberos availability +KERBEROS_AVAILABLE = False +if OS == OS_MACOS: + # requests_gssapi is newer but not available everywhere + try: + # extra imports needed to get it compiled on macOS + import numbers + import gssapi.raw.cython_converters + from requests_gssapi import HTTPSPNEGOAuth as HTTPSKerberos + KERBEROS_AVAILABLE = True + except ImportError: + print('No Kerberos available') +else: + # requests_gssapi is newer but not available everywhere + try: + # requests_gssapi needs installation of KfW - Kerberos for Windows + # requests_kerberoes doesn't + from requests_kerberos import HTTPKerberosAuth as HTTPSKerberos + KERBEROS_AVAILABLE = True + except ImportError: + print('No Kerberos available') + # since Qt6 HighDPI-awareness is default behaviour if QT_VERSION_MAJOR < 6: # enable HighDPI-awareness to avoid https://github.com/HenriWahl/Nagstamon/issues/618 @@ -5828,9 +5850,11 @@ def __init__(self, dialog): self.window.button_choose_custom_cert_ca_file.clicked.connect(self.choose_custom_cert_ca_file) # fill authentication combobox - self.window.input_combobox_authentication.addItems(['Basic', 'Digest', 'Kerberos', 'Bearer']) + self.window.input_combobox_authentication.addItems(['Basic', 'Digest', 'Bearer']) if ECP_AVAILABLE is True: self.window.input_combobox_authentication.addItems(['ECP']) + if KERBEROS_AVAILABLE is True: + self.window.input_combobox_authentication.addItems(['Kerberos']) # detect change of server type which leads to certain options shown or hidden self.window.input_combobox_type.activated.connect(self.toggle_type) diff --git a/Nagstamon/Servers/Generic.py b/Nagstamon/Servers/Generic.py index 0aca42590..cf3048513 100644 --- a/Nagstamon/Servers/Generic.py +++ b/Nagstamon/Servers/Generic.py @@ -61,6 +61,8 @@ OS_MACOS, RESOURCES) +# flag to keep track of Kerberos availability +KERBEROS_AVAILABLE = False if OS == OS_MACOS: # requests_gssapi is newer but not available everywhere try: @@ -68,16 +70,18 @@ import numbers import gssapi.raw.cython_converters from requests_gssapi import HTTPSPNEGOAuth as HTTPSKerberos + KERBEROS_AVAILABLE = True except ImportError: - from requests_kerberos import HTTPKerberosAuth as HTTPSKerberos + print('No Kerberos available') else: # requests_gssapi is newer but not available everywhere try: # requests_gssapi needs installation of KfW - Kerberos for Windows # requests_kerberoes doesn't from requests_kerberos import HTTPKerberosAuth as HTTPSKerberos + KERBEROS_AVAILABLE = True except ImportError: - from requests_gssapi import HTTPSPNEGOAuth as HTTPSKerberos + print('No Kerberos available') # disable annoying SubjectAltNameWarning warnings try: @@ -319,7 +323,7 @@ def create_session(self): session.auth = requests.auth.HTTPDigestAuth(self.username, self.password) elif self.authentication == 'ecp' and ECP_AVAILABLE: session.auth = HTTPECPAuth(self.idp_ecp_endpoint, username=self.username, password=self.password) - elif self.authentication == 'kerberos': + elif self.authentication == 'kerberos' and KERBEROS_AVAILABLE: session.auth = HTTPSKerberos() elif self.authentication == 'bearer': session.auth = BearerAuth(self.password)