Ticket #2550: patch_corrected.diff
File patch_corrected.diff, 4.3 KB (added by , 14 years ago) |
---|
-
docs/topics/auth.txt
1496 1496 1497 1497 The order of :setting:`AUTHENTICATION_BACKENDS` matters, so if the same 1498 1498 username and password is valid in multiple backends, Django will stop 1499 processing at the first positive match. 1499 processing at the first positive match.Also if a backend indicates that 1500 a user is not allowed by raising a :class:`~django.core.exceptions.PermissionDenied` Exception,django 1501 will stop there and will not check the backends that follow. 1500 1502 1501 1503 .. note:: 1502 1504 -
django/contrib/auth/__init__.py
1 1 import datetime 2 2 from warnings import warn 3 from django.core.exceptions import ImproperlyConfigured 3 from django.core.exceptions import ImproperlyConfigured,PermissionDenied 4 4 from django.utils.importlib import import_module 5 5 from django.contrib.auth.signals import user_logged_in, user_logged_out 6 6 … … 56 56 except TypeError: 57 57 # This backend doesn't accept these credentials as arguments. Try the next one. 58 58 continue 59 except PermissionDenied: 60 # This backend says to stop in our tracks - this user should not be allowed in at all. 61 return None 59 62 if user is None: 60 63 continue 61 64 # Annotate the user object with the path of the backend. -
django/contrib/auth/tests/auth_backends.py
3 3 from django.conf import settings 4 4 from django.contrib.auth.models import User, Group, Permission, AnonymousUser 5 5 from django.contrib.contenttypes.models import ContentType 6 from django.core.exceptions import ImproperlyConfigured 6 from django.core.exceptions import ImproperlyConfigured,PermissionDenied 7 from django.contrib.auth import authenticate 7 8 from django.test import TestCase 8 9 9 10 … … 354 355 self.assertEqual(self.user1.has_module_perms("app1"), False) 355 356 self.assertEqual(self.user1.has_module_perms("app2"), False) 356 357 358 class PermissionDeniedBackend(object): 359 """ 360 always raises PermissionDenied 361 """ 362 supports_object_permissions = False 363 supports_anonymous_user = False 364 365 def authenticate(self,username=None,password=None): 366 raise PermissionDenied 367 368 class PermissionDeniedBackendTest(TestCase): 369 """ 370 Tests that other backends are not checked once a backend raises PermissionDenied 371 """ 372 backend = 'django.contrib.auth.tests.auth_backends.PermissionDeniedBackend' 373 374 def setUp(self): 375 self.curr_auth = settings.AUTHENTICATION_BACKENDS 376 self.user1 = User.objects.create_user('test', 'test@example.com', 'test') 377 self.user1.save() 378 379 def tearDown(self): 380 settings.AUTHENTICATION_BACKENDS = self.curr_auth 381 382 def test_permission_denied(self): 383 "user is not authenticated after a backend raises permission denied #2550" 384 settings.AUTHENTICATION_BACKENDS = (self.backend,)+tuple(self.curr_auth) 385 self.assertEqual(authenticate(username='test', password='test'), None) 386 387 def test_authenticates(self): 388 settings.AUTHENTICATION_BACKENDS = tuple(self.curr_auth) + (self.backend,) 389 self.assertEqual(authenticate(username='test', password='test'), self.user1) -
django/contrib/auth/tests/__init__.py
1 1 from django.contrib.auth.tests.auth_backends import (BackendTest, 2 2 RowlevelBackendTest, AnonymousUserBackendTest, NoAnonymousUserBackendTest, 3 NoBackendsTest, InActiveUserBackendTest, NoInActiveUserBackendTest )3 NoBackendsTest, InActiveUserBackendTest, NoInActiveUserBackendTest,PermissionDeniedBackendTest) 4 4 from django.contrib.auth.tests.basic import BasicTestCase 5 5 from django.contrib.auth.tests.decorators import LoginRequiredTestCase 6 6 from django.contrib.auth.tests.forms import (UserCreationFormTest,