]> source.dussan.org Git - redmine.git/commitdiff
Friendly response when the LDAP connection fails.
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 19 Feb 2012 18:13:46 +0000 (18:13 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 19 Feb 2012 18:13:46 +0000 (18:13 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@8911 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/controllers/account_controller.rb
app/models/auth_source.rb
app/models/auth_source_ldap.rb
test/functional/account_controller_test.rb

index 6729b4702d79edacf9cc76a4181dd80f068758c3..3874d2d8921d578f0a197a145c30c119c6e69380 100644 (file)
@@ -29,6 +29,9 @@ class AccountController < ApplicationController
     else
       authenticate_user
     end
+  rescue AuthSourceException => e
+    logger.error "An error occured when authenticating #{params[:username]}: #{e.message}"
+    render_error :message => e.message
   end
 
   # Log out current user and redirect to welcome page
index ae50febc59aba23eb5cf9a4387f9ee51f5ed45b8..933be904a71b3bdcb3f9f7c4d84fa14c59d7e98b 100644 (file)
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
+# Generic exception for when the AuthSource can not be reached
+# (eg. can not connect to the LDAP)
+class AuthSourceException < Exception; end
+
 class AuthSource < ActiveRecord::Base
   include Redmine::Ciphering
 
index cfb02b88194daa1014f92506e0aafb4ae5ac4055..5c6d28cb2f3578aa16a29c76b8773676ce032c8d 100644 (file)
@@ -40,8 +40,8 @@ class AuthSourceLdap < AuthSource
       logger.debug "Authentication successful for '#{login}'" if logger && logger.debug?
       return attrs.except(:dn)
     end
-  rescue  Net::LDAP::LdapError => text
-    raise "LdapError: " + text
+  rescue  Net::LDAP::LdapError => e
+    raise AuthSourceException.new(e.message)
   end
 
   # test the connection to the LDAP
index 00142ffd0df4aad9c515a99ca6c43219ffbaa6ce..5bf65b9abb652ce8f65281a73ff0aaba17052da8 100644 (file)
@@ -51,6 +51,16 @@ class AccountControllerTest < ActionController::TestCase
                :content => /Invalid user or password/
   end
 
+  def test_login_should_rescue_auth_source_exception
+    source = AuthSource.create!(:name => 'Test')
+    User.find(2).update_attribute :auth_source_id, source.id
+    AuthSource.any_instance.stubs(:authenticate).raises(AuthSourceException.new("Something wrong"))
+
+    post :login, :username => 'jsmith', :password => 'jsmith'
+    assert_response 500
+    assert_error_tag :content => /Something wrong/
+  end
+
   if Object.const_defined?(:OpenID)
 
   def test_login_with_openid_for_existing_user