Class: ActiveLdap::Adapter::Ldap

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

Defined Under Namespace

Modules: Method

Constant Summary

Constants inherited from Base

Base::VALID_ADAPTER_CONFIGURATION_KEYS

Instance Method Summary collapse

Methods inherited from Base

#bound?, #connecting?, #disconnect!, #entry_attribute, #initialize, jndi_connection, ldap_connection, #naming_contexts, net_ldap_connection, #rebind, #schema, #supported_control

Methods included from GetTextSupport

included

Constructor Details

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

Instance Method Details

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



169
170
171
172
173
174
175
176
177
178
179
180
181
# File 'lib/active_ldap/adapter/ldap.rb', line 169

def add(dn, entries, options={})
  super do |_dn, _entries|
    controls = options[:controls]
    attributes = parse_entries(_entries)
    info = {:dn => _dn, :attributes => _entries}
    if controls
      info.merge!(:name => :add, :controls => controls)
      execute(:add_ext, info, _dn, attributes, controls, [])
    else
      execute(:add, info, _dn, attributes)
    end
  end
end

#bind(options = {}) ⇒ Object



102
103
104
105
106
# File 'lib/active_ldap/adapter/ldap.rb', line 102

def bind(options={})
  super do
    @connection.error_message
  end
end

#bind_as_anonymous(options = {}) ⇒ Object



108
109
110
111
112
113
# File 'lib/active_ldap/adapter/ldap.rb', line 108

def bind_as_anonymous(options={})
  super do
    execute(:bind, :name => "bind: anonymous")
    true
  end
end

#connect(options = {}) ⇒ Object



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/active_ldap/adapter/ldap.rb', line 80

def connect(options={})
  super do |host, port, method|
    uri = construct_uri(host, port, method.ssl?)
    with_start_tls = method.start_tls?
    info = {
      :uri => uri,
      :with_start_tls => with_start_tls,
      :tls_options => @tls_options,
    }
    connection = log("connect", info) do
      method.connect(host, port, :tls_options => @tls_options)
    end
    [connection, uri, with_start_tls]
  end
end

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



155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/active_ldap/adapter/ldap.rb', line 155

def delete(targets, options={})
  super do |target|
    controls = options[:controls]
    info = {:dn => target}
    if controls
      info.merge!(:name => :delete, :controls => controls)
      execute(:delete_ext, info,
              target, controls, [])
    else
      execute(:delete, info, target)
    end
  end
end

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



183
184
185
186
187
188
189
190
191
192
193
194
195
# File 'lib/active_ldap/adapter/ldap.rb', line 183

def modify(dn, entries, options={})
  super do |_dn, _entries|
    controls = options[:controls]
    attributes = parse_entries(_entries)
    info = {:dn => _dn, :attributes => _entries}
    if controls
      info.merge!(:name => :modify, :controls => controls)
      execute(:modify_ext, info, _dn, attributes, controls, [])
    else
      execute(:modify, info, _dn, attributes)
    end
  end
end

#modify_rdn(dn, new_rdn, delete_old_rdn, new_superior, options = {}) ⇒ Object



197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
# File 'lib/active_ldap/adapter/ldap.rb', line 197

def modify_rdn(dn, new_rdn, delete_old_rdn, new_superior, options={})
  super do |_dn, _new_rdn, _delete_old_rdn, _new_superior|
    rename_available_p = @connection.respond_to?(:rename)
    if _new_superior and not rename_available_p
      raise NotImplemented.new(_("modify RDN with new superior"))
    end
    info = {
      :name => "modify: RDN",
      :dn => _dn,
      :new_rdn => _new_rdn,
      :new_superior => _new_superior,
      :delete_old_rdn => _delete_old_rdn
    }
    if rename_available_p
      execute(:rename, info,
              _dn, _new_rdn, _new_superior, _delete_old_rdn, [], [])
    else
      execute(:modrdn, info, _dn, _new_rdn, _delete_old_rdn)
    end
  end
end

#search(options = {}) ⇒ Object



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/active_ldap/adapter/ldap.rb', line 115

def search(options={})
  super(options) do |base, scope, filter, attrs, limit|
    begin
      use_paged_results = options[:use_paged_results]
      if use_paged_results or use_paged_results.nil?
        use_paged_results = supported_control.paged_results?
      end
      info = {
        :base => base, :scope => scope_name(scope),
        :filter => filter, :attributes => attrs, :limit => limit,
      }
      options = {
        :base              => base,
        :scope             => scope,
        :filter            => filter,
        :attributes        => attrs,
        :limit             => limit,
        :use_paged_results => use_paged_results
      }
      execute(:search_full, info, options) do |entry|
        attributes = {}
        entry.attrs.each do |attr|
          value = entry.vals(attr)
          attributes[attr] = value if value
        end
        yield([entry.dn, attributes])
      end
    rescue RuntimeError
      if $!.message == "no result returned by search"
        @logger.debug do
          args = [filter, attrs.inspect]
          _("No matches: filter: %s: attributes: %s") % args
        end
      else
        raise
      end
    end
  end
end

#unbind(options = {}) ⇒ Object



96
97
98
99
100
# File 'lib/active_ldap/adapter/ldap.rb', line 96

def unbind(options={})
  super do
    execute(:unbind)
  end
end