ruby-on-rails - 为什么 ldap 绑定在服务器上失败?
问题描述
我在我的 Rails 应用程序中对 LDAP 服务器进行身份验证,下面的代码在本地工作,但不在服务器上工作。
Net::LDAP::BindingInformationInvalidError (Invalid binding information)
在尝试登录应用程序时抛出的服务器上,但通过控制台工作
我对 Ruby 很陌生,无法找出调试它的正确方法......我知道 LDAP 配置是正确的,因为我可以从控制台或本地开发环境中进行身份验证和绑定.. 我试图通过:verbose => true
到 LDAP 构造函数,但没有效果......
require 'net/ldap'
require 'devise/strategies/authenticatable'
module Devise
module Strategies
class LdapAuthenticatable < Authenticatable
def authenticate!
if params[:user]
ldap = Net::LDAP.new :host => 'XX.XX.XX.XX',
:port => 636,
:connect_timeout => 5,
:base => 'CN=Configuration,DC=internal,DC=XX,DC=XX',
:encryption => {
:method => :simple_tls
},
:auth => {
:method => :simple,
:username => ENV['LDAP_USER'],
:password => ENV['LDAP_PASSWORD']
}
result = ldap.bind_as(:base => "OU=Users,OU=XX,DC=XX,DC=XX,DC=XX",
:filter => "(userPrincipalName=#{email})",
:password => password,
)
if result
user = User.find_by(email: email)
success!(user)
else
return fail(:invalid_login)
end
end
end
def email
params[:user][:email]
end
def password
params[:user][:password]
end
end
end
end
Warden::Strategies.add(:ldap_authenticatable, Devise::Strategies::LdapAuthenticatable)
解决了
原来是 ENV 变量没有被读取。
解决方案
也许该帐户未授权?听起来问题出在绑定配置中:base => "OU=Users,OU=XX,DC=XX,DC=XX,DC=XX"
来自遇到此错误的其他用户的更多信息:
推荐阅读
- node.js - 如果有共享卷,节点应用程序将不会在 Docker 中启动
- javascript - Sinon - 我可以模拟构造函数吗?
- javascript - 测试Edge中是否存在框架
- python - Python - 使用输入参数链接生成器
- reactjs - index.js:1 警告:收到非布尔属性“活动”的“真”
- reactjs - 如果没有管理员角色,如何在 Nextjs 中保护客户端的路由并重定向?
- visual-studio-code - 编辑 VSCode JSON 设置而不是 Gui 设置
- reactjs - 你如何构建一个网络应用程序?
- r - 删除绘图中的自动标题 (R)
- reactjs - 无法从 API 中提取数据并在 React 中绘制数据