Skip to content

Commit 96c9cfe

Browse files
skorandac00kiemon5ter
authored andcommitted
Better default for auto_bind argument to ldap3.Connection object
A Python False is not an acceptable value for the auto_bind argument to the ldap3.Connection object. This commit sets the default value to a module defined constant that makes the most sense when trying to preserve the REUSABLE strategy as the default (for now), and allows full configuration by defining a mapping between configuration string values and the ldap3 module constants, as is done for the client_strategy.
1 parent fb18057 commit 96c9cfe

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/satosa/micro_services/ldap_attribute_store.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
from ldap3.core.exceptions import LDAPException
1919

20-
2120
logger = logging.getLogger(__name__)
2221

2322
KEY_FOUND_LDAP_RECORD = 'ldap_attribute_store_found_record'
@@ -53,7 +52,7 @@ class LdapAttributeStore(ResponseMicroService):
5352
'user_id_from_attrs': [],
5453
'read_only': True,
5554
'version': 3,
56-
'auto_bind': False,
55+
'auto_bind': 'AUTO_BIND_TLS_BEFORE_BIND',
5756
'client_strategy': 'REUSABLE',
5857
'pool_size': 10,
5958
'pool_keepalive': 10,
@@ -287,7 +286,15 @@ def _ldap_connection_factory(self, config):
287286
msg = "Using bind DN {}".format(bind_dn)
288287
satosa_logging(logger, logging.DEBUG, msg, None)
289288

290-
auto_bind = config['auto_bind']
289+
auto_bind_string = config['auto_bind']
290+
auto_bind_map = {
291+
'AUTO_BIND_NONE': ldap3.AUTO_BIND_NONE,
292+
'AUTO_BIND_NO_TLS': ldap3.AUTO_BIND_NO_TLS,
293+
'AUTO_BIND_TLS_AFTER_BIND': ldap3.AUTO_BIND_TLS_AFTER_BIND,
294+
'AUTO_BIND_TLS_BEFORE_BIND': ldap3.AUTO_BIND_TLS_BEFORE_BIND
295+
}
296+
auto_bind = auto_bind_map[auto_bind_string]
297+
291298
read_only = config['read_only']
292299
version = config['version']
293300

0 commit comments

Comments
 (0)