Chris@909: # Redmine - project management software Chris@1115: # Copyright (C) 2006-2012 Jean-Philippe Lang Chris@0: # Chris@0: # This program is free software; you can redistribute it and/or Chris@0: # modify it under the terms of the GNU General Public License Chris@0: # as published by the Free Software Foundation; either version 2 Chris@0: # of the License, or (at your option) any later version. Chris@909: # Chris@0: # This program is distributed in the hope that it will be useful, Chris@0: # but WITHOUT ANY WARRANTY; without even the implied warranty of Chris@0: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Chris@0: # GNU General Public License for more details. Chris@909: # Chris@0: # You should have received a copy of the GNU General Public License Chris@0: # along with this program; if not, write to the Free Software Chris@0: # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Chris@0: Chris@1115: # Generic exception for when the AuthSource can not be reached Chris@1115: # (eg. can not connect to the LDAP) Chris@1115: class AuthSourceException < Exception; end Chris@1115: class AuthSourceTimeoutException < AuthSourceException; end Chris@1115: Chris@0: class AuthSource < ActiveRecord::Base Chris@1115: include Redmine::SubclassFactory Chris@245: include Redmine::Ciphering Chris@909: Chris@0: has_many :users Chris@909: Chris@0: validates_presence_of :name Chris@0: validates_uniqueness_of :name Chris@0: validates_length_of :name, :maximum => 60 Chris@0: Chris@0: def authenticate(login, password) Chris@0: end Chris@909: Chris@0: def test_connection Chris@0: end Chris@909: Chris@0: def auth_method_name Chris@0: "Abstract" Chris@0: end Chris@909: Chris@245: def account_password Chris@245: read_ciphered_attribute(:account_password) Chris@245: end Chris@909: Chris@245: def account_password=(arg) Chris@245: write_ciphered_attribute(:account_password, arg) Chris@245: end Chris@0: Chris@0: def allow_password_changes? Chris@0: self.class.allow_password_changes? Chris@0: end Chris@0: Chris@0: # Does this auth source backend allow password changes? Chris@0: def self.allow_password_changes? Chris@0: false Chris@0: end Chris@0: Chris@0: # Try to authenticate a user not yet registered against available sources Chris@0: def self.authenticate(login, password) Chris@1115: AuthSource.where(:onthefly_register => true).all.each do |source| Chris@0: begin Chris@0: logger.debug "Authenticating '#{login}' against '#{source.name}'" if logger && logger.debug? Chris@0: attrs = source.authenticate(login, password) Chris@0: rescue => e Chris@0: logger.error "Error during authentication: #{e.message}" Chris@0: attrs = nil Chris@0: end Chris@0: return attrs if attrs Chris@0: end Chris@0: return nil Chris@0: end Chris@0: end