Use Hash syntax for LDAP server declaration

parent 9bf7bfda
...@@ -19,7 +19,7 @@ class SessionsController < Devise::SessionsController ...@@ -19,7 +19,7 @@ class SessionsController < Devise::SessionsController
end end
if Gitlab.config.ldap.enabled if Gitlab.config.ldap.enabled
@ldap_servers = Gitlab.config.ldap.servers @ldap_servers = Gitlab::LDAP::Config.servers
end end
super super
......
...@@ -6,13 +6,13 @@ ...@@ -6,13 +6,13 @@
%ul.nav.nav-tabs %ul.nav.nav-tabs
- @ldap_servers.each_with_index do |server, i| - @ldap_servers.each_with_index do |server, i|
%li{class: (:active if i==0)} %li{class: (:active if i==0)}
= link_to server['label'], "#tab-#{server.provider_name}", 'data-toggle' => 'tab' = link_to server['label'], "#tab-#{server['provider_name']}", 'data-toggle' => 'tab'
%li %li
= link_to 'Standard', '#tab-signin', 'data-toggle' => 'tab' = link_to 'Standard', '#tab-signin', 'data-toggle' => 'tab'
.tab-content .tab-content
- @ldap_servers.each_with_index do |server,i| - @ldap_servers.each_with_index do |server,i|
%div.tab-pane{id: "tab-#{server.provider_name}", class: (:active if i==0)} %div.tab-pane{id: "tab-#{server['provider_name']}", class: (:active if i==0)}
= render 'devise/sessions/new_ldap', provider: server.provider_name = render 'devise/sessions/new_ldap', provider: server['provider_name']
%div#tab-signin.tab-pane %div#tab-signin.tab-pane
= render 'devise/sessions/new_base' = render 'devise/sessions/new_base'
......
...@@ -135,18 +135,16 @@ production: &base ...@@ -135,18 +135,16 @@ production: &base
ldap: ldap:
enabled: false enabled: false
servers: servers:
- ## provider id
## provider_id #
# # This identifier is used by GitLab to keep track of which LDAP server each
# This identifier is used by GitLab to keep track of which LDAP server each # GitLab user belongs to. Each LDAP server known to GitLab should have a unique
# GitLab user belongs to. Each LDAP server known to GitLab should have a unique # provider id. This identifier cannot be changed once users from the LDAP server
# provider_id. This identifier cannot be changed once users from the LDAP server # have started logging in to GitLab.
# have started logging in to GitLab. #
# # Format: one word, using a-z (lower case) and 0-9
# Format: one word, using a-z (lower case) and 0-9 # Example: 'paris' or 'uswest2'
# Example: 'paris' or 'uswest2' main:
provider_id: main
## label ## label
# #
......
...@@ -62,14 +62,16 @@ if Settings.ldap['enabled'] || Rails.env.test? ...@@ -62,14 +62,16 @@ if Settings.ldap['enabled'] || Rails.env.test?
if Settings.ldap['host'].present? if Settings.ldap['host'].present?
server = Settings.ldap.except('sync_time') server = Settings.ldap.except('sync_time')
server['label'] = 'LDAP' server['label'] = 'LDAP'
server['provider_id'] = '' server['provider_name'] = 'ldap'
Settings.ldap['servers'] = [server] Settings.ldap['servers'] = {
'ldap' => server
}
end end
Settings.ldap['servers'].each do |server| Settings.ldap['servers'].each do |key, server|
server['allow_username_or_email_login'] = false if server['allow_username_or_email_login'].nil? 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['active_directory'] = true if server['active_directory'].nil?
server['provider_name'] = "ldap#{server['provider_id']}".downcase server['provider_name'] ||= "ldap#{key}".downcase
server['provider_class'] = OmniAuth::Utils.camelize(server['provider_name']) server['provider_class'] = OmniAuth::Utils.camelize(server['provider_name'])
end end
end end
......
module OmniAuth::Strategies module OmniAuth::Strategies
server = Gitlab.config.ldap.servers.first server = Gitlab.config.ldap.servers.values.first
const_set(server.provider_class, Class.new(LDAP)) const_set(server['provider_class'], Class.new(LDAP))
end end
OmniauthCallbacksController.class_eval do OmniauthCallbacksController.class_eval do
server = Gitlab.config.ldap.servers.first server = Gitlab.config.ldap.servers.values.first
alias_method server.provider_name, :ldap alias_method server['provider_name'], :ldap
end end
\ No newline at end of file
...@@ -205,14 +205,14 @@ Devise.setup do |config| ...@@ -205,14 +205,14 @@ Devise.setup do |config|
# end # end
if Gitlab.config.ldap.enabled if Gitlab.config.ldap.enabled
Gitlab.config.ldap.servers.each do |server| Gitlab.config.ldap.servers.values.each do |server|
if server['allow_username_or_email_login'] 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 server.provider_name, config.omniauth server['provider_name'],
host: server['host'], host: server['host'],
base: server['base'], base: server['base'],
uid: server['uid'], uid: server['uid'],
......
...@@ -9,11 +9,11 @@ module Gitlab ...@@ -9,11 +9,11 @@ module Gitlab
end end
def self.servers def self.servers
Gitlab.config.ldap.servers Gitlab.config.ldap.servers.values
end end
def self.providers def self.providers
servers.map &:provider_name servers.map {|server| server['provider_name'] }
end end
def initialize(provider) def initialize(provider)
...@@ -75,7 +75,7 @@ module Gitlab ...@@ -75,7 +75,7 @@ module Gitlab
end end
def config_for(provider) def config_for(provider)
base_config.servers.find { |server| server.provider_name == provider } base_config.servers.values.find { |server| server['provider_name'] == provider }
end end
def encryption def encryption
......
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