Class ActiveLdap::Adapter::Ldap
In: lib/active_ldap/adapter/ldap.rb
Parent: Base
Error AttributeAssignmentError AdapterNotSpecified OperationNotPermitted RequiredObjectClassMissed ConnectionError RequiredAttributeMissed LdifInvalid LdapError DistinguishedNameNotSetError EntryNotFound SaveError StrongAuthenticationRequired AdapterNotFound ConnectionNotEstablished TimeoutError AuthenticationError AttributeValueInvalid EntryNotSaved DistinguishedNameInputInvalid EntryAlreadyExist ObjectClassError UnknownAttribute EntryInvalid DeleteError ConfigurationError DistinguishedNameInvalid DistinguishedName Base Reloadable::Deprecated Reloadable::Subclasses Enumerable Ldif Collection EntryAttribute StandardError Children HasManyWrap HasMany BelongsToMany Proxy BelongsTo Common Find LDIF Delete Update Normalizable GetText Parser ActiveRecord::Callbacks ActiveRecord::Validations Base\n[lib/active_ldap/adapter/base.rb\nlib/active_ldap/adapter/jndi.rb\nlib/active_ldap/adapter/ldap.rb\nlib/active_ldap/adapter/net_ldap.rb] Jndi Ldap NetLdap GetTextSupport Schema\n[lib/active_ldap/schema.rb\nlib/active_ldap/schema/syntaxes.rb] JndiConnection lib/active_ldap/distinguished_name.rb lib/active_ldap/base.rb lib/active_ldap/schema.rb lib/active_ldap/entry_attribute.rb lib/active_ldap/ldif.rb lib/active_ldap/ldap_error.rb ClassMethods Associations LdapBenchmarking ActionController Populate lib/active_ldap/association/has_many_wrap.rb lib/active_ldap/association/children.rb lib/active_ldap/association/collection.rb lib/active_ldap/association/proxy.rb lib/active_ldap/association/belongs_to_many.rb lib/active_ldap/association/belongs_to.rb lib/active_ldap/association/has_many.rb HasManyUtils Association ClassMethods Tree Acts Command Update Common ModifyNameRecordLoadable AddOperationModifiable DeleteOperationModifiable ReplaceOperationModifiable ModifyRecordLoadable DeleteRecordLoadable AddRecordLoadable ContentRecordLoadable LDIF Delete Find Operations GetTextSupport Escape ClassMethods Normalizable Attributes ClassMethods Configuration ClassMethods ObjectClass lib/active_ldap/get_text/parser.rb GetText ClassMethods Callbacks Validations lib/active_ldap/adapter/jndi_connection.rb lib/active_ldap/adapter/net_ldap.rb lib/active_ldap/adapter/ldap.rb lib/active_ldap/adapter/jndi.rb Adapter Helper GetTextFallback ClassMethods HumanReadable Salt UserPassword ClassMethods Connection ActiveLdap dot/m_44_0.png

Methods

Classes and Modules

Module ActiveLdap::Adapter::Ldap::Method

Public Instance methods

[Source]

     # File lib/active_ldap/adapter/ldap.rb, line 136
136:       def add(dn, entries, options={})
137:         super do |dn, entries|
138:           controls = options[:controls]
139:           attributes = parse_entries(entries)
140:           info = {:dn => dn, :attributes => entries}
141:           if controls
142:             info.merge!(:name => :add, :controls => controls)
143:             execute(:add_ext, info, dn, attributes, controls, [])
144:           else
145:             execute(:add, info, dn, attributes)
146:           end
147:         end
148:       end

[Source]

    # File lib/active_ldap/adapter/ldap.rb, line 70
70:       def bind(options={})
71:         super do
72:           @connection.error_message
73:         end
74:       end

[Source]

    # File lib/active_ldap/adapter/ldap.rb, line 76
76:       def bind_as_anonymous(options={})
77:         super do
78:           execute(:bind, :name => "bind: anonymous")
79:           true
80:         end
81:       end

