Skip to content

Commit fb18057

Browse files
skorandac00kiemon5ter
authored andcommitted
Revert to REUSABLE client strategy as default for ldap3 connection
Revert to using ldap3.REUSABLE as the default client strategy and fix configuration to allow setting the client strategy.
1 parent bd3684b commit fb18057

File tree

2 files changed

+23
-12
lines changed

2 files changed

+23
-12
lines changed

example/plugins/microservices/ldap_attribute_store.yaml.example

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,14 @@ config:
99
read_only : true
1010
version : 3
1111

12-
# See ldap3 client_strategies.
12+
# See ldap3 client_strategies. The default
13+
# is REUSABLE.
1314
client_strategy : RESTARTABLE
1415
auto_bind : true
15-
pool_size : 10
16-
pool_keepalive : 10
16+
# Specify pool size and keepalive when using
17+
# REUSABLE client strategy. Defaults are 10 and 10.
18+
#pool_size : 10
19+
#pool_keepalive : 10
1720

1821
# Attributes to return from LDAP query.
1922
query_return_attributes:

src/satosa/micro_services/ldap_attribute_store.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class LdapAttributeStore(ResponseMicroService):
5454
'read_only': True,
5555
'version': 3,
5656
'auto_bind': False,
57-
'client_strategy': ldap3.RESTARTABLE,
57+
'client_strategy': 'REUSABLE',
5858
'pool_size': 10,
5959
'pool_keepalive': 10,
6060
}
@@ -287,18 +287,26 @@ def _ldap_connection_factory(self, config):
287287
msg = "Using bind DN {}".format(bind_dn)
288288
satosa_logging(logger, logging.DEBUG, msg, None)
289289

290-
pool_size = config['pool_size']
291-
pool_keepalive = config['pool_keepalive']
292-
msg = "Using pool size {}".format(pool_size)
293-
satosa_logging(logger, logging.DEBUG, msg, None)
294-
msg = "Using pool keep alive {}".format(pool_keepalive)
295-
satosa_logging(logger, logging.DEBUG, msg, None)
296-
297290
auto_bind = config['auto_bind']
298-
client_strategy = config['client_strategy']
299291
read_only = config['read_only']
300292
version = config['version']
301293

294+
client_strategy_string = config['client_strategy']
295+
client_strategy_map = {'SYNC': ldap3.SYNC,
296+
'ASYNC': ldap3.ASYNC,
297+
'LDIF': ldap3.LDIF,
298+
'RESTARTABLE': ldap3.RESTARTABLE,
299+
'REUSABLE': ldap3.REUSABLE}
300+
client_strategy = client_strategy_map[client_strategy_string]
301+
302+
pool_size = config['pool_size']
303+
pool_keepalive = config['pool_keepalive']
304+
if client_strategy == ldap3.REUSABLE:
305+
msg = "Using pool size {}".format(pool_size)
306+
satosa_logging(logger, logging.DEBUG, msg, None)
307+
msg = "Using pool keep alive {}".format(pool_keepalive)
308+
satosa_logging(logger, logging.DEBUG, msg, None)
309+
302310
try:
303311
connection = ldap3.Connection(
304312
server,

0 commit comments

Comments
 (0)