mirror of
https://github.com/kakwa/ldapcherry
synced 2025-07-04 20:37:48 +02:00
custom error handling for UserDoesntExist, UserAlreadyExists and GroupDoesntExist
This commit is contained in:
parent
5561a9f42b
commit
a8af29692e
2 changed files with 38 additions and 10 deletions
|
@ -11,7 +11,9 @@ import ldap.modlist as modlist
|
|||
import ldap.filter
|
||||
import logging
|
||||
import ldapcherry.backend
|
||||
from ldapcherry.exceptions import UserDoesntExist, GroupDoesntExist
|
||||
from ldapcherry.exceptions import UserDoesntExist, \
|
||||
GroupDoesntExist, \
|
||||
UserAlreadyExists
|
||||
import os
|
||||
import re
|
||||
|
||||
|
@ -311,6 +313,8 @@ class Backend(ldapcherry.backend.Backend):
|
|||
ldif = modlist.addModlist(attrs_str)
|
||||
try:
|
||||
ldap_client.add_s(dn, ldif)
|
||||
except ldap.ALREADY_EXISTS as e:
|
||||
raise UserAlreadyExists(attrs[self.key], self.backend_name)
|
||||
except Exception as e:
|
||||
ldap_client.unbind_s()
|
||||
self._exception_handler(e)
|
||||
|
@ -326,7 +330,7 @@ class Backend(ldapcherry.backend.Backend):
|
|||
ldap_client.delete_s(dn)
|
||||
else:
|
||||
ldap_client.unbind_s()
|
||||
raise UserDoesntExist(username, self.backend_display_name)
|
||||
raise UserDoesntExist(username, self.backend_name)
|
||||
ldap_client.unbind_s()
|
||||
|
||||
def set_attrs(self, username, attrs):
|
||||
|
@ -417,7 +421,7 @@ class Backend(ldapcherry.backend.Backend):
|
|||
}
|
||||
)
|
||||
except ldap.NO_SUCH_OBJECT as e:
|
||||
raise GroupDoesntExist(group, self.backend_display_name)
|
||||
raise GroupDoesntExist(group, self.backend_name)
|
||||
except Exception as e:
|
||||
ldap_client.unbind_s()
|
||||
self._exception_handler(e)
|
||||
|
@ -487,7 +491,7 @@ class Backend(ldapcherry.backend.Backend):
|
|||
ret = {}
|
||||
tmp = self._get_user(username, ALL_ATTRS)
|
||||
if tmp is None:
|
||||
raise UserDoesntExist(username, self.backend_display_name)
|
||||
raise UserDoesntExist(username, self.backend_name)
|
||||
attrs_tmp = tmp[1]
|
||||
for attr in attrs_tmp:
|
||||
value_tmp = attrs_tmp[attr]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue