summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDrew Blessing <drew@gitlab.com>2017-01-05 16:01:04 -0600
committerDrew Blessing <drew@gitlab.com>2017-01-06 00:24:33 -0600
commitde4eee08947fde4b6b1b21e54329dc8f1d958362 (patch)
tree49affdf267a54d960104e549af655a0265e20af2 /lib
parent76bb8ed48ac88210e426e751ff4c3186e3b0d214 (diff)
downloadgitlab-ce-de4eee08947fde4b6b1b21e54329dc8f1d958362.tar.gz
LDAP attributes needs default values
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/ldap/auth_hash.rb2
-rw-r--r--lib/gitlab/ldap/config.rb12
-rw-r--r--lib/gitlab/ldap/person.rb8
3 files changed, 15 insertions, 7 deletions
diff --git a/lib/gitlab/ldap/auth_hash.rb b/lib/gitlab/ldap/auth_hash.rb
index bf4dd9542d5..95378e5a769 100644
--- a/lib/gitlab/ldap/auth_hash.rb
+++ b/lib/gitlab/ldap/auth_hash.rb
@@ -25,7 +25,7 @@ module Gitlab
end
def get_raw(key)
- auth_hash.extra[:raw_info][key]
+ auth_hash.extra[:raw_info][key] if auth_hash.extra
end
def ldap_config
diff --git a/lib/gitlab/ldap/config.rb b/lib/gitlab/ldap/config.rb
index de52ef3fc65..28129198438 100644
--- a/lib/gitlab/ldap/config.rb
+++ b/lib/gitlab/ldap/config.rb
@@ -107,7 +107,7 @@ module Gitlab
end
def attributes
- options['attributes']
+ default_attributes.merge(options['attributes'])
end
def timeout
@@ -130,6 +130,16 @@ module Gitlab
end
end
+ def default_attributes
+ {
+ 'username' => %w(uid userid sAMAccountName),
+ 'email' => %w(mail email userPrincipalName),
+ 'name' => 'cn',
+ 'first_name' => 'givenName',
+ 'last_name' => 'sn'
+ }
+ end
+
protected
def base_options
diff --git a/lib/gitlab/ldap/person.rb b/lib/gitlab/ldap/person.rb
index 333f170a484..7084fd1767d 100644
--- a/lib/gitlab/ldap/person.rb
+++ b/lib/gitlab/ldap/person.rb
@@ -28,7 +28,7 @@ module Gitlab
end
def name
- attribute_value(:name)
+ attribute_value(:name).first
end
def uid
@@ -62,14 +62,12 @@ module Gitlab
# 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])
+ attributes = Array(config.attributes[attribute.to_s])
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
+ entry.public_send(selected_attr)
end
end
end