Apply configuration changes for Multiple LDAP servers
This commit is contained in:
parent
3cd5abf635
commit
e1cf9c15eb
3 changed files with 36 additions and 16 deletions
|
@ -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?
|
||||||
|
|
4
config/initializers/7_omniauth.rb
Normal file
4
config/initializers/7_omniauth.rb
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
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|
|
||||||
# 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 = []
|
||||||
|
|
Loading…
Reference in a new issue