[Source]

    # File lib/active_ldap/adapter/ldap.rb, line 83
83:       def bound?
84:         connecting? and @connection.bound?
85:       end

[Source]

    # File lib/active_ldap/adapter/ldap.rb, line 53
53:       def connect(options={})
54:         super do |host, port, method|
55:           uri = construct_uri(host, port, method.ssl?)
56:           with_start_tls = method.start_tls?
57:           info = {:uri => uri, :with_start_tls => with_start_tls}
58:           [log("connect", info) {method.connect(host, port)},
59:            uri, with_start_tls]
60:         end
61:       end

[Source]

     # File lib/active_ldap/adapter/ldap.rb, line 122
122:       def delete(targets, options={})
123:         super do |target|
124:           controls = options[:controls]
125:           info = {:dn => target}
126:           if controls
127:             info.merge!(:name => :delete, :controls => controls)
128:             execute(:delete_ext, info,
129:                     target, controls, [])
130:           else
131:             execute(:delete, info, target)
132:           end
133:         end
134:       end

[Source]

     # File lib/active_ldap/adapter/ldap.rb, line 150
150:       def modify(dn, entries, options={})
151:         super do |dn, entries|
152:           controls = options[:controls]
153:           attributes = parse_entries(entries)
154:           info = {:dn => dn, :attributes => entries}
155:           if controls
156:             info.merge!(:name => :modify, :controls => controls)
157:             execute(:modify_ext, info, dn, attributes, controls, [])
158:           else
159:             execute(:modify, info, dn, attributes)
160:           end
161:         end
162:       end

[Source]

     # File lib/active_ldap/adapter/ldap.rb, line 164
164:       def modify_rdn(dn, new_rdn, delete_old_rdn, new_superior, options={})
165:         super do |dn, new_rdn, delete_old_rdn, new_superior|
166:           info = {
167:             :name => "modify: RDN",
168:             :dn => dn, :new_rdn => new_rdn, :delete_old_rdn => delete_old_rdn
169:           }
170:           execute(:modrdn, info, dn, new_rdn, delete_old_rdn)
171:         end
172:       end

[Source]

     # File lib/active_ldap/adapter/ldap.rb, line 87
 87:       def search(options={}, &block)
 88:         super(options) do |base, scope, filter, attrs, limit, callback|
 89:           begin
 90:             i = 0
 91:             info = {
 92:               :base => base, :scope => scope_name(scope),
 93:               :filter => filter, :attributes => attrs,
 94:             }
 95:             execute(:search, info, base, scope, filter, attrs) do |entry|
 96:               i += 1
 97:               attributes = {}
 98:               entry.attrs.each do |attr|
 99:                 attributes[attr] = entry.vals(attr)
100:               end
101:               callback.call([entry.dn, attributes], block)
102:               break if limit and limit <= i
103:             end
104:           rescue RuntimeError
105:             begin
106:               @connection.assert_error_code
107:             rescue LDAP::ServerDown
108:               raise ConnectionError, $!.message
109:             end
110:             if $!.message == "no result returned by search"
111:               @logger.debug do
112:                 args = [filter, attrs.inspect]
113:                 _("No matches: filter: %s: attributes: %s") % args
114:               end
115:             else
116:               raise
117:             end
118:           end
119:         end
120:       end

[Source]

    # File lib/active_ldap/adapter/ldap.rb, line 63
63:       def unbind(options={})
64:         return unless bound?
65:         operation(options) do
66:           execute(:unbind)
67:         end
68:       end

Private Instance methods

[Source]

     # File lib/active_ldap/adapter/ldap.rb, line 191
