ó
®â0_c           @   sÕ   d  d l  m Z d  d l m Z d  d l m Z d  d l m Z d  d l m	 Z	 d  d l
 m Z d  d l m Z d „  Z d	 e f d
 „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d S(   iÿÿÿÿ(   t   settings(   t   auth(   t   load_backend(   t   RemoteUserBackend(   t   ImproperlyConfigured(   t   MiddlewareMixin(   t   SimpleLazyObjectc         C   s+   t  |  d ƒ s$ t j |  ƒ |  _ n  |  j S(   Nt   _cached_user(   t   hasattrR   t   get_userR   (   t   request(    (    s@   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/middleware.pyR	   
   s    t   AuthenticationMiddlewarec           B   s   e  Z d  „  Z RS(   c            sP   t  ˆ  d ƒ s4 t d t j d  k r* d n d ƒ ‚ t ‡  f d †  ƒ ˆ  _ d  S(   Nt   sessionsó   The Django authentication middleware requires session middleware to be installed. Edit your MIDDLEWARE%s setting to insert 'django.contrib.sessions.middleware.SessionMiddleware' before 'django.contrib.auth.middleware.AuthenticationMiddleware'.t   _CLASSESt    c              s
   t  ˆ  ƒ S(   N(   R	   (    (   R
   (    s@   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/middleware.pyt   <lambda>   R   (   R   t   AssertionErrorR    t
   MIDDLEWAREt   NoneR   t   user(   t   selfR
   (    (   R
   s@   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/middleware.pyt   process_request   s    (   t   __name__t
   __module__R   (    (    (    s@   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/middleware.pyR      s   t   SessionAuthenticationMiddlewarec           B   s   e  Z d  Z d „  Z RS(   sb  
    Formerly, a middleware for invalidating a user's sessions that don't
    correspond to the user's current session authentication hash. However, it
    caused the "Vary: Cookie" header on all responses.

    It's now a shim to allow a single settings file to more easily support
    multiple versions of Django. Will be RemovedInDjango20Warning.
    c         C   s   d  S(   N(    (   R   R
   (    (    s@   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/middleware.pyR   $   s    (   R   R   t   __doc__R   (    (    (    s@   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/middleware.pyR      s   t   RemoteUserMiddlewarec           B   s5   e  Z d  Z d Z e Z d „  Z d „  Z d „  Z RS(   sý  
    Middleware for utilizing Web-server-provided authentication.

    If request.user is not authenticated, then this middleware attempts to
    authenticate the username passed in the ``REMOTE_USER`` request header.
    If authentication is successful, the user is automatically logged in to
    persist the user in the session.

    The header used is configurable and defaults to ``REMOTE_USER``.  Subclass
    this class and change the ``header`` attribute if you need to use a
    different header.
    t   REMOTE_USERc         C   sè   t  | d ƒ s t d ƒ ‚ n  y | j |  j } Wn7 t k
 rk |  j rg | j j rg |  j | ƒ n  d  SX| j j r­ | j j	 ƒ  |  j
 | | ƒ k r d  S|  j | ƒ n  t j | d | ƒ} | rä | | _ t j | | ƒ n  d  S(   NR   sç   The Django remote user auth middleware requires the authentication middleware to be installed.  Edit your MIDDLEWARE setting to insert 'django.contrib.auth.middleware.AuthenticationMiddleware' before the RemoteUserMiddleware class.t   remote_user(   R   R   t   METAt   headert   KeyErrort   force_logout_if_no_headerR   t   is_authenticatedt   _remove_invalid_usert   get_usernamet   clean_usernameR   t   authenticatet   login(   R   R
   t   usernameR   (    (    s@   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/middleware.pyR   <   s"    !	c         C   sJ   | j  t j } t j | ƒ } y | j | ƒ } Wn t k
 rE n X| S(   ss   
        Allows the backend to clean the username, if the backend defines a
        clean_username method.
        (   R   R   t   BACKEND_SESSION_KEYR   R$   t   AttributeError(   R   R'   R
   t   backend_strt   backend(    (    s@   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/middleware.pyR$   b   s    c         C   sf   y" t  | j j t j d ƒ ƒ } Wn t k
 rB t j | ƒ n  Xt | t ƒ rb t j | ƒ n  d S(   s¡   
        Removes the current authenticated user in the request which is invalid
        but only if the user is authenticated via the RemoteUserBackend.
        R   N(	   R   R   t   getR   R(   t   ImportErrort   logoutt
   isinstanceR   (   R   R
   t   stored_backend(    (    s@   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/middleware.pyR"   o   s    "(	   R   R   R   R   t   TrueR    R   R$   R"   (    (    (    s@   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/middleware.pyR   (   s   	&	t   PersistentRemoteUserMiddlewarec           B   s   e  Z d  Z e Z RS(   s£  
    Middleware for Web-server provided authentication on logon pages.

    Like RemoteUserMiddleware but keeps the user authenticated even if
    the header (``REMOTE_USER``) is not found in the request. Useful
    for setups when the external authentication via ``REMOTE_USER``
    is only expected to happen on some "logon" URL and the rest of
    the application wants to use Django's authentication mechanism.
    (   R   R   R   t   FalseR    (    (    (    s@   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/middleware.pyR2   ~   s   	N(   t   django.confR    t   django.contribR   t   django.contrib.authR   t   django.contrib.auth.backendsR   t   django.core.exceptionsR   t   django.utils.deprecationR   t   django.utils.functionalR   R	   R   R   R   R2   (    (    (    s@   /tmp/pip-unpacked-wheel-BAJOf3/django/contrib/auth/middleware.pyt   <module>   s   	V