FAQ | This is a LIVE service | Changelog

Skip to content
Snippets Groups Projects

Support authenticating with the LDAP server over SSL

Merged Dave Hart requested to merge 27-secure-ldap into master
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

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
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

  • Author Maintainer

    Pushed refactored code.

  • Please register or sign in to reply
  • Dave Hart added 1 commit

    added 1 commit

    Compare with previous version

  • Dr Rich Wareham approved this merge request

    approved this merge request

  • Dr Rich Wareham mentioned in commit eb427747

    mentioned in commit eb427747

  • Please register or sign in to reply
    Loading