Class: Rack::Auth::Ldap

Inherits:
AbstractHandler
  • Object
show all
Defined in:
lib/rack/auth/ldap.rb

Overview

Note:

please do not instantiate, this classe is reserved to Rack

class Ldap, the main authentication component for Rack inherited from the default Rack::Auth::AbstractHandler

Examples:

Usage

# in a config.ru
gem 'rack-auth-ldap'
require 'rack/auth/ldap'
use Rack::Auth::Ldap

Defined Under Namespace

Classes: Request

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, config_options = {}) ⇒ Ldap

Note:

please don not instantiate without rack config.ru

initializer for the Ldap Class

Parameters:

  • app (Block, Proc, Lambda)

    the rack application

  • config_options (hash<Symbol>) (defaults to: {})

    the configurable options

Options Hash (config_options):

  • :file (Symbol)

    the path to the YAML configuration file

See Also:



100
101
102
103
# File 'lib/rack/auth/ldap.rb', line 100

def initialize(app, config_options = {})
  super(app)
  @config = Config.new(config_options)
end

Instance Attribute Details

#configObject (readonly)

the config read accessor



91
92
93
# File 'lib/rack/auth/ldap.rb', line 91

def config
  @config
end

Instance Method Details

#call(env) ⇒ Array

call wrapper to provide authentication if not

Parameters:

  • env (Hash)

    the rack environnment variable

Returns:



108
109
110
111
112
113
114
115
116
117
# File 'lib/rack/auth/ldap.rb', line 108

def call(env)
  auth = Ldap::Request.new(env)
  return unauthorized unless auth.provided?
  return bad_request unless auth.basic?
  if valid?(auth)
    env['REMOTE_USER'] = auth.username
    return @app.call(env)
  end
  unauthorized
end