Module: Devise::Models::RadiusAuthenticatable::ClassMethods

Defined in:
lib/devise/models/radius_authenticatable.rb

Instance Method Summary collapse

Instance Method Details

#find_for_radius_authentication(authentication_hash) ⇒ Object

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.


142
143
144
145
146
147
148
149
150
151
# File 'lib/devise/models/radius_authenticatable.rb', line 142

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) ⇒ Object

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.


157
158
159
160
161
162
163
# File 'lib/devise/models/radius_authenticatable.rb', line 157

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

#radius_servers_with_portsObject

Returns an enumerable that provides each server with it's configured port. If no port is given with the server config, the default +radius_server_port is used.


168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# File 'lib/devise/models/radius_authenticatable.rb', line 168

def radius_servers_with_ports
  @radius_servers_with_ports ||= begin
    retval   = []
    servers  = self.radius_servers
    servers += [self.radius_server] if self.radius_server

    servers.each do |server|
      server, port = server.split(':')
      port ||= self.radius_server_port

      retval << [server, port]
    end

    retval
  end
end