logging.debug("Connecting to LDAP server: %s" % ldap_uri)
# Connect to the LDAP server
- conn = ldap.ldapobject.ReconnectLDAPObject(ldap_uri,
+ return ldap.ldapobject.ReconnectLDAPObject(ldap_uri,
retry_max=10, retry_delay=3)
+ def _authenticate(self):
# Bind with username and password
- bind_dn = self.settings.get("ldap_bind_dn")
- if bind_dn:
- bind_pw = self.settings.get("ldap_bind_pw", "")
- conn.simple_bind(bind_dn, bind_pw)
-
- return conn
+ self.ldap.simple_bind(
+ self.settings.get("ldap_bind_dn"),
+ self.settings.get("ldap_bind_pw", ""),
+ )
def _query(self, query, attrlist=None, limit=0, search_base=None):
logging.debug("Performing LDAP query: %s" % query)
dn = "uid=%s,ou=People,dc=mcfly,dc=local" % uid
# Create account on LDAP
+ self.accounts._authenticate()
self.ldap.add_s(dn, ldap.modlist.addModlist(account))
# Return account
def _modify(self, modlist):
logging.debug("Modifying %s: %s" % (self.dn, modlist))
+ # Authenticate before performing any write operations
+ self.accounts._authenticate()
+
# Run modify operation
self.ldap.modify_s(self.dn, modlist)