Class ActiveLDAP::Base
In: lib/activeldap/base.rb
Parent: Object

Base

Base is the primary class which contains all of the core ActiveLDAP functionality. It is meant to only ever be subclassed by extension classes.

Methods

External Aliases

methods -> __methods
  Add available attributes to the methods

Attributes

logger  [RW] 
may  [R]  Parsed schema structures
must  [R]  Parsed schema structures

Public Class methods

On connect, this is overriden by the :base argument Make the return value the string that is your LDAP base

Base.base

This method when included into Base provides an inheritable, overwritable configuration setting

This should be a string with the base of the ldap server such as ‘dc=example,dc=com’, and it should be overwritten by including configuration.rb into this class. When subclassing, the specified prefix will be concatenated.

Determine if we have exceed the retry limit or not. True is reconnecting is allowed - False if not.

Base.close This method deletes the LDAP connection object. This does NOT reset any overridden values from a Base.connect call.

Connect and bind to LDAP creating a class variable for use by all ActiveLDAP objects.

config

config must be a hash that may contain any of the following fields: :user, :password_block, :logger, :host, :port, :base, :bind_format, :try_sasl, :allow_anonymous :user specifies the username to bind with. :bind_format specifies the string to substitute the username into on bind. e.g. uid=%s,ou=People,dc=dataspill,dc=org. Overrides @@bind_format. :password_block specifies a Proc object that will yield a String to be used as the password when called. :logger specifies a preconfigured Log4r::Logger to be used for all logging :host sets the LDAP server hostname :port sets the LDAP server port :base overwrites Base.base - this affects EVERYTHING :try_sasl indicates that a SASL bind should be attempted when binding to the server (default: false) :allow_anonymous indicates that a true anonymous bind is allowed when trying to bind to the server (default: true) :retries - indicates the number of attempts to reconnect that will be undertaken when a stale connection occurs. -1 means infinite. :sasl_quiet - if true, sets @sasl_quiet on the Ruby/LDAP connection :method - whether to use :ssl, :tls, or :plain (unencrypted) :retry_wait - seconds to wait before retrying a connection :ldap_scope - dictates how to find objects. ONELEVEL by default to avoid dn_attr collisions across OUs. Think before changing. :return_objects - indicates whether find/find_all will return objects or just the distinguished name attribute value of the matches :timeout - time in seconds - defaults to disabled. This CAN interrupt search() requests. Be warned. :retry_on_timeout - whether to reconnect when timeouts occur. Defaults to true See lib/configuration.rb for defaults for each option

Return the LDAP connection object currently in use Alternately execute a command against the connection object "safely" using a given block. Use the given "errmsg" for any error conditions.

Set the LDAP connection avoiding Base.connect or multiplexing connections

Driver generator

TODO add type checking This let’s you call this method to create top-level extension object. This is really just a proof of concept and has not truly useful purpose. example: Base.create_object(:class => "user", :dnattr => "uid", :classes => [‘top’])

THIS METHOD IS DANGEROUS. INPUT IS NOT SANITIZED.

Base.dnattr

This is a placeholder for the class method that will be overridden on calling ldap_mapping in a subclass. Using a class method allows for clean inheritance from classes that already have a ldap_mapping.

On connect, this is overriden by the :base argument

Set this to LDAP_SCOPE_SUBTREE if you have a LDAP tree where all objects of the same class living in different parts of the same subtree, but not. LDAP_SCOPE_ONELEVEL is for use when all the objects in your classes live under one shared level (e.g. ou=People,dc=localdomain)

This can be overriden on a per class basis in ldap_mapping :scope

Base.ldap_scope

This method when included into Base provides an inheritable, overwritable configuration setting

This value should be the default LDAP scope behavior desired.

Attempts to reconnect up to the number of times allowed If forced, try once then fail with ConnectionError if not connected.

Base.required_classes

This method when included into Base provides an inheritable, overwritable configuration setting

The value should be the minimum required objectClasses to make an object in the LDAP server, or an empty array []. This should be overwritten by configuration.rb. Note that subclassing does not cause concatenation of arrays to occurs.

This is optionally set to the array of objectClass names that are minimally required for EVERY object on your LDAP server. If you don’t want one, set this to [].

Return the schema object

search

Wraps Ruby/LDAP connection.search to make it easier to search for specific data without cracking open Base.connection

Public Instance methods

attributes

Return attribute methods so that a program can determine available attributes dynamically without schema awareness

delete

Delete this entry from LDAP

dn

Return the authoritative dn

exists?

Return whether the entry exists in LDAP or not

method_missing

If a given method matches an attribute or an attribute alias then call the appropriate method. TODO: Determine if it would be better to define each allowed method

      using class_eval instead of using method_missing.  This would
      give tab completion in irb.

validate

Basic validation:

  • Verify that every ‘MUST’ specified in the schema has a value defined
  • Enforcement of undefined attributes is handled in the objectClass= method

Must call enforce_types() first before enforcement can be guaranteed

write

Write and validate this object into LDAP either adding or replacing attributes TODO: Binary data support TODO: Relative DN support

[Validate]