Skip to content

Move LDAPSetting to the config module #289

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 7 additions & 54 deletions django_auth_ldap/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,13 @@
from django.core.cache import cache
from django.core.exceptions import ImproperlyConfigured, ObjectDoesNotExist

from .config import ConfigurationWarning, LDAPGroupQuery, LDAPSearch, _LDAPConfig
from .config import (
ConfigurationWarning,
LDAPGroupQuery,
LDAPSearch,
LDAPSettings,
_LDAPConfig,
)

logger = _LDAPConfig.get_logger()

Expand Down Expand Up @@ -973,59 +979,6 @@ def _cache_key(self, attr_name):
)


class LDAPSettings:
"""
This is a simple class to take the place of the global settings object. An
instance will contain all of our settings as attributes, with default values
if they are not specified by the configuration.
"""

_prefix = "AUTH_LDAP_"

defaults = {
"ALWAYS_UPDATE_USER": True,
"AUTHORIZE_ALL_USERS": False,
"BIND_AS_AUTHENTICATING_USER": False,
"BIND_DN": "",
"BIND_PASSWORD": "",
"CONNECTION_OPTIONS": {},
"DENY_GROUP": None,
"FIND_GROUP_PERMS": False,
"CACHE_TIMEOUT": 0,
"GROUP_SEARCH": None,
"GROUP_TYPE": None,
"MIRROR_GROUPS": None,
"MIRROR_GROUPS_EXCEPT": None,
"PERMIT_EMPTY_PASSWORD": False,
"REQUIRE_GROUP": None,
"NO_NEW_USERS": False,
"SERVER_URI": "ldap://localhost",
"START_TLS": False,
"USER_QUERY_FIELD": None,
"USER_ATTRLIST": None,
"USER_ATTR_MAP": {},
"USER_DN_TEMPLATE": None,
"USER_FLAGS_BY_GROUP": {},
"USER_SEARCH": None,
}

def __init__(self, prefix="AUTH_LDAP_", defaults={}):
"""
Loads our settings from django.conf.settings, applying defaults for any
that are omitted.
"""
self._prefix = prefix

defaults = dict(self.defaults, **defaults)

for name, default in defaults.items():
value = getattr(django.conf.settings, prefix + name, default)
setattr(self, name, value)

def _name(self, suffix):
return self._prefix + suffix


def valid_cache_key(key):
"""
Sanitizes a cache key for memcached.
Expand Down
54 changes: 54 additions & 0 deletions django_auth_ldap/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,67 @@

import ldap
import ldap.filter
from django.conf import settings
from django.utils.tree import Node


class ConfigurationWarning(UserWarning):
pass


class LDAPSettings:
"""
This is a simple class to take the place of the global settings object. An
instance will contain all of our settings as attributes, with default values
if they are not specified by the configuration.
"""

_prefix = "AUTH_LDAP_"

defaults = {
"ALWAYS_UPDATE_USER": True,
"AUTHORIZE_ALL_USERS": False,
"BIND_AS_AUTHENTICATING_USER": False,
"BIND_DN": "",
"BIND_PASSWORD": "",
"CONNECTION_OPTIONS": {},
"DENY_GROUP": None,
"FIND_GROUP_PERMS": False,
"CACHE_TIMEOUT": 0,
"GROUP_SEARCH": None,
"GROUP_TYPE": None,
"MIRROR_GROUPS": None,
"MIRROR_GROUPS_EXCEPT": None,
"PERMIT_EMPTY_PASSWORD": False,
"REQUIRE_GROUP": None,
"NO_NEW_USERS": False,
"SERVER_URI": "ldap://localhost",
"START_TLS": False,
"USER_QUERY_FIELD": None,
"USER_ATTRLIST": None,
"USER_ATTR_MAP": {},
"USER_DN_TEMPLATE": None,
"USER_FLAGS_BY_GROUP": {},
"USER_SEARCH": None,
}

def __init__(self, prefix="AUTH_LDAP_", defaults={}):
"""
Loads our settings from django.conf.settings, applying defaults for any
that are omitted.
"""
self._prefix = prefix

defaults = dict(self.defaults, **defaults)

for name, default in defaults.items():
value = getattr(settings, prefix + name, default)
setattr(self, name, value)

def _name(self, suffix):
return self._prefix + suffix


class _LDAPConfig:
"""
A private class that loads and caches some global objects.
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy