[Python-modules-commits] [django-auth-ldap] 03/07: New upstream version 1.2.14+dfsg

Michael Fladischer fladi at moszumanska.debian.org
Sun Jul 30 17:42:30 UTC 2017


This is an automated email from the git hooks/post-receive script.

fladi pushed a commit to branch debian/master
in repository django-auth-ldap.

commit 00e11fe19821894e05f59645a8b5424a5179c23b
Author: Michael Fladischer <FladischerMichael at fladi.at>
Date:   Fri Jul 28 11:35:34 2017 +0200

    New upstream version 1.2.14+dfsg
---
 PKG-INFO                           |   6 +++---
 README                             |   4 ++--
 django_auth_ldap.egg-info/PKG-INFO |   6 +++---
 django_auth_ldap/__init__.py       |   2 +-
 django_auth_ldap/backend.py        |  39 ++++++++++++++++++++++++++++++-------
 django_auth_ldap/tests.py          |   6 ++++++
 docs/source/.conf.py.swp           | Bin 16384 -> 16384 bytes
 docs/source/conf.py                |   2 +-
 setup.py                           |   2 +-
 9 files changed, 49 insertions(+), 18 deletions(-)

diff --git a/PKG-INFO b/PKG-INFO
index 30b644a..e94b291 100644
--- a/PKG-INFO
+++ b/PKG-INFO
@@ -1,6 +1,6 @@
 Metadata-Version: 1.1
 Name: django-auth-ldap
-Version: 1.2.13
+Version: 1.2.14
 Summary: Django LDAP authentication backend
 Home-page: http://bitbucket.org/psagers/django-auth-ldap/
 Author: Peter Sagerson
@@ -11,8 +11,8 @@ Description: This is a Django authentication backend that authenticates against
         but there are many rich configuration options for working with users, groups,
         and permissions.
         
-        This version is supported on Python 2.6, 2.7, 3.3, 3.4, 3.5, and 3.6; and Django >= 1.3.
-        Under Python 2, it requires `python-ldap
+        This version is supported on Python 2.7, 3.3, 3.4, 3.5, and 3.6; and Django >=
+        1.5. Under Python 2, it requires `python-ldap
         <https://pypi.python.org/pypi/python-ldap>`_ >= 2.0; under Python 3, it uses
         `pyldap <https://pypi.python.org/pypi/pyldap>`_.
         
diff --git a/README b/README
index 8bd1948..75d9890 100644
--- a/README
+++ b/README
@@ -3,8 +3,8 @@ service. Configuration can be as simple as a single distinguished name template,
 but there are many rich configuration options for working with users, groups,
 and permissions.
 
-This version is supported on Python 2.6, 2.7, 3.3, 3.4, 3.5, and 3.6; and Django >= 1.3.
-Under Python 2, it requires `python-ldap
+This version is supported on Python 2.7, 3.3, 3.4, 3.5, and 3.6; and Django >=
+1.5. Under Python 2, it requires `python-ldap
 <https://pypi.python.org/pypi/python-ldap>`_ >= 2.0; under Python 3, it uses
 `pyldap <https://pypi.python.org/pypi/pyldap>`_.
 
diff --git a/django_auth_ldap.egg-info/PKG-INFO b/django_auth_ldap.egg-info/PKG-INFO
index 30b644a..e94b291 100644
--- a/django_auth_ldap.egg-info/PKG-INFO
+++ b/django_auth_ldap.egg-info/PKG-INFO
@@ -1,6 +1,6 @@
 Metadata-Version: 1.1
 Name: django-auth-ldap
-Version: 1.2.13
+Version: 1.2.14
 Summary: Django LDAP authentication backend
 Home-page: http://bitbucket.org/psagers/django-auth-ldap/
 Author: Peter Sagerson
@@ -11,8 +11,8 @@ Description: This is a Django authentication backend that authenticates against
         but there are many rich configuration options for working with users, groups,
         and permissions.
         
-        This version is supported on Python 2.6, 2.7, 3.3, 3.4, 3.5, and 3.6; and Django >= 1.3.
-        Under Python 2, it requires `python-ldap
+        This version is supported on Python 2.7, 3.3, 3.4, 3.5, and 3.6; and Django >=
+        1.5. Under Python 2, it requires `python-ldap
         <https://pypi.python.org/pypi/python-ldap>`_ >= 2.0; under Python 3, it uses
         `pyldap <https://pypi.python.org/pypi/pyldap>`_.
         
diff --git a/django_auth_ldap/__init__.py b/django_auth_ldap/__init__.py
index b426daa..a3c7552 100644
--- a/django_auth_ldap/__init__.py
+++ b/django_auth_ldap/__init__.py
@@ -1,2 +1,2 @@
-version = (1, 2, 13)
+version = (1, 2, 14)
 version_string = '.'.join(map(str, version))
