diff options
author | Tiago Botelho <tiagonbotelho@hotmail.com> | 2017-09-25 16:14:22 +0100 |
---|---|---|
committer | Tiago Botelho <tiagonbotelho@hotmail.com> | 2017-09-25 16:14:22 +0100 |
commit | cd85a558dc3e568b327e2b0502b59b34d17b19bd (patch) | |
tree | 210680ae0b1c333fdc277ee8fbbd585ddb6b90ad | |
parent | 718e5b0865a0d871f01b12c22a15757dc1fcc66b (diff) | |
download | gitlab-ce-cd85a558dc3e568b327e2b0502b59b34d17b19bd.tar.gz |
Creates compound query for LDAP email attributes.
-rw-r--r-- | lib/gitlab/ldap/adapter.rb | 20 | ||||
-rw-r--r-- | lib/gitlab/ldap/person.rb | 2 |
2 files changed, 15 insertions, 7 deletions
diff --git a/lib/gitlab/ldap/adapter.rb b/lib/gitlab/ldap/adapter.rb index cd7e4ca7b7e..8bbd4af58e0 100644 --- a/lib/gitlab/ldap/adapter.rb +++ b/lib/gitlab/ldap/adapter.rb @@ -73,19 +73,27 @@ module Gitlab private def user_options(field, value, limit) - options = { attributes: Gitlab::LDAP::Person.ldap_attributes(config).compact.uniq } + filter = nil + options = { + attributes: Gitlab::LDAP::Person.ldap_attributes(config).compact.uniq, + base: config.base + } + options[:size] = limit if limit - if field.to_sym == :dn + case field.to_sym + when :dn options[:base] = value options[:scope] = Net::LDAP::SearchScope_BaseObject - options[:filter] = user_filter + when :email + filter = config.attributes['email'].map do |field| + Net::LDAP::Filter.eq(field, value) + end.inject(:|) else - options[:base] = config.base - options[:filter] = user_filter(Net::LDAP::Filter.eq(field, value)) + filter = Net::LDAP::Filter.eq(field, value) end - options + options.merge(filter: user_filter(filter)) end def user_filter(filter = nil) diff --git a/lib/gitlab/ldap/person.rb b/lib/gitlab/ldap/person.rb index be64cc3991b..7631d9e8b17 100644 --- a/lib/gitlab/ldap/person.rb +++ b/lib/gitlab/ldap/person.rb @@ -18,7 +18,7 @@ module Gitlab end def self.find_by_email(email, adapter) - Array(adapter.config.attributes['email']).find { |attr| adapter.user(attr, email) } + adapter.user('email', email) end def self.disabled_via_active_directory?(dn, adapter) |