|
|
@@ -21,6 +21,7 @@ User Admin to work seamlessly with LDAP.
|
|
|
from builtins import str, object
|
|
|
|
|
|
import logging
|
|
|
+import sys
|
|
|
|
|
|
LOG = logging.getLogger(__name__)
|
|
|
|
|
|
@@ -33,13 +34,16 @@ except ImportError:
|
|
|
SCOPE_SUBTREE = None
|
|
|
import re
|
|
|
|
|
|
-from django.utils.encoding import smart_text
|
|
|
-
|
|
|
import desktop.conf
|
|
|
from desktop.lib.python_util import CaseInsensitiveDict
|
|
|
|
|
|
from useradmin.models import User
|
|
|
|
|
|
+if sys.version_info[0] > 2:
|
|
|
+ from django.utils.encoding import smart_str
|
|
|
+else:
|
|
|
+ from django.utils.encoding import smart_text as smart_str
|
|
|
+
|
|
|
CACHED_LDAP_CONN = None
|
|
|
|
|
|
|
|
|
@@ -245,26 +249,26 @@ class LdapConnection(object):
|
|
|
|
|
|
ldap_info = {
|
|
|
'dn': dn,
|
|
|
- 'username': smart_text(data[user_name_attr][0])
|
|
|
+ 'username': smart_str(data[user_name_attr][0])
|
|
|
}
|
|
|
|
|
|
if 'givenName' in data:
|
|
|
- first_name = smart_text(data['givenName'][0])
|
|
|
+ first_name = smart_str(data['givenName'][0])
|
|
|
if len(first_name) > 30:
|
|
|
LOG.warn('First name is truncated to 30 characters for [<User: %s>].' % ldap_info['username'])
|
|
|
ldap_info['first'] = first_name[:30]
|
|
|
if 'sn' in data:
|
|
|
- last_name = smart_text(data['sn'][0])
|
|
|
+ last_name = smart_str(data['sn'][0])
|
|
|
if len(last_name) > 30:
|
|
|
LOG.warn('Last name is truncated to 30 characters for [<User: %s>].' % ldap_info['username'])
|
|
|
ldap_info['last'] = last_name[:30]
|
|
|
if 'mail' in data:
|
|
|
- ldap_info['email'] = smart_text(data['mail'][0])
|
|
|
+ ldap_info['email'] = smart_str(data['mail'][0])
|
|
|
# memberOf and isMemberOf should be the same if they both exist
|
|
|
if 'memberOf' in data:
|
|
|
- ldap_info['groups'] = [smart_text(member) for member in data['memberOf']]
|
|
|
+ ldap_info['groups'] = [smart_str(member) for member in data['memberOf']]
|
|
|
if 'isMemberOf' in data:
|
|
|
- ldap_info['groups'] = [smart_text(member) for member in data['isMemberOf']]
|
|
|
+ ldap_info['groups'] = [smart_str(member) for member in data['isMemberOf']]
|
|
|
|
|
|
user_info.append(ldap_info)
|
|
|
return user_info
|