我们在实际编写Ruby语言代码时,在实现Ruby连接到LDAP的情况下,通常都可以使用到三种方法。在这里我们将会学到其中的两种。#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技巧分享
当前URL:http://www.csdahua.cn/qtweb/news7/444407.html
网站建设、网络推广公司-快上网,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等
广告
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源:
快上网