Module: Devise::Models::LdapNorm
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/devise_ldap_norm/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
-
#after_ldap_authentication ⇒ Object
Called after a successful LDAP authentication.
- #change_password!(current_password) ⇒ Object
- #in_ldap_group?(group_name, group_attribute = LDAP::DEFAULT_GROUP_UNIQUE_MEMBER_LIST_KEY) ⇒ Boolean
- #ldap_dn ⇒ Object
- #ldap_entry ⇒ Object
- #ldap_get_param(param) ⇒ Object
- #ldap_groups ⇒ Object
- #login_with ⇒ Object
-
#new_record? ⇒ Boolean
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Callbacks defaulted to get past ActiveRecord related checks from Devise %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%.
- #password=(new_password) ⇒ Object
- #persisted? ⇒ Boolean
- #reset_password!(new_password, new_password_confirmation) ⇒ Object
-
#valid_ldap_authentication?(password) ⇒ Boolean
Checks if a resource is valid upon authentication.
Instance Method Details
#after_ldap_authentication ⇒ Object
Called after a successful LDAP authentication
96 97 |
# File 'lib/devise_ldap_norm/model.rb', line 96 def after_ldap_authentication end |
#change_password!(current_password) ⇒ Object
37 38 39 40 41 |
# File 'lib/devise_ldap_norm/model.rb', line 37 def change_password!(current_password) raise "Need to set new password first" if @password.blank? Devise::LDAP::Adapter.update_own_password(login_with, @password, current_password) end |
#in_ldap_group?(group_name, group_attribute = LDAP::DEFAULT_GROUP_UNIQUE_MEMBER_LIST_KEY) ⇒ Boolean
71 72 73 |
# File 'lib/devise_ldap_norm/model.rb', line 71 def in_ldap_group?(group_name, group_attribute = LDAP::DEFAULT_GROUP_UNIQUE_MEMBER_LIST_KEY) Devise::LDAP::Adapter.in_ldap_group?(login_with, group_name, group_attribute) end |
#ldap_dn ⇒ Object
75 76 77 |
# File 'lib/devise_ldap_norm/model.rb', line 75 def ldap_dn ldap_entry ? ldap_entry.dn : nil end |
#ldap_entry ⇒ Object
63 64 65 |
# File 'lib/devise_ldap_norm/model.rb', line 63 def ldap_entry @ldap_entry ||= Devise::LDAP::Adapter.get_ldap_entry(login_with) end |
#ldap_get_param(param) ⇒ Object
79 80 81 82 83 84 85 |
# File 'lib/devise_ldap_norm/model.rb', line 79 def ldap_get_param(param) if ldap_entry && !ldap_entry[param].empty? value = ldap_entry.send(param) else nil end end |
#ldap_groups ⇒ Object
67 68 69 |
# File 'lib/devise_ldap_norm/model.rb', line 67 def ldap_groups Devise::LDAP::Adapter.get_groups(login_with) end |
#login_with ⇒ Object
32 33 34 35 |
# File 'lib/devise_ldap_norm/model.rb', line 32 def login_with @login_with ||= Devise.mappings.find {|k,v| v.class_name == self.class.name}.last.to.authentication_keys.first self[@login_with] end |
#new_record? ⇒ Boolean
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Callbacks defaulted to get past ActiveRecord related checks from Devise %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
18 19 20 |
# File 'lib/devise_ldap_norm/model.rb', line 18 def new_record? false end |
#password=(new_password) ⇒ Object
51 52 53 54 55 56 |
# File 'lib/devise_ldap_norm/model.rb', line 51 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 |
#persisted? ⇒ Boolean
22 23 24 |
# File 'lib/devise_ldap_norm/model.rb', line 22 def persisted? false end |
#reset_password!(new_password, new_password_confirmation) ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/devise_ldap_norm/model.rb', line 43 def reset_password!(new_password, new_password_confirmation) if new_password == new_password_confirmation && ::Devise.ldap_update_password Devise::LDAP::Adapter.update_password(login_with, new_password) end clear_reset_password_token if valid? save end |
#valid_ldap_authentication?(password) ⇒ Boolean
Checks if a resource is valid upon authentication.
59 60 61 |
# File 'lib/devise_ldap_norm/model.rb', line 59 def valid_ldap_authentication?(password) Devise::LDAP::Adapter.valid_credentials?(login_with, password) end |