From e23a26aea02ebef4aefa1463ebf589c7c5c4bff0 Mon Sep 17 00:00:00 2001 From: Jan-Willem van der Meer Date: Fri, 3 Oct 2014 17:27:35 +0200 Subject: [PATCH] Add provider context to Ldap::Access --- lib/gitlab/ldap/access.rb | 18 ++++++++++++------ lib/gitlab/ldap/user.rb | 2 +- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/lib/gitlab/ldap/access.rb b/lib/gitlab/ldap/access.rb index adf12f5abdb..901acb63057 100644 --- a/lib/gitlab/ldap/access.rb +++ b/lib/gitlab/ldap/access.rb @@ -1,16 +1,21 @@ +# LDAP authorization model +# +# * Check if we are allowed access (not blocked) +# * Update authorizations and associations +# module Gitlab module LDAP class Access - attr_reader :adapter + attr_reader :adapter, :provider - def self.open(&block) - Gitlab::LDAP::Adapter.open do |adapter| - block.call(self.new(adapter)) + def self.open(provider, &block) + Gitlab::LDAP::Adapter.open(provider) do |adapter| + block.call(self.new(provider, adapter)) end end def self.allowed?(user) - self.open do |access| + self.open(user.provider) do |access| if access.allowed?(user) access.update_permissions(user) access.update_email(user) @@ -23,7 +28,8 @@ module Gitlab end end - def initialize(adapter=nil) + def initialize(provider, adapter=nil) + @provider = provider @adapter = adapter end diff --git a/lib/gitlab/ldap/user.rb b/lib/gitlab/ldap/user.rb index a50a30d6bdc..28a48671d85 100644 --- a/lib/gitlab/ldap/user.rb +++ b/lib/gitlab/ldap/user.rb @@ -66,7 +66,7 @@ module Gitlab def find_by_uid_and_provider # LDAP distinguished name is case-insensitive model. - where(provider: auth_hash.provider). + where(provider: [auth_hash.provider, :ldap]). where('lower(extern_uid) = ?', auth_hash.uid.downcase).last end -- GitLab