From c781d10b54f6f60cc5477f268f22bbedd139df9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Lebleu?= Date: Sat, 17 May 2014 02:09:55 +0200 Subject: [PATCH] [enh] Catch error when LDAP server is down --- locales/en.json | 3 ++- locales/fr.json | 3 ++- moulinette/authenticators/ldap.py | 10 ++++++---- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/locales/en.json b/locales/en.json index 49069045..d8639548 100644 --- a/locales/en.json +++ b/locales/en.json @@ -10,7 +10,8 @@ "unable_authenticate" : "Unable to authenticate", "unable_retrieve_session" : "Unable to retrieve the session", - "error_ldap_operation" : "An error occured during LDAP operation", + "ldap_server_down" : "Unable to reach LDAP server", + "ldap_operation_error" : "An error occured during LDAP operation", "password" : "Password", "invalid_password" : "Invalid password", diff --git a/locales/fr.json b/locales/fr.json index 57386a1e..b446a52d 100644 --- a/locales/fr.json +++ b/locales/fr.json @@ -10,7 +10,8 @@ "unable_authenticate" : "Impossible de vous authentifier", "unable_retrieve_session" : "Impossible de récupérer la session", - "error_ldap_operation" : "Une erreur est survenue lors de l'opération LDAP", + "ldap_server_down" : "Impossible d'atteindre le serveur LDAP", + "ldap_operation_error" : "Une erreur est survenue lors de l'opération LDAP", "password" : "Mot de passe", "invalid_password" : "Mot de passe incorrect", diff --git a/moulinette/authenticators/ldap.py b/moulinette/authenticators/ldap.py index 1855a79f..b0ab5ae0 100644 --- a/moulinette/authenticators/ldap.py +++ b/moulinette/authenticators/ldap.py @@ -66,6 +66,8 @@ class Authenticator(BaseAuthenticator): con.simple_bind_s() except ldap.INVALID_CREDENTIALS: raise MoulinetteError(errno.EACCES, m18n.g('invalid_password')) + except ldap.SERVER_DOWN: + raise MoulinetteError(169, m18n.g('ldap_server_down')) else: self.con = con @@ -94,7 +96,7 @@ class Authenticator(BaseAuthenticator): try: result = self.con.search_s(base, ldap.SCOPE_SUBTREE, filter, attrs) except: - raise MoulinetteError(169, m18n.g('error_ldap_operation')) + raise MoulinetteError(169, m18n.g('ldap_operation_error')) result_list = [] if not attrs or 'dn' not in attrs: @@ -123,7 +125,7 @@ class Authenticator(BaseAuthenticator): try: self.con.add_s(dn, ldif) except: - raise MoulinetteError(169, m18n.g('error_ldap_operation')) + raise MoulinetteError(169, m18n.g('ldap_operation_error')) else: return True @@ -142,7 +144,7 @@ class Authenticator(BaseAuthenticator): try: self.con.delete_s(dn) except: - raise MoulinetteError(169, m18n.g('error_ldap_operation')) + raise MoulinetteError(169, m18n.g('ldap_operation_error')) else: return True @@ -170,7 +172,7 @@ class Authenticator(BaseAuthenticator): self.con.modify_ext_s(dn, ldif) except: - raise MoulinetteError(169, m18n.g('error_ldap_operation')) + raise MoulinetteError(169, m18n.g('ldap_operation_error')) else: return True