Dynamically initiate LDAP strategies

parent 3a358005
......@@ -32,12 +32,9 @@ class OmniauthCallbacksController < Devise::OmniauthCallbacksController
end
end
alias_method :ldap0, :ldap
alias_method :ldap1, :ldap
alias_method :ldap2, :ldap
alias_method :ldap3, :ldap
alias_method :ldap4, :ldap
alias_method :ldap5, :ldap
Gitlab.config.ldap.servers.each do |server|
alias_method "ldap#{server.index}", :ldap
end
def omniauth_error
@provider = params[:provider]
......
......@@ -4,15 +4,15 @@
.login-body
- if ldap_enabled? && gitlab_config.signin_enabled
%ul.nav.nav-tabs
- @ldap_servers.each_with_index do |server, i|
- @ldap_servers.each do |server|
%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
= link_to 'Standard', '#tab-signin', 'data-toggle' => 'tab'
.tab-content
- @ldap_servers.each_with_index do |server, i|
%div.tab-pane{id: "tab-ldap#{i}", class: (:active if server['primary'])}
= render 'devise/sessions/new_ldap', provider: "ldap#{i}"
- @ldap_servers.each do |server|
%div.tab-pane{id: "tab-ldap#{server.index}", class: (:active if server['primary'])}
= render 'devise/sessions/new_ldap', provider: "ldap#{server.index}"
%div#tab-signin.tab-pane
= render 'devise/sessions/new_base'
......@@ -38,7 +38,6 @@
%span.light Did not receive confirmation email?
= link_to "Send again", new_confirmation_path(resource_name)
- if extra_config.has_key?('sign_in_text')
%hr
= markdown(extra_config.sign_in_text)
......@@ -134,63 +134,69 @@ production: &base
# bundle exec rake gitlab:ldap:check RAILS_ENV=production
ldap:
enabled: false
host: '_your_ldap_server'
port: 636
uid: 'sAMAccountName'
method: 'ssl' # "tls" or "ssl" or "plain"
bind_dn: '_the_full_dn_of_the_user_you_will_bind_with'
password: '_the_password_of_the_bind_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.
# How much slower depends on your LDAP setup, but it is not uncommon for this check to add seconds of waiting time.
# The default value is to have a 'slow click' once every 3600 seconds, i.e. once per hour.
#
# Warning: if you set this value too low, every click in GitLab will be a 'slow click' for all of your LDAP users.
# sync_time: 3600
# If allow_username_or_email_login is enabled, GitLab will ignore everything
# after the first '@' in the LDAP username submitted by the user on login.
#
# Example:
# - the user enters 'jane.doe@example.com' and 'p@ssw0rd' as LDAP credentials;
# - GitLab queries the LDAP server with 'jane.doe' and 'p@ssw0rd'.
#
# If you are using "uid: 'userPrincipalName'" on ActiveDirectory you need to
# disable this setting, because the userPrincipalName contains an '@'.
allow_username_or_email_login: false
# Base where we can search for users
#
# Ex. ou=People,dc=gitlab,dc=example
#
base: ''
# Filter LDAP users
#
# Format: RFC 4515
# Ex. (employeeType=developer)
#
user_filter: ''
# Base where we can search for groups
#
# Ex. ou=Groups,dc=gitlab,dc=example
#
group_base: ''
# LDAP group of users who should be admins in GitLab
#
# Ex. GLAdmins
#
admin_group: ''
# Name of attribute which holds a ssh public key of the user object.
# If false or nil, SSH key syncronisation will be disabled.
#
# Ex. sshpublickey
#
sync_ssh_keys: false
servers:
-
host: '_your_ldap_server'
port: 636
uid: 'sAMAccountName'
method: 'ssl' # "tls" or "ssl" or "plain"
bind_dn: '_the_full_dn_of_the_user_you_will_bind_with'
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.
# 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.
# The default value is to have a 'slow click' once every 3600 seconds, i.e. once per hour.
#
# Warning: if you set this value too low, every click in GitLab will be a 'slow click' for all of your LDAP users.
# sync_time: 3600
# If allow_username_or_email_login is enabled, GitLab will ignore everything
# after the first '@' in the LDAP username submitted by the user on login.
#
# Example:
# - the user enters 'jane.doe@example.com' and 'p@ssw0rd' as LDAP credentials;
# - GitLab queries the LDAP server with 'jane.doe' and 'p@ssw0rd'.
#
# If you are using "uid: 'userPrincipalName'" on ActiveDirectory you need to
# disable this setting, because the userPrincipalName contains an '@'.
allow_username_or_email_login: false
# Base where we can search for users
#
# Ex. ou=People,dc=gitlab,dc=example
#
base: ''
# Filter LDAP users
#
# Format: RFC 4515
# Ex. (employeeType=developer)
#
user_filter: ''
# Base where we can search for groups
#
# Ex. ou=Groups,dc=gitlab,dc=example
#
group_base: ''
# LDAP group of users who should be admins in GitLab
#
# Ex. GLAdmins
#
admin_group: ''
# Name of attribute which holds a ssh public key of the user object.
# If false or nil, SSH key syncronisation will be disabled.
#
# Ex. sshpublickey
#
sync_ssh_keys: false
## OmniAuth settings
omniauth:
......
......@@ -64,7 +64,7 @@ if Settings.ldap['enabled'] && Settings.ldap['host'].present?
excluded_per_server_settings = %w(sync_time allow_username_or_email_login)
server = Settings.ldap.except(excluded_per_server_settings)
server['primary'] = true
server['name'] = 'LDAP'
server['label'] = 'LDAP'
Settings.ldap['servers'] = [server]
end
......
module OmniAuth::Strategies
class Ldap0 < LDAP; end
class Ldap1 < LDAP; end
class Ldap2 < LDAP; end
class Ldap3 < LDAP; end
class Ldap4 < LDAP; end
class Ldap5 < LDAP; end
Gitlab.config.ldap.servers.each do |server|
class_name = "Ldap#{server.index}"
const_set(class_name, Class.new(LDAP))
end
end
......@@ -211,8 +211,8 @@ Devise.setup do |config|
email_stripping_proc = ->(name) {name}
end
Gitlab.config.ldap.servers.each_with_index do |server, i|
config.omniauth :"ldap#{i}",
Gitlab.config.ldap.servers.each do |server|
config.omniauth :"ldap#{server.index}",
host: server['host'],
base: server['base'],
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