Rails Devise LDAP Error: NoMethodError in Devise::SessionsController#create

My team has setup my ruby on rails app to work with devise ldap. Whenever a user logs in for the first time, it creates a new entry in the Users model and works completely fine. But whenever a user that already exist in the Users database tries to login it gives the following error:

NoMethodError in Devise::SessionsController#create

undefined method `to' for nil:NilClass

From looking at the server console, it seems like it is failing on this SQL statement:

SELECT `users`.* FROM `users` WHERE `users`.`username` = 'jDoe' LIMIT 1

I think the server is getting no results from that query.

But whenever I run that same sql statement in the ruby console, it gives the correct result (the record of the user attempting to login)

Here are some of my devise configs. I am new to devise and ruby (and I also didn't install the devise) so let me know if you need other config files to debug this problem.

initializers/devise.rb

Devise.setup do |config|

  config.ldap_create_user = true
  config.ldap_update_password = false

  config.mailer_sender = "****"

  require 'devise/orm/active_record'

  config.authentication_keys = [ :username ]

  config.case_insensitive_keys = [ :email ]

  config.strip_whitespace_keys = [ :email ]

  config.skip_session_storage = [:http_auth]

  config.stretches = Rails.env.test? ? 1 : 10

  config.reconfirmable = true

  config.password_length = 8..128

  config.sign_out_via = :delete

end

ldap.yml

authorizations: &AUTHORIZATIONS
  group_base: ou=groups,dc=test,dc=com

  required_groups:

    - cn=admins,ou=groups,dc=test,dc=com
    - cn=users,ou=groups,dc=test,dc=com

    - ["moreMembers", "cn=users,ou=groups,dc=test,dc=com"]

  require_attribute:
    objectClass: inetOrgPerson
    authorizationRole: postsAdmin

development:
  host: ****
  port: 636
  attribute: uid 
  base: ou=People,dc=***,dc=com
  admin_user: cn=admin,dc=test,dc=com
  admin_password: admin_password
  ssl: true

test:
  host: localhost
  port: 3389
  attribute: cn
  base: ou=people,dc=test,dc=com
  admin_user: cn=admin,dc=test,dc=com
  admin_password: admin_password
  ssl: simple_tls

production:
  host: localhost
  port: 636
  attribute: cn
  base: ou=people,dc=test,dc=com
  admin_user: cn=admin,dc=test,dc=com
  admin_password: admin_password
  ssl: start_tls

user.rb

class User < ActiveRecord::Base
  devise :ldap_authenticatable, :rememberable, :trackable
  attr_accessible :name, :cell, :email, :pref, :type, :username, :password, :password_confirmation, :remember_me
end

Answers


My problem happened because I had 2 tables that inherited from User (Client, and Runner) and they both tried to authenticate with the same ldap. When I took out the single table inheritance everything worked fine.


Need Your Help

How to align two divs evenly

html css html5

I am trying to render a section of my pafe as in this following image. http://i.imgur.com/63q9Syr.jpg

root-artifact.xml does not automatically generate when create CApp project (wso2 carbon studio v2.0.1)

wso2 wso2carbon wso2developerstudio

I installed wso2 carbon studio 2.0.1 (ref: http://wso2.org/project/developer-studio/2.0.1/docs/install_guide.html, https://wso2.org/jira/browse/TOOLS-739), but root-artifact.xml does not automatica...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.