Class: AuthSource

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
Authorization
Defined in:
app/models/auth_source.rb

Overview

redMine - project management software Copyright (C) 2006 Jean-Philippe Lang

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

Direct Known Subclasses

AuthSourceInternal, AuthSourceLdap

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Authorization

#enforce_create_permissions, #enforce_destroy_permissions, #enforce_edit_permissions, #enforce_permissions, included, #permission_failed?

Class Method Details

.authenticate(login, password) ⇒ Object

Try to authenticate a user not yet registered against available sources Returns : user's attributes OR nil


55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'app/models/auth_source.rb', line 55

def self.authenticate(, password)
  AuthSource.all.each do |source|
    logger.debug "Authenticating '#{login}' against '#{source.name}'"
    begin
      if (attrs = source.authenticate(, password))
        logger.debug "Authentication successful for '#{login}'"
        attrs[:auth_source_id] = source.id
      end
    rescue => e
      logger.error "Error during authentication: #{e.message}"
      attrs = nil
    end
    return attrs if attrs
  end
  nil
end

Instance Method Details

#auth_method_nameObject


33
34
35
# File 'app/models/auth_source.rb', line 33

def auth_method_name
  "Abstract"
end

#authenticate(login, password) ⇒ Object


27
28
# File 'app/models/auth_source.rb', line 27

def authenticate(, password)
end

#can_set_password?Boolean

By default a user may not set their password via Foreman An internal AuthSource should override this and provide a password mechanism


49
50
51
# File 'app/models/auth_source.rb', line 49

def can_set_password?
  false
end

#test_connectionObject


30
31
# File 'app/models/auth_source.rb', line 30

def test_connection
end

#to_labelObject


37
38
39
40
41
42
43
44
45
# File 'app/models/auth_source.rb', line 37

def to_label
  if type_before_type_cast.empty?
    logger.warn "Corrupt AuthSource! Record id:#{id} name:#{name} does not have an associated type. This may be due to importing a production database."
    return nil
  end

  kind = type_before_type_cast.sub("AuthSource","")
  "#{kind.upcase}-#{name}" if name
end