diff --git a/django_auth_ldap/backend.py b/django_auth_ldap/backend.py
index 70f2e76..35806a6 100644
--- a/django_auth_ldap/backend.py
+++ b/django_auth_ldap/backend.py
@@ -472,14 +472,21 @@ class _LDAPUser(object):
 
     def _load_user_dn(self):
         """
-        Populates self._user_dn with the distinguished name of our user. This
-        will either construct the DN from a template in
+        Populates self._user_dn with the distinguished name of our user.
+
+        This will either construct the DN from a template in
         AUTH_LDAP_USER_DN_TEMPLATE or connect to the server and search for it.
+        If we have to search, we'll cache the DN.
+
         """
         if self._using_simple_bind_mode():
-            self._construct_simple_user_dn()
+            self._user_dn = self._construct_simple_user_dn()
         else:
-            self._search_for_user_dn()
+            cache_key = 'django_auth_ldap.user_dn.{}'.format(self._username)
+            self._user_dn = cache_get_or_set(
+                cache, cache_key, self._search_for_user_dn,
+                self.settings.GROUP_CACHE_TIMEOUT
+            )
 
     def _using_simple_bind_mode(self):
         return (self.settings.USER_DN_TEMPLATE is not None)
@@ -488,7 +495,9 @@ class _LDAPUser(object):
         template = self.settings.USER_DN_TEMPLATE
         username = ldap.dn.escape_dn_chars(self._username)
 
-        self._user_dn = template % {'user': username}
+        user_dn = template % {'user': username}
+
+        return user_dn
 
     def _search_for_user_dn(self):
         """
@@ -500,8 +509,12 @@ class _LDAPUser(object):
             raise ImproperlyConfigured('AUTH_LDAP_USER_SEARCH must be an LDAPSearch instance.')
 
         results = search.execute(self.connection, {'user': self._username})
-        if results is not None and len(results) == 1:
-            (self._user_dn, self._user_attrs) = next(iter(results))
+        if (results is not None) and (len(results) == 1):
+            (user_dn, self._user_attrs) = next(iter(results))
+        else:
+            user_dn = None
+
+        return user_dn
 
     def _check_requirements(self):
         """
@@ -1021,3 +1034,15 @@ class LDAPSettings(object):
 
     def _name(self, suffix):
         return (self._prefix + suffix)
+
+
+def cache_get_or_set(cache, key, default, timeout=None):
+    """
+    Backport of Django 1.9's cache.get_or_set.
+    """
+    value = cache.get(key)
+    if value is None:
+        value = default() if callable(default) else default
+        cache.set(key, value, timeout)
+
+    return value
diff --git a/django_auth_ldap/tests.py b/django_auth_ldap/tests.py
index 6b877b5..f605432 100644
--- a/django_auth_ldap/tests.py
+++ b/django_auth_ldap/tests.py
@@ -39,6 +39,7 @@ except ImportError:
 import django
 from django.conf import settings
 from django.contrib.auth.models import User, Permission, Group
+from django.core.cache import cache
 from django.core.exceptions import ImproperlyConfigured
 import django.db.models.signals
 from django.test import TestCase
@@ -271,12 +272,17 @@ class LDAPTest(TestCase):
         warnings.filterwarnings(
             'ignore', message='.*?AUTH_PROFILE_MODULE', category=DeprecationWarning, module='django_auth_ldap'
         )
+        warnings.filterwarnings(
+            'ignore', category=UnicodeWarning, module='mockldap.ldapobject'
+        )
 
     @classmethod
     def tearDownClass(cls):
         del cls.mockldap
 
     def setUp(self):
+        cache.clear()
+
         self.mockldap.start()
         self.ldapobj = self.mockldap['ldap://localhost']
 
diff --git a/docs/source/.conf.py.swp b/docs/source/.conf.py.swp
index 6b50423..f606a28 100644
Binary files a/docs/source/.conf.py.swp and b/docs/source/.conf.py.swp differ
diff --git a/docs/source/conf.py b/docs/source/conf.py
index fd0d8bc..406ce1a 100644
--- a/docs/source/conf.py
+++ b/docs/source/conf.py
@@ -59,7 +59,7 @@ copyright = u'2009, Peter Sagerson'
 # The short X.Y version.
 version = '1.1'
 # The full version, including alpha/beta/rc tags.
-release = '1.2.13'
+release = '1.2.14'
 
 # The language for content autogenerated by Sphinx. Refer to documentation
 # for a list of supported languages.
diff --git a/setup.py b/setup.py
index 6397eff..6d06024 100644
--- a/setup.py
+++ b/setup.py
@@ -10,7 +10,7 @@ PY3 = (sys.version_info[0] == 3)
 
 setup(
     name="django-auth-ldap",
-    version="1.2.13",
+    version="1.2.14",
     description="Django LDAP authentication backend",
     long_description=open('README').read(),
     url="http://bitbucket.org/psagers/django-auth-ldap/",

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/django-auth-ldap.git



More information about the Python-modules-commits mailing list