@@ -59,6 +59,7 @@ def init_app(app):
59
59
app .config .setdefault ('LDAP_OPENLDAP' , False )
60
60
app .config .setdefault ('LDAP_GROUP_MEMBER_FILTER' , '*' )
61
61
app .config .setdefault ('LDAP_GROUP_MEMBER_FILTER_FIELD' , '*' )
62
+ app .config .setdefault ('LDAP_CUSTOM_OPTIONS' , {})
62
63
63
64
if app .config ['LDAP_USE_SSL' ] or app .config ['LDAP_USE_TLS' ]:
64
65
ldap .set_option (ldap .OPT_X_TLS_REQUIRE_CERT ,
@@ -74,6 +75,14 @@ def init_app(app):
74
75
if app .config ['LDAP_{0}' .format (option )] is None :
75
76
raise LDAPException ('LDAP_{0} cannot be None!' .format (option ))
76
77
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
+
77
86
@property
78
87
def initialize (self ):
79
88
"""Initialize a connection to the LDAP server.
@@ -88,6 +97,7 @@ def initialize(self):
88
97
current_app .config ['LDAP_PORT' ]))
89
98
conn .set_option (ldap .OPT_NETWORK_TIMEOUT ,
90
99
current_app .config ['LDAP_TIMEOUT' ])
100
+ conn = self ._set_custom_options (conn )
91
101
conn .protocol_version = ldap .VERSION3
92
102
if current_app .config ['LDAP_USE_TLS' ]:
93
103
conn .start_tls_s ()
0 commit comments