I'm working on getting LDAP authentication into the hobo user model.
I'll create a recipe in the cookbook for it once I get it all
working.

I'm using the "simple_ldap_authenticator" gem.

I added the LDAP configuration settings to the top of environment.rb:

   require 'ldap'
   require 'simple_ldap_authenticator'
   SimpleLdapAuthenticator.servers = [<my domain controllers>]
   SimpleLdapAuthenticator.use_ssl = false  # so far I can't get SSL
to work yet
   SimpleLdapAuthenticator.port = 389
   SimpleLdapAuthenticator.login_format = '%[email protected]'

SimpleLdapAuthenticator also requires a logger to be set, but the
RAILS_DEFAULT_LOGGER is not defined yet when environment.rb is
executing, so I added that piece to initializers/new_rails_defaults.rb
for now.
  SimpleLdapAuthenticator.logger = RAILS_DEFAULT_LOGGER
I'll find a better place to do this later, but this works for now.

I was thinking I would override the .authenticate method of the user
model, but doing a def authenticate inside models/user.rb doesn't seem
to override the authenticate method that's defined in /usr/lib/ruby/
gems/1.8/gems/hobo-0.9.102/lib/hobo/user.rb.  So for now I have to do
my experimentation inside /usr/lib/ruby/gems/1.8/gems/hobo-0.9.102/lib/
hobo/user.rb.

The authenticate method should check if the login/password combination
is valid using SimpleLdapAuthenticator.valid?(login, password).  If
it's valid, then find the user in the database and use it.  If the
user does not exist in the database, create the user record.

Something like this:
   def authenticate(login, password)
        if SimpleLdapAuthenticator.valid?(login, password)
                 u = find(:first, :conditions => ["#...@login_attribute} = ?", 
login])
# need to get the salt (actually, no I don't care about salt anymore,
I just want the record :)
           if u.nil?
                        u = User.new  # Doesn't work
                        u.email_address = login + "@domain.com"
          end
        u
    end

User.new works in script/console, but not in this authenticate
method.  It's a Hobo::User, not a User here, and Hobo::User doesn't
have a new method..  Maybe I need @user_models.new or something?

So my questions for the gurus:

0.  Is this even the correct approach?
1.  How can I override/redefine the authenticate method of the user
model?
2.  How do I create a new user record in the database from the
authenticate method?

Thanks for your input!

Brian

--

You received this message because you are subscribed to the Google Groups "Hobo 
Users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/hobousers?hl=en.


Reply via email to