Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Only use lpad in production
  • Loading branch information
Merlin Buczek committed May 3, 2019
1 parent e0f6cfe commit 50869c3
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 45 deletions.
60 changes: 15 additions & 45 deletions config/settings/base.py
Expand Up @@ -3,8 +3,6 @@
"""

import environ
import ldap
from django_auth_ldap.config import LDAPSearch, GroupOfNamesType

from django.utils.translation import gettext_lazy as _

Expand Down Expand Up @@ -82,36 +80,8 @@
# AUTHENTICATION
# ------------------------------------------------------------------------------
AUTHENTICATION_BACKENDS = [
'django_auth_ldap.backend.LDAPBackend',
# 'django.contrib.auth.backends.ModelBackend',
'django.contrib.auth.backends.ModelBackend',
]

AUTH_LDAP_SERVER_URI = "ldap://127.0.0.1:10389/"

AUTH_LDAP_BIND_DN = ""
AUTH_LDAP_BIND_PASSWORD = ""
AUTH_LDAP_USER_SEARCH = LDAPSearch(
"ou=users,dc=example,dc=com", ldap.SCOPE_SUBTREE, "(uid=%(user)s)")

AUTH_LDAP_FIND_GROUP_PERMS = True
AUTH_LDAP_GROUP_SEARCH = LDAPSearch(
'ou=groups,dc=example,dc=com',
ldap.SCOPE_SUBTREE,
'(objectClass=groupOfNames)',
)
AUTH_LDAP_GROUP_TYPE = GroupOfNamesType(name_attr='cn')

AUTH_LDAP_USER_ATTR_MAP = {
'first_name': 'givenName',
'last_name': 'sn',
'email': 'mail',
}

AUTH_LDAP_USER_FLAGS_BY_GROUP = {
'is_staff': 'cn=staff,ou=groups,dc=example,dc=com',
'is_superuser': 'cn=superuser,ou=groups,dc=example,dc=com',
}

# AUTH_USER_MODEL = 'users.User'
# LOGIN_REDIRECT_URL = 'users:redirect'
# LOGIN_URL = 'account_login'
Expand All @@ -124,20 +94,20 @@
'django.contrib.auth.hashers.BCryptSHA256PasswordHasher',
'django.contrib.auth.hashers.BCryptPasswordHasher',
]
# AUTH_PASSWORD_VALIDATORS = [
# {
# 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
# },
# {
# 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
# },
# {
# 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
# },
# {
# 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
# },
# ]
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]

# MIDDLEWARE
# ------------------------------------------------------------------------------
Expand Down
35 changes: 35 additions & 0 deletions config/settings/production.py
@@ -1,3 +1,6 @@
import ldap
from django_auth_ldap.config import LDAPSearch, GroupOfNamesType

from .base import * # noqa
from .base import env

Expand Down Expand Up @@ -29,6 +32,38 @@
}
}

# AUTHENTICATION
AUTHENTICATION_BACKENDS = [
'django_auth_ldap.backend.LDAPBackend',
# 'django.contrib.auth.backends.ModelBackend',
]

AUTH_LDAP_SERVER_URI = "ldap://127.0.0.1:10389/"

AUTH_LDAP_BIND_DN = ""
AUTH_LDAP_BIND_PASSWORD = ""
AUTH_LDAP_USER_SEARCH = LDAPSearch(
"ou=users,dc=example,dc=com", ldap.SCOPE_SUBTREE, "(uid=%(user)s)")

AUTH_LDAP_FIND_GROUP_PERMS = True
AUTH_LDAP_GROUP_SEARCH = LDAPSearch(
'ou=groups,dc=example,dc=com',
ldap.SCOPE_SUBTREE,
'(objectClass=groupOfNames)',
)
AUTH_LDAP_GROUP_TYPE = GroupOfNamesType(name_attr='cn')

AUTH_LDAP_USER_ATTR_MAP = {
'first_name': 'givenName',
'last_name': 'sn',
'email': 'mail',
}

AUTH_LDAP_USER_FLAGS_BY_GROUP = {
'is_staff': 'cn=staff,ou=groups,dc=example,dc=com',
'is_superuser': 'cn=superuser,ou=groups,dc=example,dc=com',
}

# SECURITY
# ------------------------------------------------------------------------------
# https://docs.djangoproject.com/en/dev/ref/settings/#secure-proxy-ssl-header
Expand Down

0 comments on commit 50869c3

Please sign in to comment.