cschiewek / devise_ldap_authenticatable

Devise Module for LDAP
MIT License
594 stars 359 forks source link

nomethod error in devise::sessions::create. #256

Closed spacerobotTR closed 5 years ago

spacerobotTR commented 5 years ago

I have deployed a site to a linux server via capistrano and I cannot get the LDAP authentication to function on it. It works fine in development on my windows machine and my MAC dev machine but on the production serer it errors out with nomethod error in devise::sessions::create. undefined method `[]' for nil:NilClass.

The highlighted error code is:

ldap_options = params ldap_config["ssl"] = :simple_tls if ldap_config["ssl"] === true ldap_options[:encryption] = ldap_config["ssl"].to_sym if ldap_config["ssl"]

LDAP.yml:

`authorizations: &AUTHORIZATIONS required_groups: - CN=GROUP1,OU=Users,OU=mysite,DC=ad,DC=com

development:
  host: mysite.com
  port: 389
  attribute: sAMAccountName
  base: dc=ad,dc=com
  admin_user: user
  admin_password: password
  ssl: false
  <<: *AUTHORIZATIONS

 production:
  host: mysite.com
  port: 389
  attribute: sAMAccountName
  base: dc=ad,dc=com
  admin_user: user
  admin_password: password
  ssl: false
  <<: *AUTHORIZATIONS`

initializers/devise.rb

`Devise.setup do |config|

  # ==> LDAP Configuration
   config.ldap_logger = true
   config.ldap_create_user = true
  # config.ldap_update_password = true
  # config.ldap_config = "#{Rails.root}/config/ldap.yml"
   config.ldap_check_group_membership = true
  # config.ldap_check_group_membership_without_admin = false
  # config.ldap_check_attributes = true
  # config.ldap_check_attributes_presence = false
   config.ldap_use_admin_to_bind = true
   config.ldap_ad_group_check = true

  config.mailer_sender = 'please-change-me-at-config-initializers-devise@example.com'

  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 : 11

  config.reconfirmable = true

  config.expire_all_remember_me_on_sign_out = true

  config.password_length = 6..128

  config.email_regexp = /\A[^@\s]+@[^@\s]+\z/

  config.timeout_in = 15.minutes

  config.reset_password_within = 6.hours

  config.sign_out_via = :delete

end`

user.rb

`class User < ApplicationRecord
  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
  devise :ldap_authenticatable, :registerable,
         :recoverable, :rememberable, :validatable
  def email_required?
    false
  end

  validates :username, presence: true, uniqueness: true

  has_many :projects
end`

I've been all over this but have not gotten it to work yet. I am wondering if the production site can't find the ldap files maybe?

Any help is appreciated.

spacerobotTR commented 5 years ago

I figured it out! In my LDAP.yml file the production connection section was indented by one space. This was causing it to not load the config correctly. Everything is working now.

muhammadrefda commented 3 years ago

thanks, I'm getting this error too, resolve by delete one space in development