allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject git commit: [#7221] set display_name for ldap autoregister; decode unicode values from ldap
Date Fri, 26 Sep 2014 01:52:49 GMT
Repository: allura
Updated Branches:
  refs/heads/db/7721 [created] 69f30c4e0


[#7221] set display_name for ldap autoregister; decode unicode values from ldap


Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/69f30c4e
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/69f30c4e
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/69f30c4e

Branch: refs/heads/db/7721
Commit: 69f30c4e0f10056bee3fdc15b0a15341524befa0
Parents: da05789
Author: Dave Brondsema <dbrondsema@slashdotmedia.com>
Authored: Fri Sep 26 01:52:33 2014 +0000
Committer: Dave Brondsema <dbrondsema@slashdotmedia.com>
Committed: Fri Sep 26 01:52:33 2014 +0000

----------------------------------------------------------------------
 Allura/allura/lib/plugin.py | 34 ++++++++++++++++++++--------------
 1 file changed, 20 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/69f30c4e/Allura/allura/lib/plugin.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/plugin.py b/Allura/allura/lib/plugin.py
index 78aae92..256d11c 100644
--- a/Allura/allura/lib/plugin.py
+++ b/Allura/allura/lib/plugin.py
@@ -527,7 +527,9 @@ class LdapAuthenticationProvider(AuthenticationProvider):
         if user is None:
             if asbool(config.get('auth.ldap.autoregister', True)):
                 log.debug('LdapAuth: authorized user {} needs a mongo record registered.
 Creating...'.format(username))
-                user = M.User.register({'username': username})
+                user = M.User.register({'username': username,
+                                        'display_name': LdapUserPreferencesProvider()._get_pref(username,
'display_name'),
+                                        })
             else:
                 log.debug('LdapAuth: no user {} found in local mongo'.format(username))
                 raise exc.HTTPUnauthorized()
@@ -1233,22 +1235,26 @@ class LdapUserPreferencesProvider(UserPreferencesProvider):
     def get_pref(self, user, pref_name):
         from allura import model as M
         if pref_name in self.fields and user != M.User.anonymous():
-            con = ldap_conn()
-            try:
-                rs = con.search_s(ldap_user_dn(user.username), ldap.SCOPE_BASE)
-            except ldap.NO_SUCH_OBJECT:
-                rs = []
-            else:
-                con.unbind_s()
-            if not rs:
-                log.warning('LdapUserPref: No user record found for: {}'.format(user.username))
-                return ''
-            user_dn, user_attrs = rs[0]
-            ldap_attr = self.fields[pref_name]
-            return user_attrs[ldap_attr][0]  # assume single-valued list
+            self._get_pref(user.username, pref_name)
         else:
             return LocalUserPreferencesProvider().get_pref(user, pref_name)
 
+    def _get_pref(self, username, pref_name):
+        con = ldap_conn()
+        try:
+            rs = con.search_s(ldap_user_dn(username), ldap.SCOPE_BASE)
+        except ldap.NO_SUCH_OBJECT:
+            rs = []
+        else:
+            con.unbind_s()
+        if not rs:
+            log.warning('LdapUserPref: No user record found for: {}'.format(user.username))
+            return ''
+        user_dn, user_attrs = rs[0]
+        ldap_attr = self.fields[pref_name]
+        # assume single-valued list
+        return user_attrs[ldap_attr][0].decode('utf-8')
+
     def set_pref(self, user, pref_name, pref_value):
         if pref_name in self.fields:
             con = ldap_conn()


Mime
View raw message