annotate .svn/pristine/2d/2d3d652686003e0e75f2451ee9050de946a60dda.svn-base @ 1494:e248c7af89ec redmine-2.4

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