summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/controllers/account_controller.rb3
-rw-r--r--app/models/auth_source.rb4
-rw-r--r--app/models/auth_source_ldap.rb4
-rw-r--r--test/functional/account_controller_test.rb10
4 files changed, 19 insertions, 2 deletions
diff --git a/app/controllers/account_controller.rb b/app/controllers/account_controller.rb
index 6729b4702..3874d2d89 100644
--- a/app/controllers/account_controller.rb
+++ b/app/controllers/account_controller.rb
@@ -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
diff --git a/app/models/auth_source.rb b/app/models/auth_source.rb
index ae50febc5..933be904a 100644
--- a/app/models/auth_source.rb
+++ b/app/models/auth_source.rb
@@ -15,6 +15,10 @@
# 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
diff --git a/app/models/auth_source_ldap.rb b/app/models/auth_source_ldap.rb
index cfb02b881..5c6d28cb2 100644
--- a/app/models/auth_source_ldap.rb
+++ b/app/models/auth_source_ldap.rb
@@ -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
diff --git a/test/functional/account_controller_test.rb b/test/functional/account_controller_test.rb
index 00142ffd0..5bf65b9ab 100644
--- a/test/functional/account_controller_test.rb
+++ b/test/functional/account_controller_test.rb
@@ -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