Class: ActiveLdap::Adapter::NetLdap

Inherits:
Base
  • Object
show all
Defined in:
lib/active_ldap/adapter/net_ldap.rb

Constant Summary collapse

METHOD =
{
  :ssl => :simple_tls,
  :tls => :start_tls,
  :plain => nil,
}

Constants inherited from Base

Base::VALID_ADAPTER_CONFIGURATION_KEYS

Instance Method Summary collapse

Methods inherited from Base

#connecting?, #disconnect!, #initialize, ldap_connection, net_ldap_connection, #rebind, #schema

Methods included from GetTextSupport

included

Constructor Details

This class inherits a constructor from ActiveLdap::Adapter::Base

Instance Method Details

#add(dn, entries, options = {}) ⇒ Object



109
110
111
112
113
114
115
116
117
118
119
# File 'lib/active_ldap/adapter/net_ldap.rb', line 109

def add(dn, entries, options={})
  super do |dn, entries|
    attributes = {}
    entries.each do |type, key, attrs|
      attrs.each do |name, values|
        attributes[name] = values
      end
    end
    execute(:add, :dn => dn, :attributes => attributes)
  end
end

#bind(options = {}) ⇒ Object



41
42
43
44
45
46
47
48
# File 'lib/active_ldap/adapter/net_ldap.rb', line 41

def bind(options={})
  @bound = false
  begin
    super
  rescue Net::LDAP::LdapError
    raise AuthenticationError, $!.message
  end
end

#bind_as_anonymous(options = {}) ⇒ Object



50
51
52
53
54
55
56
# File 'lib/active_ldap/adapter/net_ldap.rb', line 50

def bind_as_anonymous(options={})
  super do
    @bound = false
    execute(:bind, :method => :anonymous)
    @bound = true
  end
end

#bound?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/active_ldap/adapter/net_ldap.rb', line 58

def bound?
  connecting? and @bound
end

#connect(options = {}) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/active_ldap/adapter/net_ldap.rb', line 25

def connect(options={})
  @bound = false
  super do |host, port, method|
    config = {
      :host => host,
      :port => port,
    }
    config[:encryption] = {:method => method} if method
    Net::LDAP::Connection.new(config)
  end
end

#delete(targets, options = {}) ⇒ Object



103
104
105
106
107
# File 'lib/active_ldap/adapter/net_ldap.rb', line 103

def delete(targets, options={})
  super do |target|
    execute(:delete, :dn => target)
  end
end

#load(ldifs, options = {}) ⇒ Object



89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/active_ldap/adapter/net_ldap.rb', line 89

def load(ldifs, options={})
  super do |ldif|
    entry = Net::LDAP::Entry.from_single_ldif_string(ldif)
    attributes = {}
    entry.each do |name, values|
      attributes[name] = values
    end
    attributes.delete(:dn)
    execute(:add,
            :dn => entry.dn,
            :attributes => attributes)
  end
end

#modify(dn, entries, options = {}) ⇒ Object



121
122
123
124
125
126
127
# File 'lib/active_ldap/adapter/net_ldap.rb', line 121

def modify(dn, entries, options={})
  super do |dn, entries|
    execute(:modify,
            :dn => dn,
            :operations => parse_entries(entries))
  end
end

#search(options = {}, &block) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/active_ldap/adapter/net_ldap.rb', line 62

def search(options={}, &block)
  super(options) do |base, scope, filter, attrs, limit, callback|
    args = {
      :base => base,
      :scope => scope,
      :filter => filter,
      :attributes => attrs,
      :size => limit,
    }
    execute(:search, args) do |entry|
      attributes = {}
      entry.original_attribute_names.each do |name|
        attributes[name] = entry[name]
      end
      callback.call([entry.dn, attributes], block)
    end
  end
end

#to_ldif(dn, attributes) ⇒ Object



81
82
83
84
85
86
87
# File 'lib/active_ldap/adapter/net_ldap.rb', line 81

def to_ldif(dn, attributes)
  entry = Net::LDAP::Entry.new(dn.dup)
  attributes.each do |key, values|
    entry[key] = values.flatten
  end
  entry.to_ldif
end

#unbind(options = {}) ⇒ Object



37
38
39
# File 'lib/active_ldap/adapter/net_ldap.rb', line 37

def unbind(options={})
  @bound = false
end