Class: Net::LDAP::AuthAdapter::Simple

Inherits:
Net::LDAP::AuthAdapter show all
Defined in:
lib/net/ldap/auth_adapter/simple.rb

Instance Method Summary collapse

Methods inherited from Net::LDAP::AuthAdapter

[], #initialize, register

Constructor Details

This class inherits a constructor from Net::LDAP::AuthAdapter

Instance Method Details

#bind(auth) ⇒ Object


7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/net/ldap/auth_adapter/simple.rb', line 7

def bind(auth)
  user, psw = if auth[:method] == :simple
                [auth[:username] || auth[:dn], auth[:password]]
              else
                ["", ""]
              end

  raise Net::LDAP::BindingInformationInvalidError, "Invalid binding information" unless (user && psw)

  message_id = @connection.next_msgid
  request    = [
    Net::LDAP::Connection::LdapVersion.to_ber, user.to_ber,
    psw.to_ber_contextspecific(0)
  ].to_ber_appsequence(Net::LDAP::PDU::BindRequest)

  @connection.send(:write, request, nil, message_id)
  pdu = @connection.queued_read(message_id)

  if !pdu || pdu.app_tag != Net::LDAP::PDU::BindResult
    raise Net::LDAP::NoBindResultError, "no bind result"
  end

  pdu
end