Commit da07665bc86588820da048ce5c3f9f7d46c3dd03
Exists in
master
and in
4 other branches
Merge pull request #4289 from karlhungus/feature-ldap-signin-with-email-or-username
Allow the ldap logins with email or username
Showing
3 changed files
with
11 additions
and
1 deletions
Show diff stats
config/gitlab.yml.example
| @@ -97,6 +97,7 @@ production: &base | @@ -97,6 +97,7 @@ production: &base | ||
| 97 | method: 'ssl' # "ssl" or "plain" | 97 | method: 'ssl' # "ssl" or "plain" |
| 98 | bind_dn: '_the_full_dn_of_the_user_you_will_bind_with' | 98 | bind_dn: '_the_full_dn_of_the_user_you_will_bind_with' |
| 99 | password: '_the_password_of_the_bind_user' | 99 | password: '_the_password_of_the_bind_user' |
| 100 | + allow_username_or_email_login: true | ||
| 100 | 101 | ||
| 101 | ## OmniAuth settings | 102 | ## OmniAuth settings |
| 102 | omniauth: | 103 | omniauth: |
config/initializers/1_settings.rb
| @@ -37,6 +37,8 @@ end | @@ -37,6 +37,8 @@ end | ||
| 37 | # Default settings | 37 | # Default settings |
| 38 | Settings['ldap'] ||= Settingslogic.new({}) | 38 | Settings['ldap'] ||= Settingslogic.new({}) |
| 39 | Settings.ldap['enabled'] = false if Settings.ldap['enabled'].nil? | 39 | Settings.ldap['enabled'] = false if Settings.ldap['enabled'].nil? |
| 40 | +Settings.ldap['allow_username_or_email_login'] = false if Settings.ldap['allow_username_or_email_login'].nil? | ||
| 41 | + | ||
| 40 | 42 | ||
| 41 | Settings['omniauth'] ||= Settingslogic.new({}) | 43 | Settings['omniauth'] ||= Settingslogic.new({}) |
| 42 | Settings.omniauth['enabled'] = false if Settings.omniauth['enabled'].nil? | 44 | Settings.omniauth['enabled'] = false if Settings.omniauth['enabled'].nil? |
config/initializers/devise.rb
| @@ -206,6 +206,12 @@ Devise.setup do |config| | @@ -206,6 +206,12 @@ Devise.setup do |config| | ||
| 206 | # end | 206 | # end |
| 207 | 207 | ||
| 208 | if Gitlab.config.ldap.enabled | 208 | if Gitlab.config.ldap.enabled |
| 209 | + if Gitlab.config.ldap.allow_username_or_email_login | ||
| 210 | + email_stripping_proc = ->(name) {name.gsub(/@.*$/,'')} | ||
| 211 | + else | ||
| 212 | + email_stripping_proc = ->(name) {name} | ||
| 213 | + end | ||
| 214 | + | ||
| 209 | config.omniauth :ldap, | 215 | config.omniauth :ldap, |
| 210 | host: Gitlab.config.ldap['host'], | 216 | host: Gitlab.config.ldap['host'], |
| 211 | base: Gitlab.config.ldap['base'], | 217 | base: Gitlab.config.ldap['base'], |
| @@ -213,7 +219,8 @@ Devise.setup do |config| | @@ -213,7 +219,8 @@ Devise.setup do |config| | ||
| 213 | port: Gitlab.config.ldap['port'], | 219 | port: Gitlab.config.ldap['port'], |
| 214 | method: Gitlab.config.ldap['method'], | 220 | method: Gitlab.config.ldap['method'], |
| 215 | bind_dn: Gitlab.config.ldap['bind_dn'], | 221 | bind_dn: Gitlab.config.ldap['bind_dn'], |
| 216 | - password: Gitlab.config.ldap['password'] | 222 | + password: Gitlab.config.ldap['password'], |
| 223 | + name_proc: email_stripping_proc | ||
| 217 | end | 224 | end |
| 218 | 225 | ||
| 219 | Gitlab.config.omniauth.providers.each do |provider| | 226 | Gitlab.config.omniauth.providers.each do |provider| |