Class: IAuthU::Authenticator::LDAP

Inherits:
Object
  • Object
show all
Defined in:
lib/iauthu/authenticator/ldap.rb

Defined Under Namespace

Classes: Builder

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ LDAP

Returns a new instance of LDAP.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/iauthu/authenticator/ldap.rb', line 13

def initialize(opts)
  @config = opts
  @login_format = @config.delete(:login_format) || "%s"
  @credentials = @config.delete(:credentials) || []
  use_ssl = @config.delete(:use_ssl) || false
  server_names = @config.delete(:servers) || []
  
  @servers = server_names.map do |name|
    conf = @config.clone
    conf[:host] = name
    server = Net::LDAP.new(conf)
    server.encryption(:simple_tls) if use_ssl
    server
  end
end

Class Method Details

.build(&block) ⇒ Object



7
8
9
10
11
# File 'lib/iauthu/authenticator/ldap.rb', line 7

def self.build(&block)
  b = Builder.new
  b.instance_eval(&block)
  b.ldap_auth
end

Instance Method Details

#call(user, pass) ⇒ Object



29
30
31
32
33
34
35
36
37
# File 'lib/iauthu/authenticator/ldap.rb', line 29

def call(user,pass)
  @servers.each do |s|
    s.auth(@login_format % user, pass)
    ident = {"username" => user}
    ident["credentials"] = @credentials
    return ident if s.bind
  end
  return nil
end