尝试在Ruby on Rails上进行LDAP搜索查询但不断收到错误不能引用Net :: LDAP :: Entry

时间:2017-07-13 09:32:04

标签: 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 = 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

我的sessions_controller:

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

此代码正在检查LDAP中是否存在尝试登录的用户,如果他在LDAP and SQL DB,他将在webapp上获得会话并继续,如果他在LDAP而不在SQL DB我的SQLSERVER数据库中的某一行将使用employee number (NumeroEmpregado, title)创建,当我'我试图从LADP获取title来创建我得到的字段can't quote Net::LDAP::Entry我尝试了不同的过滤器,有些过滤了nil和其他[]

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

0 个答案:

没有答案