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.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2013 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 AuthSourceTimeoutException < AuthSourceException; end
  21. class AuthSource < ActiveRecord::Base
  22. include Redmine::SubclassFactory
  23. include Redmine::Ciphering
  24. has_many :users
  25. validates_presence_of :name
  26. validates_uniqueness_of :name
  27. validates_length_of :name, :maximum => 60
  28. def authenticate(login, password)
  29. end
  30. def test_connection
  31. end
  32. def auth_method_name
  33. "Abstract"
  34. end
  35. def account_password
  36. read_ciphered_attribute(:account_password)
  37. end
  38. def account_password=(arg)
  39. write_ciphered_attribute(:account_password, arg)
  40. end
  41. def searchable?
  42. false
  43. end
  44. def self.search(q)
  45. results = []
  46. AuthSource.all.each do |source|
  47. begin
  48. if source.searchable?
  49. results += source.search(q)
  50. end
  51. rescue AuthSourceException => e
  52. logger.error "Error while searching users in #{source.name}: #{e.message}"
  53. end
  54. end
  55. results
  56. end
  57. def allow_password_changes?
  58. self.class.allow_password_changes?
  59. end
  60. # Does this auth source backend allow password changes?
  61. def self.allow_password_changes?
  62. false
  63. end
  64. # Try to authenticate a user not yet registered against available sources
  65. def self.authenticate(login, password)
  66. AuthSource.where(:onthefly_register => true).all.each do |source|
  67. begin
  68. logger.debug "Authenticating '#{login}' against '#{source.name}'" if logger && logger.debug?
  69. attrs = source.authenticate(login, password)
  70. rescue => e
  71. logger.error "Error during authentication: #{e.message}"
  72. attrs = nil
  73. end
  74. return attrs if attrs
  75. end
  76. return nil
  77. end
  78. end