Created
July 26, 2016 07:34
-
-
Save gjbagrowski/8d8293f3e3c3b2baa08fb20cfd47f771 to your computer and use it in GitHub Desktop.
django-auth-ldap + ldap.forumsys.com
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logging | |
logger = logging.getLogger('django_auth_ldap') | |
logger.addHandler(logging.StreamHandler()) | |
logger.setLevel(logging.DEBUG) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import unicode_literals, absolute_import, print_function | |
# import this file in your settings module | |
AUTHENTICATION_BACKENDS = ( | |
'django_auth_ldap.backend.LDAPBackend', | |
'django.contrib.auth.backends.ModelBackend', | |
) | |
AUTH_LDAP_SERVER_URI = "ldap://ldap.forumsys.com" | |
AUTH_LDAP_USER_DN_TEMPLATE = "uid=%(user)s,dc=example,dc=com" | |
AUTH_LDAP_USER_ATTR_MAP = { | |
"last_name": "sn", | |
"email": "mail", | |
} | |
AUTH_LDAP_ALWAYS_UPDATE_USER = True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import unicode_literals, absolute_import, print_function | |
from django_auth_ldap.backend import populate_user | |
from django.dispatch import receiver | |
@receiver(populate_user) | |
def populate_user_from_ldap( | |
sender, signal, user=None, ldap_user=None, **kwargs): | |
try: | |
user.first_name = ldap_user.attrs['cn'][0].split()[0] | |
except (KeyError, IndexError): | |
pass | |
user.is_superuser = True | |
user.is_active = True | |
user.is_staff = True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment