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 @ 1533:59e13100ea95

History | View | Annotate | Download (2.52 KB)

1 909:cbb26bc654de Chris
# Redmine - project management software
2 1494:e248c7af89ec Chris
# Copyright (C) 2006-2014  Jean-Philippe Lang
3 0:513646585e45 Chris
#
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 909:cbb26bc654de Chris
#
9 0:513646585e45 Chris
# 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 909:cbb26bc654de Chris
#
14 0:513646585e45 Chris
# 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 1115:433d4f72a19b Chris
# 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 0:513646585e45 Chris
class AuthSource < ActiveRecord::Base
24 1115:433d4f72a19b Chris
  include Redmine::SubclassFactory
25 245:051f544170fe Chris
  include Redmine::Ciphering
26 909:cbb26bc654de Chris
27 0:513646585e45 Chris
  has_many :users
28 909:cbb26bc654de Chris
29 0:513646585e45 Chris
  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 909:cbb26bc654de Chris
36 0:513646585e45 Chris
  def test_connection
37
  end
38 909:cbb26bc654de Chris
39 0:513646585e45 Chris
  def auth_method_name
40
    "Abstract"
41
  end
42 909:cbb26bc654de Chris
43 245:051f544170fe Chris
  def account_password
44
    read_ciphered_attribute(:account_password)
45
  end
46 909:cbb26bc654de Chris
47 245:051f544170fe Chris
  def account_password=(arg)
48
    write_ciphered_attribute(:account_password, arg)
49
  end
50 0:513646585e45 Chris
51 1464:261b3d9a4903 Chris
  def searchable?
52
    false
53
  end
54
55
  def self.search(q)
56
    results = []
57
    AuthSource.all.each do |source|
58
      begin
59
        if source.searchable?
60
          results += source.search(q)
61
        end
62
      rescue AuthSourceException => e
63
        logger.error "Error while searching users in #{source.name}: #{e.message}"
64
      end
65
    end
66
    results
67
  end
68
69 0:513646585e45 Chris
  def allow_password_changes?
70
    self.class.allow_password_changes?
71
  end
72
73
  # Does this auth source backend allow password changes?
74
  def self.allow_password_changes?
75
    false
76
  end
77
78
  # Try to authenticate a user not yet registered against available sources
79
  def self.authenticate(login, password)
80 1517:dffacf8a6908 Chris
    AuthSource.where(:onthefly_register => true).each do |source|
81 0:513646585e45 Chris
      begin
82
        logger.debug "Authenticating '#{login}' against '#{source.name}'" if logger && logger.debug?
83
        attrs = source.authenticate(login, password)
84
      rescue => e
85
        logger.error "Error during authentication: #{e.message}"
86
        attrs = nil
87
      end
88
      return attrs if attrs
89
    end
90
    return nil
91
  end
92
end