BigW Consortium Gitlab

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,21 +205,23 @@ Devise.setup do |config| ...@@ -205,21 +205,23 @@ 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|
email_stripping_proc = ->(name) {name.gsub(/@.*$/,'')} if server['allow_username_or_email_login']
else email_stripping_proc = ->(name) {name.gsub(/@.*$/,'')}
email_stripping_proc = ->(name) {name} else
email_stripping_proc = ->(name) {name}
end
config.omniauth server.provider_name,
host: server['host'],
base: server['base'],
uid: server['uid'],
port: server['port'],
method: server['method'],
bind_dn: server['bind_dn'],
password: server['password'],
name_proc: email_stripping_proc
end end
config.omniauth :ldap,
host: Gitlab.config.ldap['host'],
base: Gitlab.config.ldap['base'],
uid: Gitlab.config.ldap['uid'],
port: Gitlab.config.ldap['port'],
method: Gitlab.config.ldap['method'],
bind_dn: Gitlab.config.ldap['bind_dn'],
password: Gitlab.config.ldap['password'],
name_proc: email_stripping_proc
end end
Gitlab.config.omniauth.providers.each do |provider| Gitlab.config.omniauth.providers.each do |provider|
......
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