def get_real_name(self):
"""
Attempt to retrieve the LDAP Common Name of the given login name.
"""
encoding = _config.get('ldap', 'encoding')
user_dn = self.get_user_dn().encode(encoding)
name_attr = _config.get('ldap', 'name_attr')
try:
res = self.ldap.search_s(user_dn, ldap.SCOPE_BASE,
'(objectClass=*)', [name_attr])
except ldap.LDAPError:
_logger.exception("Caught exception while retrieving user name "
"from LDAP, returning None as name")
return None
# Just look at the first result record, since we are searching for
# a specific user
record = res[0][1]
name = record[name_attr][0]
return name
评论列表
文章目录