ó
Ý*µPc           @   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 „  Z
 d e f d „  ƒ  YZ d	 e f d
 „  ƒ  YZ d S(   iÿÿÿÿ(   t   auth(   t   load_backend(   t   RemoteUserBackend(   t   ImproperlyConfigured(   t   SimpleLazyObjectc         C   s+   t  |  d ƒ s$ t j |  ƒ |  _ n  |  j S(   Nt   _cached_user(   t   hasattrR    t   get_userR   (   t   request(    (    s7   ../Django//lib/python/django/contrib/auth/middleware.pyR      s    t   AuthenticationMiddlewarec           B   s   e  Z d  „  Z RS(   c            s7   t  ˆ  d ƒ s t d ƒ ‚ t ‡  f d †  ƒ ˆ  _ d  S(   Nt   sessions¸   The Django authentication middleware requires session middleware to be installed. Edit your MIDDLEWARE_CLASSES setting to insert 'django.contrib.sessions.middleware.SessionMiddleware'.c              s
   t  ˆ  ƒ S(   N(   R   (    (   R   (    s7   ../Django//lib/python/django/contrib/auth/middleware.pyt   <lambda>   s    (   R   t   AssertionErrorR   t   user(   t   selfR   (    (   R   s7   ../Django//lib/python/django/contrib/auth/middleware.pyt   process_request   s    (   t   __name__t
   __module__R   (    (    (    s7   ../Django//lib/python/django/contrib/auth/middleware.pyR	      s   t   RemoteUserMiddlewarec           B   s&   e  Z d  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 } Wnˆ t k
 r¼ | j j ƒ  r¸ yA t | j j	 t
 j d ƒ ƒ } t | t ƒ r‘ t
 j | ƒ n  Wq¸ t k
 r´ } t
 j | ƒ q¸ Xn  d  SX| j j ƒ  rô | j j ƒ  |  j | | ƒ k rô d  Sn  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_CLASSES setting to insert 'django.contrib.auth.middleware.AuthenticationMiddleware' before the RemoteUserMiddleware class.t    t   remote_user(   R   R   t   METAt   headert   KeyErrorR   t   is_authenticatedR   R
   t   getR    t   BACKEND_SESSION_KEYt
   isinstanceR   t   logoutt   get_usernamet   clean_usernamet   authenticatet   login(   R   R   t   usernamet   stored_backendt   eR   (    (    s7   ../Django//lib/python/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    R   R   R   t   AttributeError(   R   R"   R   t   backend_strt   backend(    (    s7   ../Django//lib/python/django/contrib/auth/middleware.pyR   P   s    (   R   R   t   __doc__R   R   R   (    (    (    s7   ../Django//lib/python/django/contrib/auth/middleware.pyR      s   	(N(   t   django.contribR    t   django.contrib.authR   t   django.contrib.auth.backendsR   t   django.core.exceptionsR   t   django.utils.functionalR   R   t   objectR	   R   (    (    (    s7   ../Django//lib/python/django/contrib/auth/middleware.pyt   <module>   s   	