新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
Ruby連接到LDAP技巧分享
我們在實(shí)際編寫Ruby語言代碼時(shí),在實(shí)現(xiàn)Ruby連接到LDAP的情況下,通常都可以使用到三種方法。在這里我們將會學(xué)到其中的兩種。#t#

Ruby連接到LDAP代碼示例:
- conn = LDAP::Conn.new("rsads02.foo.com")
- conn.bind("CN=username,CN=Users,DC=foo,
DC=com","password") do |bound| - bound.search("DC=foo,DC=com",
LDAP::LDAP_SCOPE_SUBTREE,"(&(name=*)
(objectCategory=person))",
['name','ipPhone']) do |user| - puts "#{user['name']} #{user['ipPhone']}"
- end
- end
- require 'net/ldap'
- ldap = Net::LDAP.new :host =>
server_ip_address, - :port => 389,
- :auth => {
- :method => :simple,
- :username =>"cn=manager,dc=example,dc=com",
- :password => "opensesame"
- }
- filter = Net::LDAP::Filter.eq(
"cn", "George*" ) - treebase = "dc=example,dc=com"
- ldap.search( :base => treebase,
:filter => filter )do |entry| - puts "DN: #{entry.dn}"
- entry.each do |attribute, values|
- puts " #{attribute}:"
- values.each do |value|
- puts " --->#{value}"
- end
- end
- end
- p ldap.get_operation_result
希望以上介紹的這些Ruby連接到LDAP的方法能夠幫助大家。
本文題目:Ruby連接到LDAP技巧分享
網(wǎng)頁地址:http://fisionsoft.com.cn/article/djjcjph.html


咨詢
建站咨詢
