Skip to content

Commit

Permalink
KERBEROS_AVAILABLE
Browse files Browse the repository at this point in the history
  • Loading branch information
HenriWahl committed Oct 10, 2023
1 parent 2974433 commit 04e8843
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
26 changes: 25 additions & 1 deletion Nagstamon/QUI/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 7 additions & 3 deletions Nagstamon/Servers/Generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,23 +61,27 @@
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:
# 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:
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:
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 04e8843

Please sign in to comment.