To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / app / models / auth_source.rb @ 440:6253d777aa12

History | View | Annotate | Download (1.77 KB)

1
# redMine - project management software
2
# Copyright (C) 2006  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
class AuthSource < ActiveRecord::Base
19
  has_many :users
20
  
21
  validates_presence_of :name
22
  validates_uniqueness_of :name
23
  validates_length_of :name, :maximum => 60
24

    
25
  def authenticate(login, password)
26
  end
27
  
28
  def test_connection
29
  end
30
  
31
  def auth_method_name
32
    "Abstract"
33
  end
34

    
35
  def allow_password_changes?
36
    self.class.allow_password_changes?
37
  end
38

    
39
  # Does this auth source backend allow password changes?
40
  def self.allow_password_changes?
41
    false
42
  end
43

    
44
  # Try to authenticate a user not yet registered against available sources
45
  def self.authenticate(login, password)
46
    AuthSource.find(:all, :conditions => ["onthefly_register=?", true]).each do |source|
47
      begin
48
        logger.debug "Authenticating '#{login}' against '#{source.name}'" if logger && logger.debug?
49
        attrs = source.authenticate(login, password)
50
      rescue => e
51
        logger.error "Error during authentication: #{e.message}"
52
        attrs = nil
53
      end
54
      return attrs if attrs
55
    end
56
    return nil
57
  end
58
end