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 Attribute Summary

Attributes inherited from Base

#runtime

Instance Method Summary collapse

Methods inherited from Base

#connecting?, #disconnect!, #entry_attribute, #initialize, jndi_connection, ldap_connection, #log_info, net_ldap_connection, #rebind, #reset_runtime, #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



136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/active_ldap/adapter/ldap.rb', line 136

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



70
71
72
73
74
# File 'lib/active_ldap/adapter/ldap.rb', line 70

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

#bind_as_anonymous(options = {}) ⇒ Object



76
77
78
79
80
81
# File 'lib/active_ldap/adapter/ldap.rb', line 76

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

#bound?Boolean

Returns:

  • (Boolean)


83
84
85
# File 'lib/active_ldap/adapter/ldap.rb', line 83

def bound?
  connecting? and @connection.bound?
end

#connect(options = {}) ⇒ Object



53
54
55
56
57
58
59
60
61
# File 'lib/active_ldap/adapter/ldap.rb', line 53

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}
    [log("connect", info) {method.connect(host, port)},
     uri, with_start_tls]
  end
end

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



122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/active_ldap/adapter/ldap.rb', line 122

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



150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/active_ldap/adapter/ldap.rb', line 150

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



164
165
166
167
168
169
170
171
172
# File 'lib/active_ldap/adapter/ldap.rb', line 164

def modify_rdn(dn, new_rdn, delete_old_rdn, new_superior, options={})
  super do |dn, new_rdn, delete_old_rdn, new_superior|
    info = {
      :name => "modify: RDN",
      :dn => dn, :new_rdn => new_rdn, :delete_old_rdn => delete_old_rdn
    }
    execute(:modrdn, info, dn, new_rdn, delete_old_rdn)
  end
end

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



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/active_ldap/adapter/ldap.rb', line 87

def search(options={}, &block)
  super(options) do |base, scope, filter, attrs, limit, callback|
    begin
      i = 0
      info = {
        :base => base, :scope => scope_name(scope),
        :filter => filter, :attributes => attrs,
      }
      execute(:search, info, base, scope, filter, attrs) do |entry|
        i += 1
        attributes = {}
        entry.attrs.each do |attr|
          attributes[attr] = entry.vals(attr)
        end
        callback.call([entry.dn, attributes], block)
        break if limit and limit <= i
      end
    rescue RuntimeError
      begin
        @connection.assert_error_code
      rescue LDAP::ServerDown
        raise ConnectionError, $!.message
      end
      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



63
64
65
66
67
68
# File 'lib/active_ldap/adapter/ldap.rb', line 63

def unbind(options={})
  return unless bound?
  operation(options) do
    execute(:unbind)
  end
end