For work we wanted to have our users login using their Windows domain account. Windows domain servers have an LDAP implementation so we decided to add LDAP support to our AuthLogic login scheme.
The first step is to get a basic LDAP Authentication working. The followings steps detail that method.
First go to https://entic.net/CF and setup an account there. You will receive an email with important connection information.
Install the ruby-ldap gem.
sudo gem install ruby-ldap
Next you should test that you have everything figured out by connecting to your LDAP.
require 'net/ldap'
ldap = Net::LDAP.new
=> #<Net::LDAP:0x100540f78 @open_connection=nil, @encryption=nil, @auth={:method=>:anonymous}, @verbose=false, @port=389, @base="dc=com", @host="127.0.0.1">
ldap.host 'ds1-sjc.entic.net'
ldap.port = 389
ldap.auth 'uid=username, ou=People, o=entic.net', 'pwd'
ldap.bind
If it all works you should get a true response, entering an invalid password will get a false. There are other errors you can get if you have the wrong connection etc.
Once this method works you can try working with the LDAP you are going to connect to for regular use.
Once I had this working I added in the AuthLogic-LDAP. I had to make a lot of modifications though and those can be seen at https://github.com/onyxgs/authlogic_ldap.
To use this you need to add your settings to the UserSession class.
class UserSession < Authlogic::Session::Base
ldap_port 389
ldap_host 'ds1-sjc.entic.net'
ldap_ou 'People'
ldap_o 'entic.net'
find_by_ldap_login_method :find_by_username
end
There are also some settings you can/should make in the User class.
acts_as_authentic do |config|
config.validate_email_field = false
config.validate_ldap_login = AppConfig.use_ldap
end