Use Hash syntax for LDAP server declaration

parent 9bf7bfda
......@@ -19,7 +19,7 @@ class SessionsController < Devise::SessionsController
end
if Gitlab.config.ldap.enabled
@ldap_servers = Gitlab.config.ldap.servers
@ldap_servers = Gitlab::LDAP::Config.servers
end
super
......
......@@ -6,13 +6,13 @@
%ul.nav.nav-tabs
- @ldap_servers.each_with_index do |server, i|
%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
= link_to 'Standard', '#tab-signin', 'data-toggle' => 'tab'
.tab-content
- @ldap_servers.each_with_index do |server,i|
%div.tab-pane{id: "tab-#{server.provider_name}", class: (:active if i==0)}
= render 'devise/sessions/new_ldap', provider: server.provider_name
%div.tab-pane{id: "tab-#{server['provider_name']}", class: (:active if i==0)}
= render 'devise/sessions/new_ldap', provider: server['provider_name']
%div#tab-signin.tab-pane
= render 'devise/sessions/new_base'
......
......@@ -135,18 +135,16 @@ production: &base
ldap:
enabled: false
servers:
-
## provider_id
## provider id
#
# 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
# 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.
#
# Format: one word, using a-z (lower case) and 0-9
# Example: 'paris' or 'uswest2'
provider_id: main
main:
## label
#
......
......@@ -62,14 +62,16 @@ 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]
server['provider_name'] = 'ldap'
Settings.ldap['servers'] = {
'ldap' => server
}
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['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'])
end
end
......
module OmniAuth::Strategies
server = Gitlab.config.ldap.servers.first
const_set(server.provider_class, Class.new(LDAP))
server = Gitlab.config.ldap.servers.values.first
const_set(server['provider_class'], Class.new(LDAP))
end
OmniauthCallbacksController.class_eval do
server = Gitlab.config.ldap.servers.first
alias_method server.provider_name, :ldap
server = Gitlab.config.ldap.servers.values.first
alias_method server['provider_name'], :ldap
end
\ No newline at end of file
......@@ -205,14 +205,14 @@ Devise.setup do |config|
# end
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']
email_stripping_proc = ->(name) {name.gsub(/@.*$/,'')}
else
email_stripping_proc = ->(name) {name}
end
config.omniauth server.provider_name,
config.omniauth server['provider_name'],
host: server['host'],
base: server['base'],
uid: server['uid'],
......
......@@ -9,11 +9,11 @@ module Gitlab
end
def self.servers
Gitlab.config.ldap.servers
Gitlab.config.ldap.servers.values
end
def self.providers
servers.map &:provider_name
servers.map {|server| server['provider_name'] }
end
def initialize(provider)
......@@ -75,7 +75,7 @@ module Gitlab
end
def config_for(provider)
base_config.servers.find { |server| server.provider_name == provider }
base_config.servers.values.find { |server| server['provider_name'] == provider }
end
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