Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Speicher <robert@gitlab.com>2017-01-04 00:11:10 +0300
committerDouglas Barbosa Alexandre <dbalexandre@gmail.com>2017-01-05 20:38:21 +0300
commitdbbac3e9b136e8ef0ae7ed80a99251285cbf60b3 (patch)
tree9e0e7e457450345ca98d1c2eddf03a38697d20a8 /lib/gitlab
parent3352a4c4e100bc01408d3c8bbe14d1d2d760942a (diff)
Merge branch 'ldap_person_attributes' into 'master'
Gitlab::LDAP::Person uses LDAP attributes configuration Closes #26290 See merge request !8418
Diffstat (limited to 'lib/gitlab')
-rw-r--r--lib/gitlab/ldap/person.rb19
1 files changed, 17 insertions, 2 deletions
diff --git a/lib/gitlab/ldap/person.rb b/lib/gitlab/ldap/person.rb
index b81f3e8e8f5..333f170a484 100644
--- a/lib/gitlab/ldap/person.rb
+++ b/lib/gitlab/ldap/person.rb
@@ -28,7 +28,7 @@ module Gitlab
end
def name
- entry.cn.first
+ attribute_value(:name)
end
def uid
@@ -40,7 +40,7 @@ module Gitlab
end
def email
- entry.try(:mail)
+ attribute_value(:email)
end
def dn
@@ -56,6 +56,21 @@ module Gitlab
def config
@config ||= Gitlab::LDAP::Config.new(provider)
end
+
+ # Using the LDAP attributes configuration, find and return the first
+ # attribute with a value. For example, by default, when given 'email',
+ # this method looks for 'mail', 'email' and 'userPrincipalName' and
+ # returns the first with a value.
+ def attribute_value(attribute)
+ attributes = Array(config.attributes[attribute.to_sym])
+ selected_attr = attributes.find { |attr| entry.respond_to?(attr) }
+
+ return nil unless selected_attr
+
+ # Some LDAP attributes return an array,
+ # even if it is a single value (like 'cn')
+ Array(entry.public_send(selected_attr)).first
+ end
end
end
end