Skip to content

Commit

Permalink
Report the actual error when ldap fails
Browse files Browse the repository at this point in the history
  • Loading branch information
alexAubin committed Apr 9, 2020
1 parent 33c3505 commit 628ffc9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 26 deletions.
1 change: 0 additions & 1 deletion locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
"invalid_token": "Invalid token - please authenticate",
"invalid_usage": "Invalid usage, pass --help to see help",
"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",
"logged_in": "Logged in",
"logged_out": "Logged out",
Expand Down
41 changes: 16 additions & 25 deletions moulinette/authenticators/ldap.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,12 @@ def search(self, base=None, filter="(objectClass=*)", attrs=["dn"]):
try:
result = self.con.search_s(base, ldap.SCOPE_SUBTREE, filter, attrs)
except Exception as e:
logger.exception(
raise MoulinetteError(
"error during LDAP search operation with: base='%s', "
"filter='%s', attrs=%s and exception %s",
base,
filter,
attrs,
e,
"filter='%s', attrs=%s and exception %s"
% (base, filter, attrs, e),
raw_msg=True
)
raise MoulinetteError("ldap_operation_error", action="search")

result_list = []
if not attrs or "dn" not in attrs:
Expand Down Expand Up @@ -185,14 +182,12 @@ def add(self, rdn, attr_dict):
try:
self.con.add_s(dn, ldif)
except Exception as e:
logger.exception(
raise MoulinetteError(
"error during LDAP add operation with: rdn='%s', "
"attr_dict=%s and exception %s",
rdn,
attr_dict,
e,
"attr_dict=%s and exception %s"
% (rdn, attr_dict, e),
raw_msg=True
)
raise MoulinetteError("ldap_operation_error", action="add")
else:
return True

Expand All @@ -211,12 +206,11 @@ def remove(self, rdn):
try:
self.con.delete_s(dn)
except Exception as e:
logger.exception(
"error during LDAP delete operation with: rdn='%s' and exception %s",
rdn,
e,
raise MoulinetteError(
"error during LDAP delete operation with: rdn='%s' and exception %s"
% (rdn, e),
raw_msg=True
)
raise MoulinetteError("ldap_operation_error", action="remove")
else:
return True

Expand Down Expand Up @@ -249,15 +243,12 @@ def update(self, rdn, attr_dict, new_rdn=False):

self.con.modify_ext_s(dn, ldif)
except Exception as e:
logger.exception(
raise MoulinetteError(
"error during LDAP update operation with: rdn='%s', "
"attr_dict=%s, new_rdn=%s and exception: %s",
rdn,
attr_dict,
new_rdn,
e,
"attr_dict=%s, new_rdn=%s and exception: %s"
% (rdn, attr_dict, new_rdn, e),
raw_msg=True
)
raise MoulinetteError("ldap_operation_error", action="update")
else:
return True

Expand Down

0 comments on commit 628ffc9

Please sign in to comment.