gpt4 book ai didi

ruby-on-rails - 使用 ldap 通过设计 ruby​​ on rails 连接到广告

转载 作者:数据小太阳 更新时间:2023-10-29 08:07:18 25 4
gpt4 key购买 nike

问题 我在使用 devise_ldap_authentication 连接到我的 Microsoft Active Directory 时遇到问题。出于某种原因,当我将 LDAP 搜索与 devise 一起使用时,我一直得到 LDAP 搜索产生 0 个匹配项,我 100% 确定我使用的是正确的凭据,所以我使用“net/ldap”编写了一个测试类,看看我是否可以找到正确的匹配项很快它就可以与我的测试类一起使用,但是,我仍然无法使用 devise_ldap_auth 进行身份验证。任何帮助将不胜感激或帮助设置我的 config/ldap.yml 以匹配我的测试类。

这是我的config/ldap.yml

#Environment
development:
host: myldap.mydomain.com
port: 389
attribute: sAMAccountname
base: dc=mydomain, dc=com
admin_user: cn=admin,dc=mydomain,dc=com
admin_password: password
#ssl: false

这是我的设计.rb

Devise.setup do |config|
# ==> LDAP Configuration
config.ldap_logger = true
# config.ldap_create_user = false
# config.ldap_update_password = true
config.ldap_config = "#{Rails.root}/config/ldap.yml"
# config.ldap_check_group_membership = false
# config.ldap_check_group_membership_without_admin = false
config.ldap_check_attributes = true
#config.ldap_use_admin_to_bind = true
# config.ldap_ad_group_check = false

这是我在设计中使用 ldap 时得到的结果。

D, [2016-06-24T07:01:30.558440 #42760] DEBUG -- :   LDAP: LDAP dn lookup: sAMAccountName=snow
D, [2016-06-24T07:01:30.558507 #42760] DEBUG -- : LDAP: LDAP dn lookup: sAMAccountName=snow
D, [2016-06-24T07:01:30.558549 #42760] DEBUG -- : LDAP: LDAP search for login: sAMAccountName=snow
D, [2016-06-24T07:01:30.558579 #42760] DEBUG -- : LDAP: LDAP search for login: sAMAccountName=snow
D, [2016-06-24T07:01:30.594029 #42760] DEBUG -- : LDAP: LDAP search yielded 0 matches
D, [2016-06-24T07:01:30.594099 #42760] DEBUG -- : LDAP: LDAP search yielded 0 matches
D, [2016-06-24T07:01:30.594146 #42760] DEBUG -- : LDAP: Authorizing user sAMAccountName=snow,dc=mydomain, dc=com
D, [2016-06-24T07:01:30.594180 #42760] DEBUG -- : LDAP: Authorizing user sAMAccountName=snow,dc=mydomain, dc=com
D, [2016-06-24T07:01:30.611308 #42760] DEBUG -- : LDAP: Not authorized because not authenticated.
D, [2016-06-24T07:01:30.611377 #42760] DEBUG -- : LDAP: Not authorized because not authenticated.

这是我的测试类,用于在我的 Microsoft AD 上使用 ldap 进行身份验证

require 'net/ldap' # gem install ruby-net-ldap
module Test
class PutAd
SERVER = 'myldap.mydomain.com'
PORT = 389
BASE = 'DC=mydomain,DC=com'
DOMAIN = 'mydomain.com'

ATTR_SV = {
:login => :samaccountname,
:first_name => :givenname,
:last_name => :sn,
:email => :mail
}


def self.authenticate(login, pass)
return nil if login.empty? or pass.empty?

conn = Net::LDAP.new :host => SERVER,
:port => PORT,
:base => BASE,
:auth => { :username => "#{login}@#{DOMAIN}",
:password => pass,
:method => :simple }
if conn.bind and user = conn.search(:filter => "sAMAccountName=#{login}").first
return self.new(user)
else
return nil
end
rescue Net::LDAP::LdapError => e
return nil
end
end
end

^这将返回我的帐户信息,如果匹配则返回零。

最佳答案

原来我的公司有不同的授权用户的方式。我将高级标志添加到我的设计 ldap 安装中,并相应地设置它并立即运行。

==> 高级 LDAP 配置

config.ldap_auth_username_builder = Proc.new() {|attribute, login, ldap| "#{login}@mydomain.com"}

关于ruby-on-rails - 使用 ldap 通过设计 ruby​​ on rails 连接到广告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38013178/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com