mirror of
https://github.com/kakwa/ldapcherry
synced 2024-11-26 03:04:30 +01:00
better exception handling if user or group doesn't exist
This commit is contained in:
parent
77fbb346f1
commit
3a6da2e480
@ -522,7 +522,10 @@ class LdapCherry(object):
|
||||
return {}
|
||||
ret = {}
|
||||
for b in self.backends:
|
||||
try:
|
||||
tmp = self.backends[b].get_user(username)
|
||||
except UserDoesntExist as e:
|
||||
break
|
||||
for attr in tmp:
|
||||
if attr in self.attributes.backend_attributes[b]:
|
||||
attrid = self.attributes.backend_attributes[b][attr]
|
||||
@ -1053,6 +1056,12 @@ class LdapCherry(object):
|
||||
for r in self.roles.flatten:
|
||||
display_names[r] = self.roles.flatten[r]['display_name']
|
||||
user_attrs = self._get_user(user)
|
||||
if user_attrs == {}:
|
||||
return self.temp_error.render(
|
||||
is_admin=is_admin,
|
||||
alert='warning',
|
||||
message="User doesn't exist"
|
||||
)
|
||||
tmp = self._get_roles(user)
|
||||
user_roles = tmp['roles']
|
||||
user_lonely_groups = tmp['unusedgroups']
|
||||
@ -1098,6 +1107,12 @@ class LdapCherry(object):
|
||||
params = self._parse_params(params)
|
||||
self._selfmodify(params)
|
||||
user_attrs = self._get_user(user)
|
||||
if user_attrs == {}:
|
||||
return self.temp_error.render(
|
||||
is_admin=is_admin,
|
||||
alert='warning',
|
||||
message="User doesn't exist"
|
||||
)
|
||||
form = self.temp_form.render(
|
||||
attributes=self.attributes.get_selfattributes(),
|
||||
values=user_attrs,
|
||||
|
@ -10,6 +10,7 @@ import ldap
|
||||
import ldap.modlist as modlist
|
||||
import logging
|
||||
import ldapcherry.backend
|
||||
from ldapcherry.exceptions import UserDoesntExist, GroupDoesntExist
|
||||
import os
|
||||
import re
|
||||
|
||||
@ -97,8 +98,7 @@ class Backend(ldapcherry.backend.Backend):
|
||||
elif et is ldap.NO_SUCH_OBJECT:
|
||||
self._logger(
|
||||
severity=logging.ERROR,
|
||||
msg="Search DN '" + basedn +
|
||||
"' doesn't exist, check '" +
|
||||
msg="DN doesn't exist, check '" +
|
||||
self.backend_name +
|
||||
".userdn'or '" +
|
||||
self.backend_name +
|
||||
@ -338,6 +338,8 @@ class Backend(ldapcherry.backend.Backend):
|
||||
'backend': self.backend_name
|
||||
}
|
||||
)
|
||||
except ldap.NO_SUCH_OBJECT as e:
|
||||
raise GroupDoesntExist(group, self.backend_name)
|
||||
except Exception as e:
|
||||
ldap_client.unbind_s()
|
||||
self._exception_handler(e)
|
||||
@ -395,7 +397,10 @@ class Backend(ldapcherry.backend.Backend):
|
||||
|
||||
def get_user(self, username):
|
||||
ret = {}
|
||||
attrs_tmp = self._get_user(username, ALL_ATTRS)[1]
|
||||
tmp = self._get_user(username, ALL_ATTRS)
|
||||
if tmp is None:
|
||||
raise UserDoesntExist(username, self.backend_name)
|
||||
attrs_tmp = tmp[1]
|
||||
for attr in attrs_tmp:
|
||||
value_tmp = attrs_tmp[attr]
|
||||
if len(value_tmp) == 1:
|
||||
|
Loading…
Reference in New Issue
Block a user