From b215350edf7bef6119d90d5d307e3621d3168fce Mon Sep 17 00:00:00 2001 From: Oleg Girko Date: Thu, 24 Oct 2013 00:20:48 +0100 Subject: [PATCH] Set username field of users created from LDAP to uid attribute. The previous approach of making username from user part of email address (part of address before '@') has the following limitations: * username in email is not guaranteed to be unique, * email could have nothing to do with user identity in LDAP (like presonal email on an external email service). On the other hand, LDAP uid is guaranteed to be unique, as it represents user's login name on Unix/Linux systems. To understand this change, please note that gitlab_omniauth-ldap Ruby gem uses the following mapping to store LDAP attrinbutes in auth info: * dn attribute of LDAP entry is stored in uid attribute of auth info; * uid attribute of LDAP entry is stored in nickname attribute of auth info. Signed-off-by: Oleg Girko --- lib/gitlab/ldap/user.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/gitlab/ldap/user.rb b/lib/gitlab/ldap/user.rb index c8f3a69376..06c1e37063 100644 --- a/lib/gitlab/ldap/user.rb +++ b/lib/gitlab/ldap/user.rb @@ -13,8 +13,8 @@ module Gitlab def find_or_create(auth) @auth = auth - if uid.blank? || email.blank? - raise_error("Account must provide an uid and email address") + if uid.blank? || email.blank? || username.blank? + raise_error("Account must provide a dn, uid and email address") end user = find(auth) @@ -64,6 +64,10 @@ module Gitlab model.where(provider: provider, extern_uid: uid).last end + def username + auth.info.nickname.to_s.force_encoding("utf-8") + end + def provider 'ldap' end