README 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. This is a Django authentication backend that authenticates against an LDAP
  2. service. Configuration can be as simple as a single distinguished name
  3. template, but there are many rich configuration options for working with users,
  4. groups, and permissions.
  5. This version is tested on Python 2.6 to 2.7, Django >= 1.3, and python-ldap
  6. 2.4.13.
  7. Full documentation can be found at http://pythonhosted.org/django-auth-ldap/;
  8. following is an example configuration, just to whet your appetite::
  9. import ldap
  10. from django_auth_ldap.config import LDAPSearch, GroupOfNamesType
  11. # Baseline configuration.
  12. AUTH_LDAP_SERVER_URI = "ldap://ldap.example.com"
  13. AUTH_LDAP_BIND_DN = "cn=django-agent,dc=example,dc=com"
  14. AUTH_LDAP_BIND_PASSWORD = "phlebotinum"
  15. AUTH_LDAP_USER_SEARCH = LDAPSearch("ou=users,dc=example,dc=com",
  16. ldap.SCOPE_SUBTREE, "(uid=%(user)s)")
  17. # or perhaps:
  18. # AUTH_LDAP_USER_DN_TEMPLATE = "uid=%(user)s,ou=users,dc=example,dc=com"
  19. # Set up the basic group parameters.
  20. AUTH_LDAP_GROUP_SEARCH = LDAPSearch("ou=django,ou=groups,dc=example,dc=com",
  21. ldap.SCOPE_SUBTREE, "(objectClass=groupOfNames)"
  22. )
  23. AUTH_LDAP_GROUP_TYPE = GroupOfNamesType()
  24. # Simple group restrictions
  25. AUTH_LDAP_REQUIRE_GROUP = "cn=enabled,ou=django,ou=groups,dc=example,dc=com"
  26. AUTH_LDAP_DENY_GROUP = "cn=disabled,ou=django,ou=groups,dc=example,dc=com"
  27. # Populate the Django user from the LDAP directory.
  28. AUTH_LDAP_USER_ATTR_MAP = {
  29. "first_name": "givenName",
  30. "last_name": "sn",
  31. "email": "mail"
  32. }
  33. AUTH_LDAP_PROFILE_ATTR_MAP = {
  34. "employee_number": "employeeNumber"
  35. }
  36. AUTH_LDAP_USER_FLAGS_BY_GROUP = {
  37. "is_active": "cn=active,ou=django,ou=groups,dc=example,dc=com",
  38. "is_staff": "cn=staff,ou=django,ou=groups,dc=example,dc=com",
  39. "is_superuser": "cn=superuser,ou=django,ou=groups,dc=example,dc=com"
  40. }
  41. AUTH_LDAP_PROFILE_FLAGS_BY_GROUP = {
  42. "is_awesome": "cn=awesome,ou=django,ou=groups,dc=example,dc=com",
  43. }
  44. # Use LDAP group membership to calculate group permissions.
  45. AUTH_LDAP_FIND_GROUP_PERMS = True
  46. # Cache group memberships for an hour to minimize LDAP traffic
  47. AUTH_LDAP_CACHE_GROUPS = True
  48. AUTH_LDAP_GROUP_CACHE_TIMEOUT = 3600
  49. # Keep ModelBackend around for per-user permissions and maybe a local
  50. # superuser.
  51. AUTHENTICATION_BACKENDS = (
  52. 'django_auth_ldap.backend.LDAPBackend',
  53. 'django.contrib.auth.backends.ModelBackend',
  54. )