Created
December 4, 2009 19:31
-
-
Save mattyoho/249280 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# http://lbi.lostboys.nl/prikbord/ruby-on-rails-ldap-integration | |
class UserSession < Authlogic::Session::Base | |
verify_password_method :valid_ldap_credentials? | |
end | |
class User < ActiveRecord::Base | |
acts_as_authentic :validate_password_field => false | |
protected | |
def valid_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 successful | |
end | |
end | |
class CreateUsers < ActiveRecord::Migration | |
def self.up | |
create_table :users do |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.timestamps | |
end | |
end | |
def self.down | |
drop_table :users | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment