I run: Ruby 1.9.3p0, Rails 3.1.1, Develop 1.4.9, Devise_ldap_authenticatable 0.4.10
I use Devise to authenticate my Rails application through the ldap server. I use the username instead of email for authentication, so naturally the email field in my table is empty.
To request ldap for email, the official way is to add this code to the user model:
before_save :get_ldap_email def get_ldap_email self.email = Devise::LdapAdapter.get_ldap_param(self.username,"mail") end
This code crashes without trying to do anything with ldap:
undefined method `mail' for nil:NilClass
This refers to the line inside the method definition. Log output is no more useful:
Started POST "/users/sign_in" for 10.50.1.96 at 2011-11-15 11:18:16 -0800 Processing by Devise::SessionsController#create as HTML Parameters: {"utf8"=>"✓", "authenticity_token"=>"<hidden>=", "user"=>{"username"=>"<hidden>", "password"=>"[FILTERED]", "remember_me"=>"0"}, "commit"=>"Sign in"} User Load (0.9ms) SELECT "users".* FROM "users" WHERE "users"."username" = '<hidden>' LIMIT 1 LDAP: LDAP dn lookup: uid=<hidden> LDAP: LDAP search for login: uid=<hidden> LDAP: Authorizing user <hidden> LDAP: LDAP dn lookup: uid=<hidden> LDAP: LDAP search for login: <hidden> Completed 500 Internal Server Error in 251ms NoMethodError (undefined method `mail' for nil:NilClass): app/models/user.rb:14:in `get_ldap_email'
All lines preceding error 500 are normal successful LDAP authentication not associated with an email request.
I only started learning Ruby, Rails, and Devise last week, so I'm not sure which files will be most important, but here is my user.rb and gemfile model:
class User < ActiveRecord::Base
And gemfile:
source 'http://rubygems.org' gem 'rails', '3.1.1'
I tried to restart the server and installed the package since the last GemFile update. In my configuration there is ldap_create_user = true, and the username is the correct field name for users. Is there a mistake in this method? Could there be version incompatibility? I'm not quite sure what else to check, and the rails give me nothing to begin with to continue. I would like to help with this.