Class: Devise::Strategies::HolmanAuthenticatable

Inherits:
Authenticatable
  • Object
show all
Defined in:
lib/holman_active_directory/authenticatable.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#http_passObject

Returns the value of attribute http_pass.



36
37
38
# File 'lib/holman_active_directory/authenticatable.rb', line 36

def http_pass
  @http_pass
end

#http_userObject

Returns the value of attribute http_user.



36
37
38
# File 'lib/holman_active_directory/authenticatable.rb', line 36

def http_user
  @http_user
end

Instance Method Details

#active_directory_password?(user, password) ⇒ Boolean

Returns:

  • (Boolean)


43
44
45
46
47
# File 'lib/holman_active_directory/authenticatable.rb', line 43

def active_directory_password?(user, password)
  dn       = user.active_directory_distinguished_name
  return false unless dn
  HolmanActiveDirectory.valid_password?(dn, password)
end

#authenticate!Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/holman_active_directory/authenticatable.rb', line 6

def authenticate!
  use_http_authenticate if defined?(ActionController)

  return fail(:invalid) unless user.present? && password.present?

  if user.valid_password?(password) # invited users may create their own password and login without AD
    success!(user)
  elsif active_directory_password?(user, password)
    session[:ldap_session] = true
    session[:expires_at] = HolmanActiveDirectory::AccessControl.ldap_session_timeout
    success!(user)
  else
    fail(:invalid)
  end
rescue Net::LDAP::Error
  fail(:no_ad)
end

#emailObject



28
29
30
# File 'lib/holman_active_directory/authenticatable.rb', line 28

def email
  http_user || params[:user][:email]
end

#passwordObject



32
33
34
# File 'lib/holman_active_directory/authenticatable.rb', line 32

def password
  http_pass || super
end

#use_http_authenticateObject



38
39
40
41
# File 'lib/holman_active_directory/authenticatable.rb', line 38

def use_http_authenticate
  return unless request.authorization
  @http_user, @http_pass = ActionController::HttpAuthentication::Basic::user_name_and_password(request)
end

#userObject



24
25
26
# File 'lib/holman_active_directory/authenticatable.rb', line 24

def user
  @cached_user ||= User.find_for_authentication(email)
end