Module: PassiveLDAP

Defined in:
lib/passiveldap.rb

Overview

PassiveLDAP

This class is for ActiveRecord <=> LDAP interoparibility, designed so most of the data can be stored in SQL / ActiveRecord tables, but some data (usally the User datas) may be stored in an LDAP directory. PassiveLDAP tries to emulate ActiveRecord as much as possible (like it includes ActiveRecord::Validation, so you may use those methods for attribute validations), and extending it with some methods that are useful when using an LDAP directory. This library can be thought of a high level library on top of Net::LDAP

PassiveLDAP has some “advanced” features. See PassiveLDAP::Base#set_protection_level, PassiveLDAP::Base#set_password and PassiveLDAP::Base#passive_ldap

Usage

Create a subclass of PassiveLDAP, then use the following macros in the subclass’ body to set the connection, and the attributes of the objects: PassiveLDAP::Base#passive_ldap and PassiveLDAP::Base#passive_ldap_attr.

In other aspects PassiveLDAP tries to emulate ActiveRecord, so you may check it’s documentation too. Methods marked with AR are methods used in ActiveRecord too, and they are usually compatible with AR (or they raise ARFeatureMissing or ARMethodMissing)

Example

the User class is a real-life example of the usage of PassiveLDAP.

check the documentation of PassiveLDAP::Base#passive_ldap and PassiveLDAP::Base#passive_ldap_attr too

ActiveRecord compatibility

PassiveLDAP mixes-in some of the modules that ActiveRecord::Base uses. Things that are somehow tested:

  • Validations: #validates_presence_of and #validates_format_of does work, and should other ones too, except #validates_uniqueness_of, because it depends on SQL. PassiveLDAP has a new validation scheme: #validates_format_of_each, which will do a #validates_format_of for each element of a multi-valued attribute.

  • Reflections: the Rails 1.2.x dynamic scaffold (after some modifications so it will work with Rails 2.0.2) works with PassiveLDAP, but ActiveScaffold doesn’t (even after some tinkering. Don’t know why, it will only show the number of records, and the same amount of bars)

The other ones (like Aggregations, Callbacks, Observers, etc.) may work too (or may raise lots of errors), but are untested

PassiveLDAP should work as a “belongs_to” in an ActiveRecord example:

class User < PassiveLDAP::Base
  #config
end
class Account < ActiveRecord::Base
  belongs_to :user, :class_name => "User", :foreign_key => "user_id" 
  # some more config
end

after this you may say something like:

.user.cn

Don’t use “eager loading” as that will of course not work! (it is SQL specific)

Setting #has_one or #has_many in PassiveLDAP is untested (likely to fail) example:

class User < PassiveLDAP::Base
  has_one :account
  # more config
end

Disclaimer

The library is in an early alpha-stage. Use at your own risk.

Bug-fixes and feature-additions sent to my email adress are welcome!

Defined Under Namespace

Modules: Types Classes: ARFeatureMissing, ARMethodMissing, AttributeAssignmentError, Base, ConnectionError, DistinguishedNameException, PassiveLDAPError, RecordNotFound, RecordNotSaved