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