Parent

OmniAuth::LDAP::Adaptor

Constants

METHOD
MUST_HAVE_KEYS

A list of needed keys. Possible alternatives are specified using sub-lists.

VALID_ADAPTER_CONFIGURATION_KEYS

Attributes

auth[R]
base[R]
bind_dn[RW]
connection[R]
filter[R]
password[RW]
uid[R]

Public Class Methods

new(configuration={}) click to toggle source
# File lib/omniauth-ldap/adaptor.rb, line 40
def initialize(configuration={})
  Adaptor.validate(configuration)
  @configuration = configuration.dup
  @configuration[:allow_anonymous] ||= false
  @logger = @configuration.delete(:logger)
  VALID_ADAPTER_CONFIGURATION_KEYS.each do |name|
    instance_variable_set("@#{name}", @configuration[name])
  end
  method = ensure_method(@method)
  config = {
    :host => @host,
    :port => @port,
    :encryption => method,
    :base => @base
  }

  @bind_method = @try_sasl ? :sasl : (@allow_anonymous||!@bind_dn||!@password ? :anonymous : :simple)


  @auth = sasl_auths({:username => @bind_dn, :password => @password}).first if @bind_method == :sasl
  @auth ||= { :method => @bind_method,
              :username => @bind_dn,
              :password => @password
            }
  config[:auth] = @auth
  @connection = Net::LDAP.new(config)
end
validate(configuration={}) click to toggle source
# File lib/omniauth-ldap/adaptor.rb, line 29
def self.validate(configuration={})
  message = []
  MUST_HAVE_KEYS.each do |names|
    names = [names].flatten
    missing_keys = names.select{|name| configuration[name].nil?}
    if missing_keys == names
      message << names.join(' or ')
    end
  end
  raise ArgumentError.new(message.join(",") +" MUST be provided") unless message.empty?
end

Public Instance Methods

bind_as(args = {}) click to toggle source

:base => “dc=yourcompany, dc=com”,

:filter => "(mail=#{user})",
:password => psw
# File lib/omniauth-ldap/adaptor.rb, line 71
def bind_as(args = {})
  result = false
  @connection.open do |me|
    rs = me.search args
    if rs and rs.first and dn = rs.first.dn
      password = args[:password]
      method = args[:method] || @method
      password = password.call if password.respond_to?(:call)
      if method == 'sasl'
      result = rs.first if me.bind(sasl_auths({:username => dn, :password => password}).first)
      else
      result = rs.first if me.bind(:method => :simple, :username => dn,
                          :password => password)
      end
    end
  end
  result
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.