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 @ 1358:b8f94812d737

History | View | Annotate | Download (2.17 KB)

1
# Redmine - project management software
2
# Copyright (C) 2006-2012  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
class AuthSourceTimeoutException < AuthSourceException; end
22

    
23
class AuthSource < ActiveRecord::Base
24
  include Redmine::SubclassFactory
25
  include Redmine::Ciphering
26

    
27
  has_many :users
28

    
29
  validates_presence_of :name
30
  validates_uniqueness_of :name
31
  validates_length_of :name, :maximum => 60
32

    
33
  def authenticate(login, password)
34
  end
35

    
36
  def test_connection
37
  end
38

    
39
  def auth_method_name
40
    "Abstract"
41
  end
42

    
43
  def account_password
44
    read_ciphered_attribute(:account_password)
45
  end
46

    
47
  def account_password=(arg)
48
    write_ciphered_attribute(:account_password, arg)
49
  end
50

    
51
  def allow_password_changes?
52
    self.class.allow_password_changes?
53
  end
54

    
55
  # Does this auth source backend allow password changes?
56
  def self.allow_password_changes?
57
    false
58
  end
59

    
60
  # Try to authenticate a user not yet registered against available sources
61
  def self.authenticate(login, password)
62
    AuthSource.where(:onthefly_register => true).all.each do |source|
63
      begin
64
        logger.debug "Authenticating '#{login}' against '#{source.name}'" if logger && logger.debug?
65
        attrs = source.authenticate(login, password)
66
      rescue => e
67
        logger.error "Error during authentication: #{e.message}"
68
        attrs = nil
69
      end
70
      return attrs if attrs
71
    end
72
    return nil
73
  end
74
end