2012-07-20 41 views
0

我正在尝试使用ActiveLdap搜索具有特定属性值的用户,但它正在向服务器发送一些奇怪的查询。我有它设置如下:ActiveLdap根据属性查找用户

class Ldapuser < ActiveLdap::Base 
    ldap_mapping :dn_attribute => 'uid', 
       :prefix => 'ou=People', 
       :classes => ['top', 'inetOrgPerson'] 
end 

,然后尝试找同学与特定专业:

Ldapuser.all(
     :attribute => 'studentMajor', :value => 'CHEM', 
     :attribute => 'primaryAffiliation', :value => 'student', 
     :attribute => 'organizationalStatus', :value => 'active').each {|user| 
    # process the user... 
} 

当我运行它,它永远不会到达内部块哪里会处理用户,我必须杀死程序。 Tcpdump显示执行了三次搜索:

  • searchRequest(1)“”baseObject - 它给出了0个结果。
  • searchRequest(2)“cn = schema”baseObject - 它给出了115个结果。
  • searchRequest(3)“ou = people,dc = myedu,dc = edu”wholeSubtree - 这需要太长时间才会中断它。

我的期望是,它会做一个查询并迅速得到约20个结果,这是我得到使用命令行使用ldapsearch时:

ldapsearch -x '(&(studentMajor=CHEM)(primaryAffiliation=student) 
     (organizationalStatus=active))' 

回答

1

它不会从出现多个属性名称 - 值对由.all()识别的文档,它是find(:all,...)的同义词,并且您看到的行为同意。它似乎只搜索第一对,或者可能是任何一对:因此搜索时间很长。您需要使用:过滤器选项,从我可以快速收集的内容中进行选择。