191:       def ensure_method(method)
192:         Method.constants.each do |name|
193:           if method.to_s.downcase == name.downcase
194:             return Method.const_get(name).new
195:           end
196:         end
197: 
198:         available_methods = Method.constants.collect do |name|
199:           name.downcase.to_sym.inspect
200:         end.join(", ")
201:         format = _("%s is not one of the available connect methods: %s")
202:         raise ConfigurationError, format % [method.inspect, available_methods]
203:       end

[Source]

     # File lib/active_ldap/adapter/ldap.rb, line 266
266:       def ensure_mod_type(type)
267:         case type
268:         when :replace, :add, :delete
269:           LDAP.const_get("LDAP_MOD_#{type.to_s.upcase}")
270:         else
271:           raise ArgumentError, _("unknown type: %s") % type
272:         end
273:       end

[Source]

     # File lib/active_ldap/adapter/ldap.rb, line 205
205:       def ensure_scope(scope)
206:         scope_map = {
207:           :base => LDAP::LDAP_SCOPE_BASE,
208:           :sub => LDAP::LDAP_SCOPE_SUBTREE,
209:           :one => LDAP::LDAP_SCOPE_ONELEVEL,
210:         }
211:         value = scope_map[scope || :sub]
212:         if value.nil?
213:           available_scopes = scope_map.keys.inspect
214:           format = _("%s is not one of the available LDAP scope: %s")
215:           raise ArgumentError, format % [scope.inspect, available_scopes]
216:         end
217:         value
218:       end

[Source]

     # File lib/active_ldap/adapter/ldap.rb, line 181
181:       def execute(method, info=nil, *args, &block)
182:         begin
183:           name = (info || {}).delete(:name) || method
184:           log(name, info) {@connection.send(method, *args, &block)}
185:         rescue LDAP::ResultError
186:           @connection.assert_error_code
187:           raise $!.message
188:         end
189:       end

[Source]

     # File lib/active_ldap/adapter/ldap.rb, line 253
253:       def parse_entries(entries)
254:         result = []
255:         entries.each do |type, key, attributes|
256:           mod_type = ensure_mod_type(type)
257:           binary = schema.attribute(key).binary?
258:           mod_type |= LDAP::LDAP_MOD_BVALUES if binary
259:           attributes.each do |name, values|
260:             result << LDAP.mod(mod_type, name, values)
261:           end
262:         end
263:         result
264:       end

[Source]

     # File lib/active_ldap/adapter/ldap.rb, line 175
175:       def prepare_connection(options={})
176:         operation(options) do
177:           @connection.set_option(LDAP::LDAP_OPT_PROTOCOL_VERSION, 3)
178:         end
179:       end

[Source]

     # File lib/active_ldap/adapter/ldap.rb, line 228
228:       def sasl_bind(bind_dn, options={})
229:         super do |bind_dn, mechanism, quiet|
230:           begin
231:             sasl_quiet = @connection.sasl_quiet
232:             @connection.sasl_quiet = quiet unless quiet.nil?
233:             args = [bind_dn, mechanism]
234:             if need_credential_sasl_mechanism?(mechanism)
235:               args << password(bind_dn, options)
236:             end
237:             info = {
238:               :name => "bind: SASL", :dn => bind_dn, :mechanism => mechanism
239:             }
240:             execute(:sasl_bind, info, *args)
241:           ensure
242:             @connection.sasl_quiet = sasl_quiet
243:           end
244:         end
245:       end

[Source]

     # File lib/active_ldap/adapter/ldap.rb, line 220
220:       def scope_name(scope)
221:         {
222:           LDAP::LDAP_SCOPE_BASE => :base,
223:           LDAP::LDAP_SCOPE_SUBTREE => :sub,
224:           LDAP::LDAP_SCOPE_ONELEVEL => :one,
225:         }[scope]
226:       end

[Source]

     # File lib/active_ldap/adapter/ldap.rb, line 247
247:       def simple_bind(bind_dn, options={})
248:         super do |bind_dn, passwd|
249:           execute(:bind, {:dn => bind_dn}, bind_dn, passwd)
250:         end
251:       end

[Validate]