enforce a sane default OPT_NETWORK_TIMEOUT for LDAP connections

see: #5208
This commit is contained in:
Ryan Petrello
2017-02-07 10:42:09 -05:00
parent 81805c780f
commit f4d55659f0
10 changed files with 64 additions and 5 deletions

View File

@@ -5,6 +5,8 @@
import logging
import uuid
import ldap
# Django
from django.dispatch import receiver
from django.contrib.auth.models import User
@@ -38,6 +40,16 @@ class LDAPSettings(BaseLDAPSettings):
'TEAM_MAP': {},
}.items())
def __init__(self, prefix='AUTH_LDAP_', defaults={}):
super(LDAPSettings, self).__init__(prefix, defaults)
# If a DB-backed setting is specified that wipes out the
# OPT_NETWORK_TIMEOUT, fall back to a sane default
if ldap.OPT_NETWORK_TIMEOUT not in getattr(self, 'CONNECTION_OPTIONS', {}):
options = getattr(self, 'CONNECTION_OPTIONS', {})
options[ldap.OPT_NETWORK_TIMEOUT] = 30
self.CONNECTION_OPTIONS = options
class LDAPBackend(BaseLDAPBackend):
'''