You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

auth_source.rb 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. # Generic exception for when the AuthSource can not be reached
  18. # (eg. can not connect to the LDAP)
  19. class AuthSourceException < Exception; end
  20. class AuthSource < ActiveRecord::Base
  21. include Redmine::SubclassFactory
  22. include Redmine::Ciphering
  23. has_many :users
  24. validates_presence_of :name
  25. validates_uniqueness_of :name
  26. validates_length_of :name, :maximum => 60
  27. def authenticate(login, password)
  28. end
  29. def test_connection
  30. end
  31. def auth_method_name
  32. "Abstract"
  33. end
  34. def account_password
  35. read_ciphered_attribute(:account_password)
  36. end
  37. def account_password=(arg)
  38. write_ciphered_attribute(:account_password, arg)
  39. end
  40. def allow_password_changes?
  41. self.class.allow_password_changes?
  42. end
  43. # Does this auth source backend allow password changes?
  44. def self.allow_password_changes?
  45. false
  46. end
  47. # Try to authenticate a user not yet registered against available sources
  48. def self.authenticate(login, password)
  49. AuthSource.find(:all, :conditions => ["onthefly_register=?", true]).each do |source|
  50. begin
  51. logger.debug "Authenticating '#{login}' against '#{source.name}'" if logger && logger.debug?
  52. attrs = source.authenticate(login, password)
  53. rescue => e
  54. logger.error "Error during authentication: #{e.message}"
  55. attrs = nil
  56. end
  57. return attrs if attrs
  58. end
  59. return nil
  60. end
  61. end