所以,我正在尝试对我的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
和其他[]