LDAP 和用户组(需要 ldap-group)
我正在开发一个应用程序,我想将此应用程序与我们的 LDAP 一起使用 并按组过滤用户。我在 APACHE 中有这段代码:
AuthLDAPURL ldap://localhost/ou=users,dc=domain,dc=com?uid
AuthLDAPGroupAttribute memberUid
AuthLDAPGroupAttributeIsDN off
AuthzLDAPAuthoritative on
Require ldap-group cn=developer,cn=testers,cn=groups,dc=domain,dc=com
它工作正常。只有开发人员和测试人员列表中的人员才能获得 在这个区域内。我试图在 Web2py 中做同样的事情,但我不能 从组中创建一个过滤器
我有此代码并且在没有组的情况下工作正常:
auth.settings.login_methods=[ldap_auth(mode='uid_r',server='localhost',port='389',
base_dn='ou=users,dc=domain,dc=com', filterstr='objectClass=*')]
我不知道如何使用:在 web2py 中需要 ldap-group。
有人可以帮助我吗?
预先非常感谢
I am developing a APP and I would like to use this APP with our LDAP
and filter the users by groups. I have this code in APACHE:
AuthLDAPURL ldap://localhost/ou=users,dc=domain,dc=com?uid
AuthLDAPGroupAttribute memberUid
AuthLDAPGroupAttributeIsDN off
AuthzLDAPAuthoritative on
Require ldap-group cn=developer,cn=testers,cn=groups,dc=domain,dc=com
It works fine. Only people from the list developer and tester can get
inside this area. I am trying to do the same in Web2py, but I can not
make a filter from the groups
I have this code and is working ok without groups:
auth.settings.login_methods=[ldap_auth(mode='uid_r',server='localhost',port='389',
base_dn='ou=users,dc=domain,dc=com', filterstr='objectClass=*')]
I not sure how to use: Require ldap-group in web2py.
Anyone can help me?
In advance many thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我自己也一直在努力解决这个问题。我认为解决方案是通过执行一些 LDAP 查询从 LDAP 导入组。
这种方法的缺点是,它要求您(1)在 use FIRST 登录时将组插入 web2py auth_group 表中。(2)如果组倾向于更改,则需要对其进行维护。这可以通过 cron 作业或手动完成。
您可以像这样查明用户之前是否登录过:
这是 LDAP 查询的一些示例代码 - 这个代码基于查找用户信息(我不确定 LDAP 如何组织组 - 我将编写代码在一两周内提取组):
导入LDAP
from ldap.filter import filter_format as ff
您可以在此处获取有关 python ldap 的更多信息:
http://www.python-ldap.org/docs.shtml
(这个有与查询组相关的代码示例)
http://www.ibm.com/developerworks/aix/library/au- ldap_crud/
另外,不要忘记使用filter_format(上面导入为ff),如果允许任何用户输入,它将转义您的ldap查询,防止LDAP注入代码。出于我的目的,我正在制作一个可公开访问的表单,用于搜索人员的 LDAP 条目。
这是一篇关于将 ActiveDirectory 组镜像到 LDAP 组的帖子。我发布这个是因为虽然它做了相反的事情,但其中一些仍然有用,特别是用于从 LDAP 获取组的过滤器,因为无论是读取还是写入都是相同的,并且它使用 python-ldap:
http://oxpedia.org/wiki/index.php?title=Mirorring_Active_Directory_user_acconts_in_LDAP
如果您的 LDAP 组没有太大变化,您可以创建一个执行以下操作的脚本:
然后根据需要运行脚本。我喜欢在运行这样的 ETL 脚本时删除一些内容,因为这样您就可以重新开始,并且不会重复内容,也不会在内容已经存在并违反数据库约束时遇到错误。
I've been wrestling with this myself. I think the solution is to import the groups from LDAP by doing some LDAP queries.
The bad part with this approach is that it requires you to (1) insert groups into web2py auth_group tables when the use FIRST logs in. (2) It would require maintenance of the groups if they tend to change. This could be done with a cron job or manually.
You can find out if the user has logged in before like this:
Here is some example code for an LDAP query - this one is based off of just looking up user info (I'm not sure how LDAP organizes groups - I will be writing code to extract groups in a week or two):
import ldap
from ldap.filter import filter_format as ff
You can get more info on python's ldap here:
http://www.python-ldap.org/docs.shtml
(this one has code examples related to querying groups)
http://www.ibm.com/developerworks/aix/library/au-ldap_crud/
Also, DON'T forget to use filter_format (imported as ff above), it will escape your ldap queries preventing LDAP injection if any user input is allowed to make it to the code. For my purposes, I was making a publicly accessible form that searched LDAP entries for people.
Here is a posting on mirroring ActiveDirectory Groups into LDAP groups. I'm posting this because while it does the opposite, some of it is still useful, particularly the filter for getting groups from LDAP since that's the same whether reading or writing, and it uses python-ldap:
http://oxpedia.org/wiki/index.php?title=Mirorring_Active_Directory_user_acconts_in_LDAP
If your ldap groups don't change much, you could create a script that does the following:
Then just run the script on an as-needed basis. I like to delete things when running ETL scripts like this because then you start fresh and don't duplicate things or run into errors when things already exist and violate DB constraints.