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

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