1 # Redmine - project management software
2 # Copyright (C) 2006-2011 Jean-Philippe Lang
3 #
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
18 # Generic exception for when the AuthSource can not be reached
19 # (eg. can not connect to the LDAP)
20 class AuthSourceException < Exception; end
21
22 class AuthSource < ActiveRecord::Base
23 include Redmine::SubclassFactory
24 include Redmine::Ciphering
25
26 has_many :users
27
28 validates_presence_of :name
29 validates_uniqueness_of :name
30 validates_length_of :name, :maximum => 60
31
32 def authenticate(login, password)
33 end
34
35 def test_connection
36 end
37
38 def auth_method_name
39 "Abstract"
40 end
41
42 def account_password
43 read_ciphered_attribute(:account_password)
44 end
45
46 def account_password=(arg)
47 write_ciphered_attribute(:account_password, arg)
48 end
49
50 def allow_password_changes?
51 self.class.allow_password_changes?
52 end
53
54 # Does this auth source backend allow password changes?
55 def self.allow_password_changes?
56 false
57 end
58
59 # Try to authenticate a user not yet registered against available sources
60 def self.authenticate(login, password)
61 AuthSource.find(:all, :conditions => ["onthefly_register=?", true]).each do |source|
62 begin
63 logger.debug "Authenticating '#{login}' against '#{source.name}'" if logger && logger.debug?
64 attrs = source.authenticate(login, password)
65 rescue => e
66 logger.error "Error during authentication: #{e.message}"
67 attrs = nil
68 end
69 return attrs if attrs
70 end
71 return nil
72 end
73 end