Module ActiveLdap::Operations::Find
In: lib/active_ldap/operations.rb
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

Public Instance methods

find

Finds the first match for value where |value| is the value of some |field|, or the wildcard match. This is only useful for derived classes. usage: Subclass.find(:attribute => "cn", :value => "some*val")

       Subclass.find('some*val')

[Source]

     # File lib/active_ldap/operations.rb, line 195
195:       def find(*args)
196:         options = extract_options_from_args!(args)
197:         args = [:first] if args.empty? and !options.empty?
198:         case args.first
199:         when :first
200:           find_initial(options)
201:         when :all
202:           options[:value] ||= args[1]
203:           find_every(options)
204:         else
205:           find_from_dns(args, options)
206:         end
207:       end

Private Instance methods

[Source]

     # File lib/active_ldap/operations.rb, line 318
318:       def ensure_dn(target)
319:         attr, value, prefix = split_search_value(target)
320:         "#{attr || dn_attribute}=#{value},#{prefix || base}"
321:       end

[Source]

     # File lib/active_ldap/operations.rb, line 225
225:       def find_every(options)
226:         options = options.dup
227:         sort_by = options.delete(:sort_by) || self.sort_by
228:         order = options.delete(:order) || self.order
229:         limit = options.delete(:limit) if sort_by or order
230:         options[:attributes] |= ["objectClass"] if options[:attributes]
231: 
232:         results = search(options).collect do |dn, attrs|
233:           instantiate([dn, attrs, {:connection => options[:connection]}])
234:         end
235:         return results if sort_by.nil? and order.nil?
236: 
237:         sort_by ||= "dn"
238:         if sort_by.downcase == "dn"
239:           results = results.sort_by {|result| DN.parse(result.dn)}
240:         else
241:           results = results.sort_by {|result| result.send(sort_by)}
242:         end
243: 
244:         results.reverse! if normalize_sort_order(order || "ascend") == :descend
245:         results = results[0, limit] if limit
246:         results
247:       end

[Source]

     # File lib/active_ldap/operations.rb, line 249
249:       def find_from_dns(dns, options)
250:         expects_array = dns.first.is_a?(Array)
251:         return [] if expects_array and dns.first.empty?
252: 
253:         dns = dns.flatten.compact.uniq
254: 
255:         case dns.size
256:         when 0
257:           raise EntryNotFound, _("Couldn't find %s without a DN") % name
258:         when 1
259:           result = find_one(dns.first, options)
260:           expects_array ? [result] : result
261:         else
262:           find_some(dns, options)
263:         end
264:       end

[Source]

     # File lib/active_ldap/operations.rb, line 210
210:       def find_initial(options)
211:         find_every(options.merge(:limit => 1)).first
212:       end

[Source]

     # File lib/active_ldap/operations.rb, line 266
266:       def find_one(dn, options)
267:         attr, value, prefix = split_search_value(dn)
268:         filter = [attr || ensure_search_attribute,
269:                   Escape.ldap_filter_escape(value)]
270:         filter = [:and, filter, options[:filter]] if options[:filter]
271:         options = {:prefix => prefix}.merge(options.merge(:filter => filter))
272:         result = find_initial(options)
273:         if result
274:           result
275:         else
276:           args = [self.is_a?(Class) ? name : self.class.name,
277:                   dn]
278:           if options[:filter]
279:             format = _("Couldn't find %s: DN: %s: filter: %s")
280:             args << options[:filter].inspect
281:           else
282:             format = _("Couldn't find %s: DN: %s")
283:           end
284:           raise EntryNotFound, format % args
285:         end
286:       end

[Source]

     # File lib/active_ldap/operations.rb, line 288
288:       def find_some(dns, options)
289:         dn_filters = dns.collect do |dn|
290:           attr, value, prefix = split_search_value(dn)
291:           attr ||= ensure_search_attribute
292:           filter = [attr, value]
293:           if prefix
294:             filter = [:and,
295:                       filter,
296:                       [dn, "*,#{Escape.ldap_filter_escape(prefix)},#{base}"]]
297:           end
298:           filter
299:         end
300:         filter = [:or, *dn_filters]
301:         filter = [:and, filter, options[:filter]] if options[:filter]
302:         result = find_every(options.merge(:filter => filter))
303:         if result.size == dns.size
304:           result
305:         else
306:           args = [self.is_a?(Class) ? name : self.class.name,
307:                   dns.join(", ")]
308:           if options[:filter]
309:             format = _("Couldn't find all %s: DNs (%s): filter: %s")
310:             args << options[:filter].inspect
311:           else
312:             format = _("Couldn't find all %s: DNs (%s)")
313:           end
314:           raise EntryNotFound, format % args
315:         end
316:       end

[Source]

     # File lib/active_ldap/operations.rb, line 214
214:       def normalize_sort_order(value)
215:         case value.to_s
216:         when /\Aasc(?:end)?\z/i
217:           :ascend
218:         when /\Adesc(?:end)?\z/i
219:           :descend
220:         else
221:           raise ArgumentError, _("Invalid order: %s") % value.inspect
222:         end
223:       end

[Validate]