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

#change_password!(current_password) ⇒ Object



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

def change_password!(current_password)
  raise "Need to set new password first" if @password.blank?

  Devise::LDAP::Adapter.update_own_password(, @password, current_password)
end

#in_ldap_group?(group_name, group_attribute = LDAP::DEFAULT_GROUP_UNIQUE_MEMBER_LIST_KEY) ⇒ Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/devise_ldap_authenticatable/model.rb', line 59

def in_ldap_group?(group_name, group_attribute = LDAP::DEFAULT_GROUP_UNIQUE_MEMBER_LIST_KEY)
  Devise::LDAP::Adapter.in_ldap_group?(, group_name, group_attribute)
end

#ldap_dnObject



63
64
65
# File 'lib/devise_ldap_authenticatable/model.rb', line 63

def ldap_dn
  Devise::LDAP::Adapter.get_dn()
end

#ldap_get_param(login_with, param) ⇒ Object



67
68
69
# File 'lib/devise_ldap_authenticatable/model.rb', line 67

def ldap_get_param(, param)
  Devise::LDAP::Adapter.get_ldap_param(,param)
end

#ldap_groupsObject



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

def ldap_groups
  Devise::LDAP::Adapter.get_groups()
end

#login_withObject



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

def 
  @login_with ||= Devise.mappings[self.class.to_s.underscore.to_sym].to.authentication_keys.first
  self[@login_with]
end

#password=(new_password) ⇒ Object



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

def password=(new_password)
  @password = new_password
  if defined?(password_digest) && @password.present? && respond_to?(:encrypted_password=)
    self.encrypted_password = password_digest(@password) 
  end
end

#reset_password!(new_password, new_password_confirmation) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/devise_ldap_authenticatable/model.rb', line 31

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

#valid_ldap_authentication?(password) ⇒ Boolean

Checks if a resource is valid upon authentication.

Returns:

  • (Boolean)


47
48
49
50
51
52
53
# File 'lib/devise_ldap_authenticatable/model.rb', line 47

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