Apply configuration changes for Multiple LDAP servers

parent 3cd5abf6
...@@ -56,9 +56,23 @@ end ...@@ -56,9 +56,23 @@ end
# Default settings # Default settings
Settings['ldap'] ||= Settingslogic.new({}) Settings['ldap'] ||= Settingslogic.new({})
Settings.ldap['enabled'] = false if Settings.ldap['enabled'].nil? Settings.ldap['enabled'] = false if Settings.ldap['enabled'].nil?
Settings.ldap['allow_username_or_email_login'] = false if Settings.ldap['allow_username_or_email_login'].nil?
Settings.ldap['active_directory'] = true if Settings.ldap['active_directory'].nil?
# backwards compatibility, we only have one host
if Settings.ldap['enabled'] || Rails.env.test?
if Settings.ldap['host'].present?
server = Settings.ldap.except('sync_time')
server['label'] = 'LDAP'
server['provider_id'] = ''
Settings.ldap['servers'] = [server]
end
Settings.ldap['servers'].each do |server|
server['allow_username_or_email_login'] = false if server['allow_username_or_email_login'].nil?
server['active_directory'] = true if server['active_directory'].nil?
server['provider_name'] = "ldap#{server['provider_id']}".downcase
server['provider_class'] = OmniAuth::Utils.camelize(server['provider_name'])
end
end
Settings['omniauth'] ||= Settingslogic.new({}) Settings['omniauth'] ||= Settingslogic.new({})
Settings.omniauth['enabled'] = false if Settings.omniauth['enabled'].nil? Settings.omniauth['enabled'] = false if Settings.omniauth['enabled'].nil?
......
module OmniAuth::Strategies
server = Gitlab.config.ldap.servers.first
const_set(server.provider_class, Class.new(LDAP))
end
...@@ -205,22 +205,24 @@ Devise.setup do |config| ...@@ -205,22 +205,24 @@ Devise.setup do |config|
# end # end
if Gitlab.config.ldap.enabled if Gitlab.config.ldap.enabled
if Gitlab.config.ldap.allow_username_or_email_login Gitlab.config.ldap.servers.each do |server|
if server['allow_username_or_email_login']
email_stripping_proc = ->(name) {name.gsub(/@.*$/,'')} email_stripping_proc = ->(name) {name.gsub(/@.*$/,'')}
else else
email_stripping_proc = ->(name) {name} email_stripping_proc = ->(name) {name}
end end
config.omniauth :ldap, config.omniauth server.provider_name,
host: Gitlab.config.ldap['host'], host: server['host'],
base: Gitlab.config.ldap['base'], base: server['base'],
uid: Gitlab.config.ldap['uid'], uid: server['uid'],
port: Gitlab.config.ldap['port'], port: server['port'],
method: Gitlab.config.ldap['method'], method: server['method'],
bind_dn: Gitlab.config.ldap['bind_dn'], bind_dn: server['bind_dn'],
password: Gitlab.config.ldap['password'], password: server['password'],
name_proc: email_stripping_proc name_proc: email_stripping_proc
end end
end
Gitlab.config.omniauth.providers.each do |provider| Gitlab.config.omniauth.providers.each do |provider|
provider_arguments = [] provider_arguments = []
......
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