Sha256: d66f25999c002fdcd09fae1a285252812af78dac08b7693b01ca1d15e0db738d

Contents?: true

Size: 1.06 KB

Versions: 10

Compression:

Stored size: 1.06 KB

Contents

require 'devise/strategies/authenticatable'

module Devise
  module Strategies
    # Strategy for signing in a user based on his login and password using LDAP.
    # Redirects to sign_in page if it's not authenticated
    class LdapAuthenticatable < Authenticatable
      def valid?
        valid_controller? && valid_params? && mapping.to.respond_to?(:authenticate_with_ldap)
      end

      # Authenticate a user based on login and password params, returning to warden
      # success and the authenticated user if everything is okay. Otherwise redirect
      # to sign in page.
      def authenticate!
        if resource = mapping.to.authenticate_with_ldap(params[scope])
          success!(resource)
        else
          fail(:invalid)
        end
      end

      protected

        def valid_controller?
          params[:controller] == 'devise/sessions'
        end

        def valid_params?
          params[scope] && params[scope][:password].present?
        end
    end
  end
end

Warden::Strategies.add(:ldap_authenticatable, Devise::Strategies::LdapAuthenticatable)

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
devise_ldap_authenticatable-0.4.6 lib/devise_ldap_authenticatable/strategy.rb
devise_ldap_authenticatable-0.4.5 lib/devise_ldap_authenticatable/strategy.rb
devise_ldap_authenticatable-0.4.4 lib/devise_ldap_authenticatable/strategy.rb
devise_ldap_authenticatable-0.4.3 lib/devise_ldap_authenticatable/strategy.rb
devise_ldap_authenticatable-0.4.2 lib/devise_ldap_authenticatable/strategy.rb
devise_ldap_authenticatable-0.4.1.1 lib/devise_ldap_authenticatable/strategy.rb
devise_ldap_authenticatable-0.4.1 lib/devise_ldap_authenticatable/strategy.rb
devise_ldap_authenticatable-0.4.0 lib/devise_ldap_authenticatable/strategy.rb
devise_ldap_authenticatable-0.3.5 lib/devise_ldap_authenticatable/strategy.rb
devise_ldap_authenticatable-0.3.3 lib/devise_ldap_authenticatable/strategy.rb