diff --git a/docs/topics/auth.txt b/docs/topics/auth.txt
index ecbc2f2..7b3c0a6 100644
a
|
b
|
By default, :setting:`AUTHENTICATION_BACKENDS` is set to::
|
1633 | 1633 | |
1634 | 1634 | ('django.contrib.auth.backends.ModelBackend',) |
1635 | 1635 | |
1636 | | That's the basic authentication scheme that checks the Django users database. |
| 1636 | That's the basic authentication backend that checks the Django users database |
| 1637 | and queries the builtin permissions, it does not provide, out-of-the-box |
| 1638 | protection against brute force attacks via any rate limiting mechanism. |
1637 | 1639 | |
1638 | 1640 | The order of :setting:`AUTHENTICATION_BACKENDS` matters, so if the same |
1639 | 1641 | username and password is valid in multiple backends, Django will stop |
… |
… |
processing at the first positive match.
|
1652 | 1654 | Writing an authentication backend |
1653 | 1655 | --------------------------------- |
1654 | 1656 | |
1655 | | An authentication backend is a class that implements two methods: |
1656 | | ``get_user(user_id)`` and ``authenticate(**credentials)``. |
| 1657 | An authentication backend is a class that implements two required methods: |
| 1658 | ``get_user(user_id)`` and ``authenticate(**credentials)``, as well as a set of |
| 1659 | optional permission related :ref:`authorization methods <authorization_methods>`. |
1657 | 1660 | |
1658 | 1661 | The ``get_user`` method takes a ``user_id`` -- which could be a username, |
1659 | 1662 | database ID or whatever -- and returns a ``User`` object. |
… |
… |
object the first time a user authenticates::
|
1699 | 1702 | ADMIN_PASSWORD = 'sha1$4e987$afbcf42e21bd417fb71db8c66b321e9fc33051de' |
1700 | 1703 | """ |
1701 | 1704 | |
| 1705 | # required transient attribute for auth backends |
| 1706 | # (see deprecation timeline) |
1702 | 1707 | supports_inactive_user = False |
1703 | 1708 | |
1704 | 1709 | def authenticate(self, username=None, password=None): |
… |
… |
object the first time a user authenticates::
|
1724 | 1729 | except User.DoesNotExist: |
1725 | 1730 | return None |
1726 | 1731 | |
| 1732 | .. _authorization_methods: |
| 1733 | |
1727 | 1734 | Handling authorization in custom backends |
1728 | 1735 | ----------------------------------------- |
1729 | 1736 | |
… |
… |
fairly simply::
|
1754 | 1761 | return False |
1755 | 1762 | |
1756 | 1763 | This gives full permissions to the user granted access in the above example. |
1757 | | Notice that the backend auth functions all take the user object as an argument, |
1758 | | and they also accept the same arguments given to the associated |
1759 | | :class:`django.contrib.auth.models.User` functions. |
| 1764 | Notice that in addition to the same arguments given to the associated |
| 1765 | :class:`django.contrib.auth.models.User` functions, the backend auth functions |
| 1766 | all take the user object, which may be an anonymous user, as an argument. |
1760 | 1767 | |
1761 | | A full authorization implementation can be found in |
1762 | | `django/contrib/auth/backends.py`_, which is the default backend and queries |
1763 | | the ``auth_permission`` table most of the time. |
| 1768 | A full authorization implementation can be found in the ``ModelBackend`` class |
| 1769 | in `django/contrib/auth/backends.py`_, which is the default backend and queries |
| 1770 | the ``auth_permission`` table most of the time. If you wish to provide |
| 1771 | custom behavior for only part of the backend API, you can take advantage of |
| 1772 | Python inheritence and subclass ``ModelBackend`` instead of implementing the |
| 1773 | complete API in a custom backend. |
1764 | 1774 | |
1765 | 1775 | .. _django/contrib/auth/backends.py: http://code.djangoproject.com/browser/django/trunk/django/contrib/auth/backends.py |
1766 | 1776 | |
… |
… |
authorize anonymous users to browse most of the site, and many allow anonymous
|
1778 | 1788 | posting of comments etc. |
1779 | 1789 | |
1780 | 1790 | Django's permission framework does not have a place to store permissions for |
1781 | | anonymous users. However, it has a foundation that allows custom authentication |
1782 | | backends to specify authorization for anonymous users. This is especially useful |
1783 | | for the authors of re-usable apps, who can delegate all questions of authorization |
1784 | | to the auth backend, rather than needing settings, for example, to control |
1785 | | anonymous access. |
| 1791 | anonymous users. However, the user object passed to an authentication backend |
| 1792 | may be an :class:`django.contrib.auth.models.AnonymousUser` object, allowing |
| 1793 | the backend to specify custom authorization behavior for anonymous users. This |
| 1794 | is especially useful for the authors of re-usable apps, who can delegate all |
| 1795 | questions of authorization to the auth backend, rather than needing settings, |
| 1796 | for example, to control anonymous access. |
1786 | 1797 | |
| 1798 | .. _inactive_auth: |
1787 | 1799 | |
1788 | 1800 | Authorization for inactive users |
1789 | 1801 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
1790 | 1802 | |
1791 | | .. versionadded:: 1.3 |
| 1803 | .. versionchanged:: 1.3 |
1792 | 1804 | |
1793 | 1805 | An inactive user is a one that is authenticated but has its attribute |
1794 | 1806 | ``is_active`` set to ``False``. However this does not mean they are not |
1795 | 1807 | authorized to do anything. For example they are allowed to activate their |
1796 | 1808 | account. |
1797 | 1809 | |
1798 | | The support for anonymous users in the permission system allows for |
1799 | | anonymous users to have permissions to do something while inactive |
| 1810 | The support for anonymous users in the permission system allows for a scenario |
| 1811 | where anonymous users have permissions to do something while inactive |
1800 | 1812 | authenticated users do not. |
1801 | 1813 | |
1802 | 1814 | To enable this on your own backend, you must set the class attribute |
… |
… |
passed to the authorization methods.
|
1811 | 1823 | |
1812 | 1824 | |
1813 | 1825 | Handling object permissions |
1814 | | --------------------------- |
| 1826 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
1815 | 1827 | |
1816 | 1828 | Django's permission framework has a foundation for object permissions, though |
1817 | 1829 | there is no implementation for it in the core. That means that checking for |
1818 | 1830 | object permissions will always return ``False`` or an empty list (depending on |
1819 | | the check performed). |
| 1831 | the check performed). An authentication backend will receive the keyword |
| 1832 | parameters ``obj`` and ``user_obj`` for each object related authorization |
| 1833 | method and can return the object level permission as appropriate. |