Class: LdapQuery::Authenticate

Inherits:
Object
  • Object
show all
Defined in:
lib/ldap_query/authenticate.rb

Overview

Used to authenticate a users LDAP credentials to a user in LDAP

Constant Summary collapse

REQUIRED_CONNECTION_KEYS =
%i[host username password base].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(credentials = {}) ⇒ Authenticate

Initialzile an ldap connection for authenticating a user



13
14
15
# File 'lib/ldap_query/authenticate.rb', line 13

def initialize(credentials = {})
  establish_connection(credentials)
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



6
7
8
# File 'lib/ldap_query/authenticate.rb', line 6

def config
  @config
end

#connectionObject

Returns the value of attribute connection.



6
7
8
# File 'lib/ldap_query/authenticate.rb', line 6

def connection
  @connection
end

Instance Method Details

#auth_user(username, password) ⇒ Boolean, ...

Authenticate the user again ldap with the supplied username/password

Parameters:

  • username (String)
  • password (String)

Returns:

  • (Boolean, Hash, Net::Ldap)


22
23
24
25
26
27
28
29
30
31
# File 'lib/ldap_query/authenticate.rb', line 22

def auth_user(username, password)
  return false if username.nil? || password.nil?

  response = @connection.link.bind_as(base: @config.base,
                                      size: 1,
                                      filter: LdapQuery::Filter.auth(username),
                                      password: password)
  # if no user was found return false, otherwise return the user
  (response && response[0]) ? response : false
end