Class: ADMapper::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/admapper/connection.rb

Constant Summary collapse

@@ad_connection =
nil
@@ad_treebase =
nil
@@ad_user_filter =
nil

Class Method Summary collapse

Class Method Details

.ad_connect!(config = nil) ⇒ Object

:password => “1234”,

:domain => "springfieldnuclear.com",
:host => "ad.springfieldnuclear.com",
:ssl => true,
:port => 636}

if ad_connect!(config_options)

....

else

...

end



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/admapper/connection.rb', line 33

def self.ad_connect!(config = nil)
 config ||= ADMapper::Configuration.connection_info

 raise ADMapper::ConfigurationMissingError if config.nil?
 username = config[:username]
 password = config[:password]
 domain = config[:domain]
 host = config[:host]
 port = config[:port]
 dc1 = domain.split(".").first
 dc2 = domain.split(".").last
 ssl = config[:ssl] ? true : false
 self.current_connection = initialize_ldap_con(username + "@#{domain}", password, host, port, ssl) 
 @@ad_treebase = "DC=#{dc1},DC=#{dc2}" 
 @@ad_user_filter = Net::LDAP::Filter.eq( "sAMAccountName", username ) 
 self.current_connection.bind
end

.ad_connect_if_not_connectedObject

connects if not connected already



64
65
66
# File 'lib/admapper/connection.rb', line 64

def self.ad_connect_if_not_connected
  self.ad_connect! if @@ad_connection.nil?
end

.current_connectionObject

class method to return the current connection



12
13
14
15
# File 'lib/admapper/connection.rb', line 12

def self.current_connection
  self.ad_connect_if_not_connected
  @@ad_connection
end

.current_connection=(conn) ⇒ Object



17
18
19
# File 'lib/admapper/connection.rb', line 17

def self.current_connection=(conn)
  @@ad_connection = conn
end

.initialize_ldap_con(user_name, password, host, port, ssl) ⇒ Object

initializes the connection to the ldap server. Does not bind.



52
53
54
55
56
57
58
59
60
61
# File 'lib/admapper/connection.rb', line 52

def self.initialize_ldap_con(user_name, password, host, port, ssl)
   ldap = Net::LDAP.new
   ldap.host = host
   ldap.port = port #required for SSL connections, 389 is the default plain text port
   if ssl 
     ldap.encryption :simple_tls #also required to tell Net:LDAP that we want SSL
   end
   ldap.auth "#{user_name}","#{password}"
   ldap #explicitly return the ldap connection object
end

.treebaseObject



7
8
9
# File 'lib/admapper/connection.rb', line 7

def self.treebase
  @@ad_treebase
end