require 'devise/strategies/authenticatable' module Devise module Strategies class LdapAuthenticatable < Authenticatable def authenticate! resource = valid_password? && mapping.to.authenticate_with_ldap(authentication_hash.merge(password: password)) return fail(:invalid) unless resource if validate(resource) resource.after_ldap_authentication if resource.respond_to?(:after_ldap_authentication) success!(resource) end end end end end Warden::Strategies.add(:ldap_authenticatable, Devise::Strategies::LdapAuthenticatable)