Class: LdapShellUtils::LdapConnection

Inherits:
Object
  • Object
show all
Defined in:
lib/ldap-shell-utils/ldap_connection.rb

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ LdapConnection

Returns a new instance of LdapConnection.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/ldap-shell-utils/ldap_connection.rb', line 10

def initialize(config)

  uri           = URI.parse( config[:url] )
  auth_config   = {
    :method   =>:simple,
    :username =>config[:username],
    :password =>config[:password]
  }
  
  configuration = {
    :host=>uri.host,
    :port=>uri.port,
    :base=>config[:base],
    :auth=>auth_config
  }
  
  configuration[:encryption] = { :method => :simple_tls } if(uri.scheme == 'ldaps')
  @connection                = Net::LDAP.new(configuration)
  
  self
rescue StandardError=>e
  raise ArgumentError.new(e.message)
end

Instance Method Details

#search(options) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/ldap-shell-utils/ldap_connection.rb', line 34

def search(options)
  
  ldap_filter = ""
  
  begin
    ldap_filter = Net::LDAP::Filter.from_rfc2254(options[:filter])
  rescue StandardError=>e
    raise ArgumentError.new(e.message)
  end
  
  options[:attributes] += [:creatorsname, :createtimestamp, :modifiersname, :modifytimestamp] if options[:audit]
  @connection.search( :filter=>ldap_filter, :attributes=>options[:attributes], :return_result=>true )
end