On Wed, 2008-04-23 at 14:40 +0200, Rory McKinley wrote:
l.set_option( LDAP::LDAP_OPT_PROTOCOL_VERSION, 3 )
Any clues as to what might be causing this?
All help appreciated.
Rory
here’s how I do it using ruby-ldap
** my_ldap.rb **
require “ldap”
Provides access to authenticate user from LDAP using the user provided
user name and password
class MyLDAP < LDAP::Conn
BASE_DN = “dc=example,dc=com”
PEOPLE_DN = “ou=people,dc=example,dc=com”
LDAP_HOST = “server.example.com”
LDAP_PORT = 389
PROTOCOL_VERSION = 3
sets up connection to LDAP server
def initialize (host = LDAP_HOST, version = PROTOCOL_VERSION)
super( host, LDAP_PORT )
set_option( LDAP::LDAP_OPT_PROTOCOL_VERSION, version )
return self
end
Bind with the user supplied information
def bind(mydn, pass)
dn = “uid=” + mydn + “,” + PEOPLE_DN
super( dn, pass )
end
end
** user.rb **
Takes user login name and password and connects to LDAP
def self.login(login, password)
if password == ‘’
return false
end
begin
conn = MyLDAP.new.bind(login, password)
rescue
return false
end
return conn.bound?
conn.unbind
end
Forces user login screen
def try_to_login
User.login(self.login, self.password)
end
and then finally, in my ‘login_controller.rb’
@user = User.new(params[:user])
logged_in_user = @user.try_to_login
if logged_in_user
@authuser=User.find(:first,
:conditions => [“login = ?”, @user[:login] ])
if @authuser == nil
flash[:notice] = “You are not authorized to use this system”
else
session[:user_id] = @authuser.id
session[:user_name] = @authuser.name
if session[:direct_to]
redirect_to (session[:direct_to])
else
redirect_to(:controller => “main_tabnav” )
end
end
So I think you should have enough information to make it work.
Craig