Skip to content

Instantly share code, notes, and snippets.

@khanzf
Created April 19, 2016 20:56
Show Gist options
  • Save khanzf/6dedd41ef5cb43cf0afa8c10d86a9eee to your computer and use it in GitHub Desktop.
Save khanzf/6dedd41ef5cb43cf0afa8c10d86a9eee to your computer and use it in GitHub Desktop.
AUTHENTICATION_BACKENDS = (
'django_auth_ldap.backend.LDAPBackend',
'django.contrib.auth.backends.ModelBackend',
)
import ldap
from django_auth_ldap.config import LDAPSearch, NestedActiveDirectoryGroupType
# Binding and connection options
AUTH_LDAP_SERVER_URI = "ldap://192.168.1.13"
AUTH_LDAP_BIND_DN = "CN=testbind,CN=Users,DC=testad,DC=offmail,DC=us" # Belongs to the username
AUTH_LDAP_BIND_PASSWORD = "MYPASSWORD" # Password
AUTH_LDAP_CONNECTION_OPTIONS = {
ldap.OPT_DEBUG_LEVEL: 1,
ldap.OPT_REFERRALS: 0,
}
# User and group search objects and types
AUTH_LDAP_USER_SEARCH = LDAPSearch("CN=Users,DC=testad,DC=offmail,DC=us",
ldap.SCOPE_SUBTREE, "(sAMAccountName=%(user)s)")
AUTH_LDAP_GROUP_SEARCH = LDAPSearch("CN=Groups,DC=testad,DC=offmail,DC=us",
ldap.SCOPE_SUBTREE, "(objectClass=group)")
AUTH_LDAP_GROUP_TYPE = NestedActiveDirectoryGroupType()
# Cache Settings
AUTH_LDAP_CACHE_GROUPS = True
AUTH_LDAP_GROUP_CACHE_TIMEOUT = 300
# What to do once the user is authenticated
AUTH_LDAP_USER_ATTR_MAP = {
"first_name": "givenName",
"last_name": "sn",
"email": "userPrincipalName"
}
AUTH_LDAP_USER_FLAGS_BY_GROUP = {
"is_staff": ["CN=securityplan_django,DC=testad,DC=offmail,DC=us",
"CN=securityplan_django,DC=testad,DC=offmail,DC=us"]
}
AUTH_LDAP_FIND_GROUP_PERMS = True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment