Module: Devise::Models::LdapAuthenticatable

Extended by:
ActiveSupport::Concern
Defined in:
lib/devise_ldap_authenticatable/model.rb

Overview

LDAP Module, responsible for validating the user credentials via LDAP.

Examples:

 User.authenticate('[email protected]', 'password123')  # returns authenticated user or nil
 User.find(1).valid_password?('password123')         # returns true/false

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#attribute_to_compare ⇒ Object

Adding this to get the field in db table with which the provided login detail should be compared to authenticate. Application Specific Change



71
72
73
# File 'lib/devise_ldap_authenticatable/model.rb', line 71

def attribute_to_compare
  Devise::LdapAdapter.get_attribute_to_compare()
end

#ldap_dn ⇒ Object



49
50
51
# File 'lib/devise_ldap_authenticatable/model.rb', line 49

def ldap_dn
  Devise::LdapAdapter.get_dn()
end

#ldap_groups ⇒ Object



45
46
47
# File 'lib/devise_ldap_authenticatable/model.rb', line 45

def ldap_groups
  Devise::LdapAdapter.get_groups()
end

#ldap_persistant_attributes ⇒ Object

Adding functions for synchronizing the values(user specified) between LDAP Metadata and Application database entry. Application Specific Change



55
56
57
# File 'lib/devise_ldap_authenticatable/model.rb', line 55

def ldap_persistant_attributes
  Devise::LdapAdapter.get_persistant_attributes() 
end

#login_with ⇒ Object



20
21
22
# File 'lib/devise_ldap_authenticatable/model.rb', line 20

def 
  self[::Devise.authentication_keys.first]
end

#password=(new_password) ⇒ Object



32
33
34
# File 'lib/devise_ldap_authenticatable/model.rb', line 32

def password=(new_password)
  @password = new_password
end

#reset_password!(new_password, new_password_confirmation) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/devise_ldap_authenticatable/model.rb', line 24

def reset_password!(new_password, new_password_confirmation)
  if new_password == new_password_confirmation && ::Devise.ldap_update_password
    Devise::LdapAdapter.update_password(, new_password)
  end
  clear_reset_password_token if valid?
  save
end

#update_persistant_attributes ⇒ Object



59
60
61
62
63
64
65
66
67
# File 'lib/devise_ldap_authenticatable/model.rb', line 59

def update_persistant_attributes
  ldap_persistant_attributes.each do |key,value|
    self[key.to_sym] = if value.is_a? Array
       value.first.to_s
    else
      value.to_s             
    end
  end 
end

#valid_ldap_authentication?(password) ⇒ Boolean

Checks if a resource is valid upon authentication.

Returns:

  • (Boolean)


37
38
39
40
41
42
43
# File 'lib/devise_ldap_authenticatable/model.rb', line 37

def valid_ldap_authentication?(password)
  if Devise::LdapAdapter.valid_credentials?(, password)
    return true
  else
    return false
  end
end