Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 尝试在RubyonRails上进行LDAP搜索查询,但不断出现错误可能';t quote Net::LDAP::Entry_Ruby On Rails_Ruby_Active Directory_Ldap - Fatal编程技术网

Ruby on rails 尝试在RubyonRails上进行LDAP搜索查询,但不断出现错误可能';t quote Net::LDAP::Entry

Ruby on rails 尝试在RubyonRails上进行LDAP搜索查询,但不断出现错误可能';t quote Net::LDAP::Entry,ruby-on-rails,ruby,active-directory,ldap,Ruby On Rails,Ruby,Active Directory,Ldap,因此,我试图对我的LDAP进行查询,并不断得到错误: can't quote Net::LDAP::Entry 这是我的authenticate_user.rb: class AuthenticateUser def self.call(*args) new(*args).call end def initialize(username, password) @username = "#{username}@company.com" @password =

因此,我试图对我的
LDAP
进行查询,并不断得到错误:

can't quote Net::LDAP::Entry
这是我的authenticate_user.rb:

class AuthenticateUser
  def self.call(*args)
    new(*args).call
  end

  def initialize(username, password)
    @username = "#{username}@company.com"
    @password = password
  end

  def call
    search_title_if_valid_user
  end

  private
  def search_title_if_valid_user
  filter = Net::LDAP::Filter.eq("objectclass", "person")
    ldap = Net::LDAP.new(
      host: "company.com",
      port: 389,
      base: "DC=company,DC=com",
      auth: { method: :simple, username: @username, password: @password }
    )

    ldap.search(filter: filter, attributes: ["title"]) if ldap.bind
  end
end
和我的控制器:

class SessionsController < ApplicationController
  def new
  end

  def create
    username = params[:nome]
    password = params[:password]

    title = AuthenticateUser.call(username, password)
    puts(title.first.inspect)

    if title
      user = User.create_with(nome: username).find_or_create_by(NumeroEmpregado: title)
      session[:user_id] = user.id
      redirect_to '/'
    else
      flash[:error] = "Erro!              \nNúmero de Empregado e/ou password incorrecto(a)"
      redirect_to '/login'
     end
  end

  def destroy
    session[:user_id] = nil
    redirect_to '/index/new'
  end
end
class sessioncontroller
此代码正在检查尝试登录的用户是否在
LDAP
中,如果他在
LDAP和SQL DB
上,他将在my
webapp上获得一个会话并继续,如果他在
LDAP
上,而不在
sqldb
上,我的
SQLSERVER
数据库中将创建一行
员工编号(NumeroEmpregado,title)
当我试图从LADP获取
标题
以创建字段时,我获取的
无法引用Net::LDAP::Entry
我尝试了不同的过滤器,一些过滤器给了我
而另一些过滤器给了我
[]

  • 我的代码有问题吗?我该如何解决这个问题