django python3 ldap_使用django-python3-ldap查找安全组的用户

Very new to LDAP and AD. I'm using django-python3-ldap to authenticate users of my django app.

We want to make it so that only a subset of our users can access our django app, so yesterday they added the security group 'MyAppGroup.' Only problem is, I don't seem able to add this to the search base. User lookup always fails.

Working search base (returns ALL users):

"ou=Basic Users, ou=BIGAPP Users,dc=subd,dc=domain,dc=com"

When I asked, they said that MyAppGroup was a security group, and that "Basic Users" and "BIGAPP Users" were "AD Members."

dsquery group -name "MyAppGroup"

returns:

CN=MyAppGroup,OU=BIGAPP Groups,dc=subd,dc=domain,dc=com

This result does not work as the search base.

Do I need to add a custom search filter for this to work? Any help is appreciated.

EDIT: Adding (&(memberOf=BIGAPPS Group)(memberOf=cn=MyAppGroup)) to search filters now returns "LDAP user attributes empty"

EDIT 2:

Running the command dsget group "CN=MyAppGroup,OU=BIGAPP Groups,dc=subd,dc=domain,dc=com" -members -expand returns a list of group members:

"CN=User McLastname,OU=Basic Users,OU=BIGAPP Groups,dc=subd,dc=domain,dc=com"

"CN=User2 o'Lastname,OU=Basic Users,OU=BIGAPP Groups,dc=subd,dc=domain,dc=com",..etc

So I know the group exists. I feel like I'm missing some small piece to make this work.

EDIT 3:

settings.py

LDAP_AUTH_FORMAT_USERNAME = "django_python3_ldap.utils.format_username_active_directory"

LDAP_AUTH_USE_TLS = True

LDAP_AUTH_ACTIVE_DIRECTORY_DOMAIN = "SUBD"

LDAP_AUTH_SEARCH_BASE="DC=subd,DC=domain,DC=com"

LDAP_AUTH_OBJECT_CLASS="user"

LDAP_AUTH_USER_FIELDS = {

"username": "sAMAccountName,

"first_name": "givenName",

"last_name": "sn",

"email": "mail",

}

LDAP_AUTH_FORMAT_SEARCH_FILTERS="myapp.searchfilter.myapp_search_filters"

Search filters

def myapp_search_filters(ldap_fields):

search_filters = format_search_filters(ldap_fields)

search_filters.append("(&(memberOf=cn=MyAppGroup,OU=BIGAPP_Group,DC=subd,DC=domain,dc=com))")

解决方案

Use the fully qualified DN of the group in the memberOf filter: (&(memberOf=CN=MyAppGroup,OU=BIGAPP Groups,dc=subd,dc=domain,dc=com))

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值