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
上,他将在mywebapp上获得一个会话并继续,如果他在LDAP
上,而不在sqldb
上,我的SQLSERVER
数据库中将创建一行员工编号(NumeroEmpregado,title)
当我试图从LADP获取标题
以创建字段时,我获取的无法引用Net::LDAP::Entry
我尝试了不同的过滤器,一些过滤器给了我零
而另一些过滤器给了我[]
- 我的代码有问题吗?我该如何解决这个问题