Skip to content

Commit 70bf596

Browse files
committed
add ability to set any valid ldap options
1 parent 14076c2 commit 70bf596

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

flask_simpleldap/__init__.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ def init_app(app):
5959
app.config.setdefault('LDAP_OPENLDAP', False)
6060
app.config.setdefault('LDAP_GROUP_MEMBER_FILTER', '*')
6161
app.config.setdefault('LDAP_GROUP_MEMBER_FILTER_FIELD', '*')
62+
app.config.setdefault('LDAP_CUSTOM_OPTIONS', {})
6263

6364
if app.config['LDAP_USE_SSL'] or app.config['LDAP_USE_TLS']:
6465
ldap.set_option(ldap.OPT_X_TLS_REQUIRE_CERT,
@@ -74,6 +75,14 @@ def init_app(app):
7475
if app.config['LDAP_{0}'.format(option)] is None:
7576
raise LDAPException('LDAP_{0} cannot be None!'.format(option))
7677

78+
@staticmethod
79+
def _set_custom_options(conn):
80+
options = current_app.config['LDAP_OPTIONS']
81+
if options:
82+
for k, v in options.values():
83+
conn.set_option(k, v)
84+
return conn
85+
7786
@property
7887
def initialize(self):
7988
"""Initialize a connection to the LDAP server.
@@ -88,6 +97,7 @@ def initialize(self):
8897
current_app.config['LDAP_PORT']))
8998
conn.set_option(ldap.OPT_NETWORK_TIMEOUT,
9099
current_app.config['LDAP_TIMEOUT'])
100+
conn = self._set_custom_options(conn)
91101
conn.protocol_version = ldap.VERSION3
92102
if current_app.config['LDAP_USE_TLS']:
93103
conn.start_tls_s()

0 commit comments

Comments
 (0)