Module: Devise::Models::LdapAuthenticatable::ClassMethods
- Defined in:
- lib/devise_ldap_authenticatable/model.rb
Overview
# Called before the ldap record is saved automatically def ldap_before_save end
Class Method Summary collapse
Instance Method Summary collapse
-
#authenticate_with_ldap(attributes = {}) ⇒ Object
Authenticate a user based on configured attribute keys.
- #find_for_ldap_authentication(attributes, entry) ⇒ Object
- #find_ldap_entry(ldap_connection, auth_key_value) ⇒ Object
- #update_with_password(resource) ⇒ Object
Class Method Details
.create_from_ldap_entry(attributes, entry) ⇒ Object
77 78 79 80 81 82 83 84 85 86 |
# File 'lib/devise_ldap_authenticatable/model.rb', line 77 def self.create_from_ldap_entry(attributes, entry) auth_key = self.authentication_keys.first auth_key_value = (self.case_insensitive_keys || []).include?(auth_key) ? attributes[auth_key].downcase : attributes[auth_key] resource = new resource[auth_key] = auth_key_value resource.password = attributes[:password] resource.ldap_before_save if resources.respond_to?(:ldap_before_save) resource.tap(&:save) end |
Instance Method Details
#authenticate_with_ldap(attributes = {}) ⇒ Object
Authenticate a user based on configured attribute keys. Returns the authenticated user if it’s valid or nil.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/devise_ldap_authenticatable/model.rb', line 47 def authenticate_with_ldap(attributes={}) auth_key = self.authentication_keys.first return nil unless attributes[auth_key].present? auth_key_value = (self.case_insensitive_keys || []).include?(auth_key) ? attributes[auth_key].downcase : attributes[auth_key] ldap_connection = Devise::LdapAdapter::LdapConnect.new( login: auth_key_value, password: attributes[:password], ldap_auth_username_builder: ::Devise.ldap_auth_username_builder, admin: ::Devise.ldap_use_admin_to_bind ) return nil unless ldap_connection. entry = find_ldap_entry(ldap_connection, auth_key_value) resource = find_for_ldap_authentication(attributes, entry) resource = create_from_ldap_entry(attributes, entry) if resource.nil? && ::Devise.ldap_create_user resource end |
#find_for_ldap_authentication(attributes, entry) ⇒ Object
70 71 72 73 74 75 |
# File 'lib/devise_ldap_authenticatable/model.rb', line 70 def find_for_ldap_authentication(attributes, entry) auth_key = self.authentication_keys.first auth_key_value = (self.case_insensitive_keys || []).include?(auth_key) ? attributes[auth_key].downcase : attributes[auth_key] where(auth_key => auth_key_value).first end |
#find_ldap_entry(ldap_connection, auth_key_value) ⇒ Object
66 67 68 |
# File 'lib/devise_ldap_authenticatable/model.rb', line 66 def find_ldap_entry(ldap_connection, auth_key_value) ldap_connection.search_for_login end |
#update_with_password(resource) ⇒ Object
88 89 90 |
# File 'lib/devise_ldap_authenticatable/model.rb', line 88 def update_with_password(resource) puts "UPDATE_WITH_PASSWORD: #{resource.inspect}" end |