Module: AD::ConnectionFactory

Defined in:
lib/ad/connection_factory.rb

Constant Summary collapse

ServiceUserBindError =
Class.new(StandardError)

Class Method Summary collapse

Class Method Details

.service_user_connectionObject



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/ad/connection_factory.rb', line 15

def service_user_connection
  connection = unauthenticated_connection
  connection.auth(
    Net::LDAP::DN.new(AD.service_user_dn).to_s,
      AD.service_user_password
  )
  unless connection.bind
    raise ServiceUserBindError, connection.get_operation_result
  end
  connection
end

.unauthenticated_connectionObject



7
8
9
10
11
12
13
# File 'lib/ad/connection_factory.rb', line 7

def unauthenticated_connection
  Net::LDAP.new(
    host: AD.host,
    port: AD.port,
    instrumentation_service: AD.instrumentation_service
  )
end