Support authenticating with the LDAP server over SSL
2 unresolved threads
2 unresolved threads
To facilitate running the sync tool outside of the CUDN (such as when testing remotely), this commit adds configuration options for specifying credentials for authenticating with the LDAP server over SSL. SSL will automatically be used when these credentials are supplied.
Closes #27 (closed)
Merge request reports
Activity
assigned to @dkh21
added 1 commit
- dff481df - Support authenticating with the LDAP server over SSL. (#27 (closed))
174 search_base, search_filter, paged_size=1000, attributes=attributes) 175 if self.username is None or self.password is None: 176 # No username and/or password specified, so assume the LDAP server can be connected to 177 # without credentials 178 ldap_server = ldap3.Server(self.host) 179 with ldap3.Connection(ldap_server, auto_bind=True) as conn: 180 return conn.extend.standard.paged_search( 181 search_base, search_filter, paged_size=1000, attributes=attributes) 182 else: 183 # Username and password specified, so use SSL and login credentials to access the 184 # LDAP server 185 ldap_server = ldap3.Server(self.host, use_ssl=True) 186 with ldap3.Connection(ldap_server, auto_bind=True, 187 user=self.username, password=self.password) as conn: 188 return conn.extend.standard.paged_search( 189 search_base, search_filter, paged_size=1000, attributes=attributes) Maybe it's a little more pythonic to have:
ldap_server = ldap3.Server(self.host) # Keyword arguments passed to ldap3.Connection. connection_kwargs = { 'auto_bind': True } # Add authentication credentials if configured if self.username: connection_kwargs['username'] = self.username if self.password: connection_kwargs['password'] = self.password with ldap3.Connection(ldap_server, **connection_kwargs) as conn: return conn.extend.standard.paged_search( search_base, search_filter, paged_size=1000, attributes=attributes)
which avoids having to repeat the
conn.extend.standard.paged_search...
stuff?changed this line in version 3 of the diff
added 1 commit
- a75a2cf6 - Support authenticating with the LDAP server over SSL. (#27 (closed))
mentioned in commit eb427747
Please register or sign in to reply