Dynamically initiate LDAP strategies

parent 3a358005
...@@ -32,12 +32,9 @@ class OmniauthCallbacksController < Devise::OmniauthCallbacksController ...@@ -32,12 +32,9 @@ class OmniauthCallbacksController < Devise::OmniauthCallbacksController
end end
end end
alias_method :ldap0, :ldap Gitlab.config.ldap.servers.each do |server|
alias_method :ldap1, :ldap alias_method "ldap#{server.index}", :ldap
alias_method :ldap2, :ldap end
alias_method :ldap3, :ldap
alias_method :ldap4, :ldap
alias_method :ldap5, :ldap
def omniauth_error def omniauth_error
@provider = params[:provider] @provider = params[:provider]
......
...@@ -4,15 +4,15 @@ ...@@ -4,15 +4,15 @@
.login-body .login-body
- if ldap_enabled? && gitlab_config.signin_enabled - if ldap_enabled? && gitlab_config.signin_enabled
%ul.nav.nav-tabs %ul.nav.nav-tabs
- @ldap_servers.each_with_index do |server, i| - @ldap_servers.each do |server|
%li{class: (:active if server['primary'])} %li{class: (:active if server['primary'])}
= link_to server['name'], "#tab-ldap#{i}", 'data-toggle' => 'tab' = link_to server['label'], "#tab-ldap#{server.index}", '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 do |server|
%div.tab-pane{id: "tab-ldap#{i}", class: (:active if server['primary'])} %div.tab-pane{id: "tab-ldap#{server.index}", class: (:active if server['primary'])}
= render 'devise/sessions/new_ldap', provider: "ldap#{i}" = render 'devise/sessions/new_ldap', provider: "ldap#{server.index}"
%div#tab-signin.tab-pane %div#tab-signin.tab-pane
= render 'devise/sessions/new_base' = render 'devise/sessions/new_base'
...@@ -38,7 +38,6 @@ ...@@ -38,7 +38,6 @@
%span.light Did not receive confirmation email? %span.light Did not receive confirmation email?
= link_to "Send again", new_confirmation_path(resource_name) = link_to "Send again", new_confirmation_path(resource_name)
- if extra_config.has_key?('sign_in_text') - if extra_config.has_key?('sign_in_text')
%hr %hr
= markdown(extra_config.sign_in_text) = markdown(extra_config.sign_in_text)
...@@ -134,6 +134,8 @@ production: &base ...@@ -134,6 +134,8 @@ production: &base
# bundle exec rake gitlab:ldap:check RAILS_ENV=production # bundle exec rake gitlab:ldap:check RAILS_ENV=production
ldap: ldap:
enabled: false enabled: false
servers:
-
host: '_your_ldap_server' host: '_your_ldap_server'
port: 636 port: 636
uid: 'sAMAccountName' uid: 'sAMAccountName'
...@@ -141,6 +143,10 @@ production: &base ...@@ -141,6 +143,10 @@ production: &base
bind_dn: '_the_full_dn_of_the_user_you_will_bind_with' bind_dn: '_the_full_dn_of_the_user_you_will_bind_with'
password: '_the_password_of_the_bind_user' password: '_the_password_of_the_bind_user'
# When authenticating against an ldap server, this will provide a unique identifier
# Only use uniq numbers here
index: 1
# This setting controls the amount of time between LDAP permission checks for each user. # This setting controls the amount of time between LDAP permission checks for each user.
# After this time has expired for a given user, their next interaction with GitLab (a click in the web UI, a git pull etc.) will be slower because the LDAP permission check is being performed. # After this time has expired for a given user, their next interaction with GitLab (a click in the web UI, a git pull etc.) will be slower because the LDAP permission check is being performed.
# How much slower depends on your LDAP setup, but it is not uncommon for this check to add seconds of waiting time. # How much slower depends on your LDAP setup, but it is not uncommon for this check to add seconds of waiting time.
......
...@@ -64,7 +64,7 @@ if Settings.ldap['enabled'] && Settings.ldap['host'].present? ...@@ -64,7 +64,7 @@ if Settings.ldap['enabled'] && Settings.ldap['host'].present?
excluded_per_server_settings = %w(sync_time allow_username_or_email_login) excluded_per_server_settings = %w(sync_time allow_username_or_email_login)
server = Settings.ldap.except(excluded_per_server_settings) server = Settings.ldap.except(excluded_per_server_settings)
server['primary'] = true server['primary'] = true
server['name'] = 'LDAP' server['label'] = 'LDAP'
Settings.ldap['servers'] = [server] Settings.ldap['servers'] = [server]
end end
......
module OmniAuth::Strategies module OmniAuth::Strategies
class Ldap0 < LDAP; end Gitlab.config.ldap.servers.each do |server|
class Ldap1 < LDAP; end class_name = "Ldap#{server.index}"
class Ldap2 < LDAP; end const_set(class_name, Class.new(LDAP))
class Ldap3 < LDAP; end end
class Ldap4 < LDAP; end
class Ldap5 < LDAP; end
end end
...@@ -211,8 +211,8 @@ Devise.setup do |config| ...@@ -211,8 +211,8 @@ Devise.setup do |config|
email_stripping_proc = ->(name) {name} email_stripping_proc = ->(name) {name}
end end
Gitlab.config.ldap.servers.each_with_index do |server, i| Gitlab.config.ldap.servers.each do |server|
config.omniauth :"ldap#{i}", config.omniauth :"ldap#{server.index}",
host: server['host'], host: server['host'],
base: server['base'], base: server['base'],
uid: server['uid'], uid: server['uid'],
......
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