Class: AD::Authentication

Inherits:
Object
  • Object
show all
Defined in:
lib/ad/authentication.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection = AD::ConnectionFactory.service_user_connection) ⇒ Authentication

Returns a new instance of Authentication.



5
6
7
# File 'lib/ad/authentication.rb', line 5

def initialize(connection = AD::ConnectionFactory.service_user_connection)
  @connection = connection
end

Instance Attribute Details

#bind_userObject (readonly)

Returns the value of attribute bind_user.



9
10
11
# File 'lib/ad/authentication.rb', line 9

def bind_user
  @bind_user
end

#connectionObject (readonly)

Returns the value of attribute connection.



9
10
11
# File 'lib/ad/authentication.rb', line 9

def connection
  @connection
end

Instance Method Details

#authenticate(username, password) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/ad/authentication.rb', line 11

def authenticate(username, password)
  @bind_user = nil
  return false if username.blank? || password.blank?
  result = @connection.bind_as(
    base: AD.base_dn,
    filter: Net::LDAP::DN.new(AD.unique_id_attr, username.strip).to_s,
    password: password.to_s
  )
  @bind_user = result[0] if result
  @bind_user ? true : false
end