Report the actual error when ldap fails

This commit is contained in:
Alexandre Aubin 2020-04-09 19:05:20 +02:00
parent 33c3505c47
commit 628ffc9da1
2 changed files with 16 additions and 26 deletions

View file

@ -19,7 +19,6 @@
"invalid_token": "Invalid token - please authenticate", "invalid_token": "Invalid token - please authenticate",
"invalid_usage": "Invalid usage, pass --help to see help", "invalid_usage": "Invalid usage, pass --help to see help",
"ldap_attribute_already_exists": "Attribute '{attribute}' already exists with value '{value}'", "ldap_attribute_already_exists": "Attribute '{attribute}' already exists with value '{value}'",
"ldap_operation_error": "An error occurred during LDAP '{action}' operation",
"ldap_server_down": "Unable to reach LDAP server", "ldap_server_down": "Unable to reach LDAP server",
"logged_in": "Logged in", "logged_in": "Logged in",
"logged_out": "Logged out", "logged_out": "Logged out",

View file

@ -148,15 +148,12 @@ class Authenticator(BaseAuthenticator):
try: try:
result = self.con.search_s(base, ldap.SCOPE_SUBTREE, filter, attrs) result = self.con.search_s(base, ldap.SCOPE_SUBTREE, filter, attrs)
except Exception as e: except Exception as e:
logger.exception( raise MoulinetteError(
"error during LDAP search operation with: base='%s', " "error during LDAP search operation with: base='%s', "
"filter='%s', attrs=%s and exception %s", "filter='%s', attrs=%s and exception %s"
base, % (base, filter, attrs, e),
filter, raw_msg=True
attrs,
e,
) )
raise MoulinetteError("ldap_operation_error", action="search")
result_list = [] result_list = []
if not attrs or "dn" not in attrs: if not attrs or "dn" not in attrs:
@ -185,14 +182,12 @@ class Authenticator(BaseAuthenticator):
try: try:
self.con.add_s(dn, ldif) self.con.add_s(dn, ldif)
except Exception as e: except Exception as e:
logger.exception( raise MoulinetteError(
"error during LDAP add operation with: rdn='%s', " "error during LDAP add operation with: rdn='%s', "
"attr_dict=%s and exception %s", "attr_dict=%s and exception %s"
rdn, % (rdn, attr_dict, e),
attr_dict, raw_msg=True
e,
) )
raise MoulinetteError("ldap_operation_error", action="add")
else: else:
return True return True
@ -211,12 +206,11 @@ class Authenticator(BaseAuthenticator):
try: try:
self.con.delete_s(dn) self.con.delete_s(dn)
except Exception as e: except Exception as e:
logger.exception( raise MoulinetteError(
"error during LDAP delete operation with: rdn='%s' and exception %s", "error during LDAP delete operation with: rdn='%s' and exception %s"
rdn, % (rdn, e),
e, raw_msg=True
) )
raise MoulinetteError("ldap_operation_error", action="remove")
else: else:
return True return True
@ -249,15 +243,12 @@ class Authenticator(BaseAuthenticator):
self.con.modify_ext_s(dn, ldif) self.con.modify_ext_s(dn, ldif)
except Exception as e: except Exception as e:
logger.exception( raise MoulinetteError(
"error during LDAP update operation with: rdn='%s', " "error during LDAP update operation with: rdn='%s', "
"attr_dict=%s, new_rdn=%s and exception: %s", "attr_dict=%s, new_rdn=%s and exception: %s"
rdn, % (rdn, attr_dict, new_rdn, e),
attr_dict, raw_msg=True
new_rdn,
e,
) )
raise MoulinetteError("ldap_operation_error", action="update")
else: else:
return True return True