diff options
Diffstat (limited to 'config')
-rw-r--r-- | config/application.rb | 1 | ||||
-rw-r--r-- | config/initializers/devise.rb | 34 | ||||
-rw-r--r-- | config/locales/en.yml | 1 |
3 files changed, 36 insertions, 0 deletions
diff --git a/config/application.rb b/config/application.rb index cd180782c..34b9dcf48 100644 --- a/config/application.rb +++ b/config/application.rb @@ -12,6 +12,7 @@ require_relative '../lib/paperclip/gif_transcoder' require_relative '../lib/paperclip/video_transcoder' require_relative '../lib/mastodon/snowflake' require_relative '../lib/mastodon/version' +require_relative '../lib/devise/ldap_authenticatable' Dotenv::Railtie.load diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb index ba7ad9e6c..0dc202976 100644 --- a/config/initializers/devise.rb +++ b/config/initializers/devise.rb @@ -36,6 +36,26 @@ module Devise mattr_accessor :pam_controlled_service @@pam_controlled_service = nil + mattr_accessor :check_at_sign + @@check_at_sign = false + + mattr_accessor :ldap_authentication + @@ldap_authentication = false + mattr_accessor :ldap_host + @@ldap_host = nil + mattr_accessor :ldap_port + @@ldap_port = nil + mattr_accessor :ldap_method + @@ldap_method = nil + mattr_accessor :ldap_base + @@ldap_base = nil + mattr_accessor :ldap_uid + @@ldap_uid = nil + mattr_accessor :ldap_bind_dn + @@ldap_bind_dn = nil + mattr_accessor :ldap_password + @@ldap_password = nil + class Strategies::PamAuthenticatable def valid? super && ::Devise.pam_authentication @@ -45,6 +65,8 @@ end Devise.setup do |config| config.warden do |manager| + manager.default_strategies(scope: :user).unshift :ldap_authenticatable if Devise.ldap_authentication + manager.default_strategies(scope: :user).unshift :pam_authenticatable if Devise.pam_authentication manager.default_strategies(scope: :user).unshift :two_factor_authenticatable manager.default_strategies(scope: :user).unshift :two_factor_backupable end @@ -324,4 +346,16 @@ Devise.setup do |config| config.pam_default_service = ENV.fetch('PAM_DEFAULT_SERVICE') { 'rpam' } config.pam_controlled_service = ENV.fetch('PAM_CONTROLLED_SERVICE') { 'rpam' } end + + if ENV['LDAP_ENABLED'] == 'true' + config.ldap_authentication = true + config.check_at_sign = true + config.ldap_host = ENV.fetch('LDAP_HOST', 'localhost') + config.ldap_port = ENV.fetch('LDAP_PORT', 389).to_i + config.ldap_method = ENV.fetch('LDAP_METHOD', :simple_tls).to_sym + config.ldap_base = ENV.fetch('LDAP_BASE') + config.ldap_bind_dn = ENV.fetch('LDAP_BIND_DN') + config.ldap_password = ENV.fetch('LDAP_PASSWORD') + config.ldap_uid = ENV.fetch('LDAP_UID', 'cn') + end end diff --git a/config/locales/en.yml b/config/locales/en.yml index 026426c84..797ec6ac1 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -769,4 +769,5 @@ en: users: invalid_email: The e-mail address is invalid invalid_otp_token: Invalid two-factor code + seamless_external_login: You are logged in via an external service, so password and e-mail settings are not available. signed_in_as: 'Signed in as:' |