Index: config/locales/en.yml =================================================================== --- config/locales/en.yml (revision 9903) +++ config/locales/en.yml (working copy) @@ -142,6 +142,7 @@ notice_account_updated: Account was successfully updated. notice_account_invalid_creditentials: Invalid user or password + notice_account_authentication_timeout: Connection to authentication server timed out notice_account_password_updated: Password was successfully updated. notice_account_wrong_password: Wrong password notice_account_register_done: Account was successfully created. To activate your account, click on the link that was emailed to you. Index: app/models/auth_source_ldap.rb =================================================================== --- app/models/auth_source_ldap.rb (revision 9903) +++ app/models/auth_source_ldap.rb (working copy) @@ -18,6 +18,7 @@ require 'iconv' require 'net/ldap' require 'net/ldap/dn' +require 'timeout' class AuthSourceLdap < AuthSource validates_presence_of :host, :port, :attr_login @@ -44,8 +45,17 @@ def authenticate(login, password) return nil if login.blank? || password.blank? - attrs = get_user_dn(login, password) + timeout = 30 # TODO: Convert to setting + timoutStatus = nil + begin + timoutStatus = Timeout::timeout(timeout) do + attrs = get_user_dn(login, password) + end + rescue Timeout::Error => e + raise Timeout::Error.new(e.message) + end + if attrs && attrs[:dn] && authenticate_dn(attrs[:dn], password) logger.debug "Authentication successful for '#{login}'" if logger && logger.debug? return attrs.except(:dn) Index: app/controllers/account_controller.rb =================================================================== --- app/controllers/account_controller.rb (revision 9903) +++ app/controllers/account_controller.rb (working copy) @@ -150,6 +150,8 @@ # Valid user successful_authentication(user) end + rescue Timeout::Error => e + auth_source_timeout end def open_id_authenticate(openid_url) @@ -229,6 +231,11 @@ flash.now[:error] = l(:notice_account_invalid_creditentials) end + def auth_source_timeout + logger.warn "Failed to authenticate user '#{params[:username]}' at #{Time.now.utc} because the authentication source connection timed out" + flash.now[:error] = l(:notice_account_authentication_timeout) + end + # Register a user for email activation. # # Pass a block for behavior when a user fails to save