Skip to content

Commit

Permalink
Apply configuration changes for Multiple LDAP servers
Browse files Browse the repository at this point in the history
  • Loading branch information
jewilmeer committed Oct 13, 2014
1 parent 3cd5abf commit e1cf9c1
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 16 deletions.
18 changes: 16 additions & 2 deletions config/initializers/1_settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,23 @@ def verify_constant(modul, current, default)
# Default settings
Settings['ldap'] ||= Settingslogic.new({})
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['enabled'] = false if Settings.omniauth['enabled'].nil?
Expand Down
4 changes: 4 additions & 0 deletions config/initializers/7_omniauth.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module OmniAuth::Strategies
server = Gitlab.config.ldap.servers.first
const_set(server.provider_class, Class.new(LDAP))
end
30 changes: 16 additions & 14 deletions config/initializers/devise.rb
Original file line number Diff line number Diff line change
Expand Up @@ -205,21 +205,23 @@
# end

if Gitlab.config.ldap.enabled
if Gitlab.config.ldap.allow_username_or_email_login
email_stripping_proc = ->(name) {name.gsub(/@.*$/,'')}
else
email_stripping_proc = ->(name) {name}
Gitlab.config.ldap.servers.each do |server|
if server['allow_username_or_email_login']
email_stripping_proc = ->(name) {name.gsub(/@.*$/,'')}
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

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

Gitlab.config.omniauth.providers.each do |provider|
Expand Down

0 comments on commit e1cf9c1

Please sign in to comment.