Lucterios2 / django_auth_ldap3_ad

Simple LDAP/AD auth module for django
https://pypi.python.org/pypi/django-auth-ldap3-ad
GNU General Public License v3.0
45 stars 25 forks source link

How to import users and groups #27

Open nova-systems opened 6 years ago

nova-systems commented 6 years ago

I have a working AD server,

your module works and I can log into admin area of django with my administrators group member.

how can I Import all users and groups to django ? my config

Active Directory

LDAP_SERVERS = [ { 'host': '10.172.90.3', 'port': 389, 'use_ssl': False, }, ] LDAP_ENGINE = "AD" LDAP_BIND_USER = "cn=intranet,ou=EFEKTUM,dc=ad,dc=efektum,dc=pl" LDAP_BIND_PASSWORD = "" LDAP_SEARCH_BASE = "dc=ad,dc=efektum,dc=pl" LDAP_USER_SEARCH_FILTER = "(&(|(userPrincipalName={0})(sAMAccountName={0}))(objectClass=user))"

DAP_USE_LDAP_GROUPS = True LDAP_GROUPS_SEARCH_BASE = "dc=ad,dc=efektum,dc=pl" LDAP_GROUPS_SEARCH_FILTER = "(&(objectClass=group))" LDAP_GROUP_MEMBER_ATTRIBUTE = "member" LDAP_SUPERUSER_GROUPS = ["CN=Administratorzy,DC=ad,DC=efektum,DC=pl", ] LDAP_STAFF_GROUPS = ["CN=IT,OU=PROJEKTY,OU=EFEKTUM,DC=ad,DC=efektum,DC=pl", ] LDAP_GROUPS_MAP = { 'DPD': "CN=DPD,OU=PROJEKTY,OU=EFEKTUM,DC=ad,DC=efektum,DC=pl", } LDAP_ATTRIBUTES_MAP = { 'username': 'sAMAccountName', 'first_name': 'givenName', 'last_name': 'sn', 'email': 'mail', }

mikedici commented 6 years ago

I have a question about LDAP_GROUPS_MAP = { 'DPD': "CN=DPD,OU=PROJEKTY,OU=EFEKTUM,DC=ad,DC=efektum,DC=pl", } you posted this as an answer to my issue and the AD login for regular users works but using the default django admin does not work. I suspect the issue is this line. I see you set the key to this dict as 'DPD', I imagine that you have something refering to 'DPD' in another file to set the group name?

povtux commented 4 years ago

Hi, Actually, the module does not import users and groups. The binding LDAP_GROUP_MAP enables you to make django groups match ldap groups. This way, you can limit the number of groups in Django to the minimum and give them the needed rigths without having all the groups of your AD. So you need to create groups you need and refer to the group name as the key in LDAP_GROUP_MAP. regards.