From ec6a6cc922b62a3e7c727a77bdad27b2f31b3b3d Mon Sep 17 00:00:00 2001 From: Nikolai Kristiansen Date: Sat, 8 Oct 2011 16:16:09 +0200 Subject: [PATCH] LDAP login. README --- README | 4 ++++ settings-sample.py | 46 ++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 README diff --git a/README b/README new file mode 100644 index 0000000..b58757e --- /dev/null +++ b/README @@ -0,0 +1,4 @@ +Requirements +============ + - django 1.3 + - (django-auth-ldap) diff --git a/settings-sample.py b/settings-sample.py index f8e5734..d32925a 100644 --- a/settings-sample.py +++ b/settings-sample.py @@ -16,7 +16,7 @@ DATABASES = { 'NAME': 'snurr', # Or path to database file if using sqlite3. 'USER': 'snurr', # Not used with sqlite3. 'PASSWORD': '', # Not used with sqlite3. - 'HOST': '', # Set to empty string for localhost. Not used with sqlite3. + 'HOST': 'snes.neuf.no', # Set to empty string for localhost. Not used with sqlite3. 'PORT': '', # Set to empty string for default. Not used with sqlite3. } } @@ -32,7 +32,7 @@ TIME_ZONE = 'Europe/Oslo' # Language code for this installation. All choices can be found here: # http://www.i18nguy.com/unicode/language-identifiers.html -LANGUAGE_CODE = 'en-us' +LANGUAGE_CODE = 'no-nb' SITE_ID = 1 @@ -117,6 +117,48 @@ INSTALLED_APPS = ( 'django.contrib.admin', 'main', ) +AUTHENTICATION_BACKENDS = ( + 'django_auth_ldap.backend.LDAPBackend', + 'django.contrib.auth.backends.ModelBackend', +) +# LDAP server URI and BIND_DN +AUTH_LDAP_SERVER_URI = 'ldap://pacman.neuf.no' +AUTH_LDAP_BIND_DN = 'uid=admin,ou=People,dc=neuf,dc=no' +AUTH_LDAP_BIND_PASSWORD = '' + +import ldap +from django_auth_ldap.config import LDAPSearch, PosixGroupType +# basic user auth +AUTH_LDAP_USER_SEARCH = LDAPSearch("ou=People,dc=neuf,dc=no", + ldap.SCOPE_ONELEVEL, "(uid=%(user)s)") +AUTH_LDAP_USER_DN_TEMPLATE = "uid=%(user)s,ou=People,dc=neuf,dc=no" +# groups +AUTH_LDAP_GROUP_SEARCH = LDAPSearch("ou=Groups,dc=neuf,dc=no", + ldap.SCOPE_ONELEVEL, "(objectClass=posixGroup)" +) +AUTH_LDAP_GROUP_TYPE = PosixGroupType() + +# Mirror groups on each auth +AUTH_LDAP_MIRROR_GROUPS = True + +AUTH_LDAP_USER_FLAGS_BY_GROUP = { + "is_active": "cn=dns-alle,ou=Groups,dc=neuf,dc=no", + "is_staff": "cn=edb,ou=Groups,dc=neuf,dc=no", + "is_superuser": "cn=edbadmin,ou=Groups,dc=neuf,dc=no" +} +AUTH_LDAP_USER_ATTR_MAP = { + "first_name": "givenName", + "last_name": "sn", + "email": "mail", +} + +# Allways update the django user object on authentication. +AUTH_LDAP_ALWAYS_UPDATE_USER = True + +import logging +logger = logging.getLogger('django_auth_ldap') +logger.addHandler(logging.StreamHandler()) +logger.setLevel(logging.DEBUG) # A sample logging configuration. The only tangible logging # performed by this configuration is to send an email to