【发布时间】:2019-08-19 01:55:55
【问题描述】:
我是使用 LDAP 的新手,非常感谢任何帮助。
我正在编写一个向 LDAP 服务器添加条目的 Ruby 程序。我可以使用终端很好地添加条目。但挑战在于使用 Ruby 使其工作。
这是我要写入的 LDAP 服务器。
# example.org
dn: dc=example,dc=org
objectClass: top
objectClass: dcObject
objectClass: organization
o: Example Inc.
dc: example
# admin, example.org
dn: cn=admin,dc=example,dc=org
objectClass: simpleSecurityObject
objectClass: organizationalRole
cn: admin
description: LDAP administrator
userPassword: mypassword
# people, example.org
dn: ou=people,dc=example,dc=org
objectClass: organizationalUnit
ou: people
这里是 ldap-program.rb 的内容。对于
require 'rubygems'
require 'net/ldap'
ldap = Net::LDAP.new :host => '127.0.0.1',
:port => 1300,
:auth => {
:method => :simple,
:username => 'cn=admin,dc=example,dc=org',
:password => 'mypassword'
}
dn = "uid=christine,ou=people,dc=example,dc=com"
attr = {
:cn => "Christine",
:sn => "Smith",
:objectClass => "inetOrgPerson",
:mail => "christine@example.com",
:uid => "christine"
}
ldap.add(:dn => dn, :attr => attr)
我一直在密切关注 ldap.add 的文档,但在这种情况下,该条目不会添加到 LDAP。谁能给点指点或建议?
【问题讨论】:
-
您能描述一下您返回的错误吗?
-
可能需要单独的 ldap.auth,请参见此处:stackoverflow.com/questions/21271834/ruby-net-ldap-add-user。
-
请注意....由于命名属性是 'uid' ,您也不需要将其添加为属性。
-
您标记了
active-directory。你真的在使用AD吗?如果是这样,我可以看到你有一些问题。
标签: ruby database active-directory ldap ldap-query