问题描述
我正在尝试通过这样做来使用 ldap 创建一个新用户:
I am trying to create a new user using ldap by doing this:
require 'net/ldap'
ldap = Net::LDAP.new
ldap.host = 'ldap'
ldap.auth('uid=myuser,ou=users,dc=my,dc=domain,dc=com', 'mypass')
ldap.bind # this executes successfully, up to this point, all is well
dn = 'uid=newuser,ou=users,dc=my,dc=domain,dc=com'
attributes = { cn: 'newuser', sn: 'surname', objectclass: ['top', 'agent'] }
ldap.add(dn: dn, attributes: attributes)
ldap.get_operation_result
#=> #<OpenStruct code=21, message="unknown result (21)">
我是 ldap 的新手,我在网上找不到一个地方可以提供如何使用 net-ldap 创建新用户的清晰示例.
I am new to ldap, and I can't find a place online that provides a clear example of how to use net-ldap to create a new user.
推荐答案
我也有这些问题,过去 2 天,但终于想出了一个解决方案来让我的用户.这是我的工作代码:
I had these issues aswell, last 2 days, but finally figured out a solution to make my user.Here is the working code for me:
ldap = Net::LDAP.new
ldap.host = SERVER
ldap.port = PORT
ldap.authenticate login, pass
dn = "cn=Pick Name, dc=example, dc=com"
attr = {
:cn => "Pick Name",
:objectclass => "User",
:sn => 'Name',
:telephoneNumber => "12345678",
:mail => "[email protected]"
}
ldap.add(:dn => dn, :attributes => attr)
我认为给我带来问题的是 ObjectClass .. 在对象类中,您使用 AD 中设置的 Type 编写.所以如果你想要一个组织单位,它看起来像这样: :objectclass => "organizationalUnit"另外我认为DN和attr中的CN需要相同.
The thing I think that has given me issues is the ObjectClass .. In the object class you write in the Type thats set in your AD. So if you wanted an organizational Unit, it would look like this: :objectclass => "organizationalUnit"Also I think the CN in DN and attr needs to be identical.
希望对你有帮助
这篇关于Ruby net-ldap 添加用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!