Add ping method to auth engines to determine if they are reachable

This commit is contained in:
Joseph Schorr 2017-05-10 20:55:10 -07:00
parent a6ea16abc5
commit 0dfb6806e3
6 changed files with 67 additions and 0 deletions

View file

@ -193,6 +193,18 @@ class LDAPUsers(FederatedUsers):
email = response.get(self._email_attr, [None])[0]
return (UserInformation(username=username, email=email, id=username), None)
def ping(self):
try:
with self._ldap.get_connection():
pass
except ldap.INVALID_CREDENTIALS:
return (False, 'LDAP Admin dn or password is invalid')
except ldap.LDAPError as lde:
logger.exception('Exception when trying to health check LDAP')
return (False, lde.message)
return (True, None)
def get_user(self, username_or_email):
""" Looks up a username or email in LDAP. """
logger.debug('Looking up LDAP username or email %s', username_or_email)