Commit b215350e authored by Oleg Girko's avatar Oleg Girko

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: default avatarOleg Girko <oleg.girko@jolla.com>
parent 3a9bda2a
......@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment