classUserSession < Authlogic::Session::Base
verify_password_method :valid_ldap_credentials?endclassUser < ActiveRecord::Base
acts_as_authentic :validate_password_field => falseprotecteddefvalid_ldap_credentials?(password_plaintext) # try to authenticate against the LDAP server
ldap =Net::LDAP.new
ldap.host=LDAP_HOST # first create the username/password strings to send to the LDAP server # in our case we need to add the domain so it looks like COMPANY\firstname.lastname
ldap.auth"#{LDAP_DOMAIN}\\"+self.login, password_plaintext
ldap.bind# will return false if authentication is NOT successfulendendclassCreateUsers < ActiveRecord::Migrationdefself.up
create_table :usersdo |t|
t.string:login
t.string:persistence_token
t.integer:login_count
t.datetime:last_request_at
t.datetime:last_login_at
t.datetime:current_login_at
t.string:last_login_ip
t.string:current_login_ip
t.timestampsendenddefself.down
drop_table :usersendend