Skip to content

Instantly share code, notes, and snippets.

@masaki
Created July 26, 2009 16:26
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save masaki/155854 to your computer and use it in GitHub Desktop.
Save masaki/155854 to your computer and use it in GitHub Desktop.
authentication w/ ActiveLdap
#!/usr/bin/env ruby
require 'rubygems'
require 'active_ldap'
ActiveLdap::Base.setup_connection(
:host => 'ldap.example.com',
:base => 'dc=example,dc=com',
)
class User < ActiveLdap::Base
ldap_maping
class << self
def authenticate(dn, password)
user = find(dn)
user.bind(password)
user
rescue ActiveLdap::EntryNotFound,
ActiveLdap::AuthenticationError,
ActiveLdap::LdapError::UnwillingToPerform
nil
end
end
end
if $0 == __FILE__
p User.authenticate('foo', 'bar')
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment