Sha256: 43fb2d410de6c967b45cf1e858b22de9c68b6bfef61b8e281a105d71282c8f2c

Contents?: true

Size: 1.31 KB

Versions: 3

Compression:

Stored size: 1.31 KB

Contents

module Castronaut
  module Adapters
    module Ldap
      
      class User 
        begin
          require "net/ldap"
        rescue LoadError
          begin
            gem 'ruby-net-ldap', '~> 0.0.4'
          rescue Gem::LoadError
            $stderr.puts "How can you have any pudding if you don\'t install ruby-net-ldap?"
            exit(0)
          end
        end
        
        def self.authenticate(username, password)
          return false if password.blank?
          
          connection = Net::LDAP.new
          connection.host = Castronaut.config.cas_adapter['host']
          connection.port = Castronaut.config.cas_adapter['port']
          
          prefix = Castronaut.config.cas_adapter['prefix']
          base = Castronaut.config.cas_adapter['base']
          
          connection.authenticate("#{prefix}#{username}, #{base}", password)
          if connection.bind
            return Castronaut::AuthenticationResult.new(username, nil)            
          else
            Castronaut.config.logger.info "#{self} - Unable to authenticate username #{username} because #{connection.get_operation_result.message} : code #{connection.get_operation_result.code}"
            return Castronaut::AuthenticationResult.new(username, "Unable to authenticate")
          end
        end

      end
    
    end
  end
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
relevance-castronaut-0.7.4 lib/castronaut/adapters/ldap/user.rb
relevance-castronaut-0.7.5 lib/castronaut/adapters/ldap/user.rb
factorylabs-castronaut-0.7.5 lib/castronaut/adapters/ldap/user.rb