ActiveLdap能够在OU之间创建多个Person和OU有很多组之间的关系

时间:2013-09-27 21:08:26

标签: ruby ldap

有没有办法用这种类型的方案配置ActiveLdap。

* dc=example,dc=com
|+ o=domain1.com,dc=example,dc=com
  \ 
   |+ ou=People,o=domain1.com,dc=example,dc=com
    \
     |- cn=user1,ou=People,o=domain1.com,dc=example,dc=com
     |- cn=user2,ou=People,o=domain1.com,dc=example,dc=com
     |- ...
   |+ ou=Groups,
    \
     |- cn=group1,ou=Groups,o=domain1.com,dc=example,dc=com
     |- cn=group2,ou=Groups,o=domain1.com,dc=example,dc=com
     |- ...
|- o=otherdomain.com,dc=example,dc=com
  \ 
   |+ ou=People,o=otherdomain.com,dc=example,dc=com
    \
     |- cn=user1,ou=People,o=otherdomain.com,dc=example,dc=com
     |- cn=user2,ou=People,o=otherdomain.com,dc=example,dc=com
     |- ...
   |+ ou=Groups,
    \
     |- cn=group1,ou=Groups,o=otherdomain.com,dc=example,dc=com
     |- cn=group2,ou=Groups,o=otherdomain.com,dc=example,dc=com
     |- ...

我尝试使用这样的东西:

class Domain < ActiveLdap::Base
  ldap_mapping :dn_attribute => 'o',
               :prefix => '',
               :classes => %w(inetdomainauthinfo top maildomain organization)
end

但我无法弄清楚如何正确创建Person.rb。

1 个答案:

答案 0 :(得分:0)

找到答案,谢谢Kouhei。

class Domain < ActiveLdap::Base
  ldap_mapping :dn_attribute => 'o',
               :prefix => '',
               :classes => %w(inetdomainauthinfo top maildomain organization)

  def user(uid)
    User.find(uid, :prefix => "ou=People,o=#{o}")
  end

  def users
    User.all(:prefix => "ou=People,o=#{o}")
  end

  def group(cn)
    Group.find(cn, :prefix => "ou=Groups,o=#{o}")
  end

  def groups
    Group.all(:prefix => "ou=Groups,o=#{o}")
  end

end


class Group < ActiveLdap::Base
  ldap_mapping :dn_attribute => 'cn',
               :prefix => '',
               :classes => %w(inetlocalmailrecipient inetmailgroupmanagement
top inetmailgroup groupofuniquenames)

  def domain
    Domain.find(dn.rdns[2]['o'])
  end
end



class User < ActiveLdap::Base
  ldap_mapping :dn_attribute => 'uid',
               :prefix => '',
               :classes => %w(top userpresenceprofile inetadmin
organizationalperson person inetuser inetlocalmailrecipient inetorgperson
inetsubscriber inetmailuser)

  def domain
    Domain.find(dn.rdns[2]['o'])
  end
end