我有一个工作ldap搜索查询
ldapsearch -H ldaps://ldap.google.com -b dc=pangeare,dc=com '(memberOf=cn=pcore_readonly,ou=Groups,dc=pangeare,dc=com)'
我想知道如何在ruby net-ldap中创建相应的过滤器:
treebase="dc=pangeare,dc=com"
filter = Net::LDAP::Filter.XXXXXXXXXX
ldap.search(:base => treebase, :filter=> filter, :return_result => true) do |entry|
entry.each do |attr,values|
puts "DN: #{entry.dn}"
Net::LDAP::Filter#eq
应该是你所寻找的
require 'net/ldap'
host = 'ldap.google.com'
port = 636
auth = {
:method => :simple, # or :simple_tls ? (I don't know Google's LDAP)
:username => 'uid=username,dc=xxx,dc=xxx',
:password => 'password'
}
ldap = Net::LDAP.new( :host => host, :port => port, :auth => auth)
base = 'dc=pangeare,dc=com'
filter = Net::LDAP::Filter.eq('memberOf','cn=pcore_readonly,ou=Groups,dc=pangeare,dc=com')
ldap.search(:base => base, :filter => filter) do |entry|
p entry
end
或者直接用Net::LDAP::Filter#construct
:
filter = Net::LDAP::Filter.construct('(memberOf=cn=pcore_readonly,ou=Groups,dc=pangeare,dc=com)')