Sha256: fb5fdae5c04835cb7d4f4debb196b213244270f6015f68a640ca338300b29c99

Contents?: true

Size: 1.21 KB

Versions: 5

Compression:

Stored size: 1.21 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 = self.find(:first, :attribute => "uid", :value => login)

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

            # Allow authentication always if logged in user is ExteralService object
            if user.class == ExternalService
              return user
            end

            # 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

5 entries across 5 versions & 1 rubygems

Version Path
puavo_authentication-0.0.19 lib/puavo/authentication.rb
puavo_authentication-0.0.18 lib/puavo/authentication.rb
puavo_authentication-0.1.0 lib/puavo/authentication.rb
puavo_authentication-0.0.17 lib/puavo/authentication.rb
puavo_authentication-0.0.13 lib/puavo/authentication.rb