module Devise::Models::RadiusAuthenticatable::ClassMethods

Public Instance Methods

find_for_radius_authentication(authentication_hash) click to toggle source

Invoked by the RadiusAuthenticatable stratgey to perform the authentication against the radius server. The username is extracted from the authentication hash and a UID is generated from the username and server IP. We then search for an existing resource using the UID and configured UID field. If no resource is found, a new resource is built (not created). If authentication is successful the callback is responsible for saving the resource. Returns the resource if authentication succeeds and nil if it does not.

# File lib/devise/models/radius_authenticatable.rb, line 120
def find_for_radius_authentication(authentication_hash)
  uid_field = self.radius_uid_field.to_sym
  username, password = radius_credentials(authentication_hash)
  uid = self.radius_uid_generator.call(username, self.radius_server)

  resource = find_for_authentication({ uid_field => uid }) ||
    new(uid_field => uid)

  resource.valid_radius_password?(username, password) ? resource : nil
end
radius_credentials(authentication_hash) click to toggle source

Extract the username and password from the supplied authentication hash. The username is extracted using the first value from Devise.authentication_keys. The username is converted to lowercase if the authentication key is in the list of case insensitive keys configured for Devise.

# File lib/devise/models/radius_authenticatable.rb, line 135
def radius_credentials(authentication_hash)
  key = self.authentication_keys.first
  value = authentication_hash[key]
  value.downcase! if (self.case_insensitive_keys || []).include?(key)

  [value, authentication_hash[:password]]
end