app/lib/ldap_authenticatable_tiny/strategy.rb
# Check that we have that user in the database, then check
# credentials against LDAP, and return success if both succeed.
# This method ultimately calls `fail` or `success!`
#
# `authentication_hash` and `password` methods are provided by the superclass:
# https://github.com/plataformatec/devise/blob/master/lib/devise/strategies/authenticatable.rb
#
# Also check out Devise's Authenticable Model and Warden's base Strategy to
# see what's going on here.
# https://github.com/wardencommunity/warden/blob/master/lib/warden/strategies/base.rb#L8
# https://github.com/plataformatec/devise/blob/master/lib/devise/models/authenticatable.rb
Check that we have that user in the database, then check
credentials against LDAP, and return success if both succeed.
This method ultimately calls `fail` or `success!`



Also check out Devise's Authenticable Model and Warden's base Strategy to
see what's going on here.
Check that we have that user in the database then check credentials against LDAP and return success if both succeed . This method ultimately calls ` fail ` or ` success! ` Also check out Devise ' s Authenticable Model and Warden ' s base Strategy to see what ' s going on here .
def authenticate_without_consistent_timing!
        begin
          login_text = authentication_hash.fetch(:login_text, '').downcase.strip
          login_code = authentication_hash.fetch(:login_code, '').downcase.strip
          password_text = password()
          if login_text.empty? || login_code.empty? || password_text.empty?
            Rollbar.error('LdapAuthenticatableTiny called with invalid params')
            logger.error 'LdapAuthenticatableTiny  called with invalid params'
            return fail!(:invalid)
          end
          educator = PerDistrict.new.find_educator_by_login_text(login_text)
          return fail!(:not_found_in_database) unless educator.present?
          if is_multifactor_enabled?(educator)
            return fail!(:invalid_multifactor) unless is_multifactor_code_valid?(educator, login_code)
          elsif !is_placeholder_multifactor_login_code?(login_code)
            return fail!(:unexpected_multifactor)
          end
          ldap_login = PerDistrict.new.ldap_login_for_educator(educator)
          return fail!(:invalid) unless is_authorized_by_ldap?(ldap_login, password_text)
          return success!(educator)
        rescue => error
          Rollbar.error('LdapAuthenticatableTiny error caught', error)
          logger.error "LdapAuthenticatableTiny, error caught: #{error}"
          return fail!(:error)
        end
        nil
      end
def authenticate_without_consistent_timing! begin login_text = authentication_hash . fetch ( :login_text , '' ) . downcase . strip login_code = authentication_hash . fetch ( :login_code , '' ) . downcase . strip password_text = password ( ) if login_text . empty? || login_code . empty? || password_text . empty? Rollbar . error ( 'LdapAuthenticatableTiny called with invalid params' ) logger . error 'LdapAuthenticatableTiny  called with invalid params' return fail! ( :invalid ) end educator = PerDistrict . new . find_educator_by_login_text ( login_text ) return fail! ( :not_found_in_database ) unless educator . present? if is_multifactor_enabled? ( educator ) return fail! ( :invalid_multifactor ) unless is_multifactor_code_valid? ( educator , login_code ) elsif ! is_placeholder_multifactor_login_code? ( login_code ) return fail! ( :unexpected_multifactor ) end ldap_login = PerDistrict . new . ldap_login_for_educator ( educator ) return fail! ( :invalid ) unless is_authorized_by_ldap? ( ldap_login , password_text ) return success! ( educator ) rescue => error Rollbar . error ( 'LdapAuthenticatableTiny error caught' , error ) logger . error "LdapAuthenticatableTiny, error caught: #{error}" return fail! ( :error ) end nil end
Check that we have that user in the database, then check
credentials against LDAP, and return success if both succeed.
Check that we have that user in the database then check credentials against LDAP and return success if both succeed .
# Get parameters user sent via superclass, and validate them. # Devise also enforces that all parameters are present before our strategy runs. # First, see if we can find an Educator record # Next, check if login code if multifactor is enabled for their account. # Also fail if they passed something unexpected for login code when it isn't enabled # for their account. # Finally, try asking the LDAP server if they have access # Success