Sha256: c855d242b062ee7c63b717ff4a4b965ed839ce18b25796bf77604b50fc55f962

Contents?: true

Size: 1 KB

Versions: 3

Compression:

Stored size: 1 KB

Contents

module Puavo
  module Authentication
    def self.included(base)
      base.send :extend, ClassMethods
    end

    module ClassMethods
      def authenticate(login, password)
        logger.debug "Find user by uid from ldap"
        logger.debug "uid: #{login}"

        begin
          user = User.find(:first, :attribute => "uid", :value => login)

          if user.bind(password)
            host = LdapBase.configuration[:host]
            base = LdapBase.base.to_s
            LdapBase.ldap_setup_connection(host, base, user.dn, password)

            # Allow authetication only if user is School Admin in the some School or organisation owner.
            if School.find( :first, :attribute => "puavoSchoolAdmin", :value => user.dn ) ||
                LdapOrganisation.first.owner.include?(user.dn)
              return user
            end
          end
        rescue Exception => e
          logger.info "Login failed: login: #{login}, Exception: #{e}"
          return false
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
puavo_authentication-0.0.6 lib/puavo/authentication.rb
puavo_authentication-0.0.4 lib/puavo/authentication.rb
puavo_authentication-0.0.3 lib/puavo/authentication.rb