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,63 +134,69 @@ production: &base ...@@ -134,63 +134,69 @@ 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
host: '_your_ldap_server' servers:
port: 636 -
uid: 'sAMAccountName' host: '_your_ldap_server'
method: 'ssl' # "tls" or "ssl" or "plain" port: 636
bind_dn: '_the_full_dn_of_the_user_you_will_bind_with' uid: 'sAMAccountName'
password: '_the_password_of_the_bind_user' method: 'ssl' # "tls" or "ssl" or "plain"
bind_dn: '_the_full_dn_of_the_user_you_will_bind_with'
# This setting controls the amount of time between LDAP permission checks for each user. password: '_the_password_of_the_bind_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. # When authenticating against an ldap server, this will provide a unique identifier
# The default value is to have a 'slow click' once every 3600 seconds, i.e. once per hour. # Only use uniq numbers here
# index: 1
# 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 # 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.
# If allow_username_or_email_login is enabled, GitLab will ignore everything # How much slower depends on your LDAP setup, but it is not uncommon for this check to add seconds of waiting time.
# after the first '@' in the LDAP username submitted by the user on login. # The default value is to have a 'slow click' once every 3600 seconds, i.e. once per hour.
# #
# Example: # Warning: if you set this value too low, every click in GitLab will be a 'slow click' for all of your LDAP users.
# - the user enters 'jane.doe@example.com' and 'p@ssw0rd' as LDAP credentials; # sync_time: 3600
# - GitLab queries the LDAP server with 'jane.doe' and 'p@ssw0rd'.
# # If allow_username_or_email_login is enabled, GitLab will ignore everything
# If you are using "uid: 'userPrincipalName'" on ActiveDirectory you need to # after the first '@' in the LDAP username submitted by the user on login.
# disable this setting, because the userPrincipalName contains an '@'. #
allow_username_or_email_login: false # Example:
# - the user enters 'jane.doe@example.com' and 'p@ssw0rd' as LDAP credentials;
# Base where we can search for users # - GitLab queries the LDAP server with 'jane.doe' and 'p@ssw0rd'.
# #
# Ex. ou=People,dc=gitlab,dc=example # If you are using "uid: 'userPrincipalName'" on ActiveDirectory you need to
# # disable this setting, because the userPrincipalName contains an '@'.
base: '' allow_username_or_email_login: false
# Filter LDAP users # Base where we can search for users
# #
# Format: RFC 4515 # Ex. ou=People,dc=gitlab,dc=example
# Ex. (employeeType=developer) #
# base: ''
user_filter: ''
# Filter LDAP users
# Base where we can search for groups #
# # Format: RFC 4515
# Ex. ou=Groups,dc=gitlab,dc=example # Ex. (employeeType=developer)
# #
group_base: '' user_filter: ''
# LDAP group of users who should be admins in GitLab # Base where we can search for groups
# #
# Ex. GLAdmins # Ex. ou=Groups,dc=gitlab,dc=example
# #
admin_group: '' group_base: ''
# Name of attribute which holds a ssh public key of the user object. # LDAP group of users who should be admins in GitLab
# If false or nil, SSH key syncronisation will be disabled. #
# # Ex. GLAdmins
# Ex. sshpublickey #
# admin_group: ''
sync_ssh_keys: false
# 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 settings
omniauth: omniauth:
......
...@@ -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