
    (ph/                         S SK Jr  S SKJr  S SKJr  S SKJr  S SKJ	r	  S SK
Jr  S SKJr  S rS	 r " S
 S\5      r " S S\5      r " S S\5      rg)    )partial)auth)load_backend)RemoteUserBackend)ImproperlyConfigured)MiddlewareMixin)SimpleLazyObjectc                 r    [        U S5      (       d  [        R                  " U 5      U l        U R                  $ )N_cached_user)hasattrr   get_userr   requests    Q/var/www/html/venv/lib/python3.13/site-packages/django/contrib/auth/middleware.pyr   r      s,    7N++#}}W5    c                    #    [        U S5      (       d#  [        R                  " U 5      I S h  vN U l        U R                  $  N7f)N_acached_user)r   r   	aget_userr   r   s    r   auserr      s7     7O,,&*nnW&= =    !>s   +AAAc                       \ rS rSrS rSrg)AuthenticationMiddleware   c                    ^ [        TS5      (       d  [        S5      e[        U4S j5      Tl        [	        [
        T5      Tl        g )NsessionzThe Django authentication middleware requires session middleware to be installed. Edit your MIDDLEWARE setting to insert 'django.contrib.sessions.middleware.SessionMiddleware' before 'django.contrib.auth.middleware.AuthenticationMiddleware'.c                     > [        T 5      $ )N)r   r   s   r   <lambda>:AuthenticationMiddleware.process_request.<locals>.<lambda>!   s
    0Ar   )r   r   r	   userr   r   )selfr   s    `r   process_request(AuthenticationMiddleware.process_request   s@    w	**&M  ((ABw/r    N)__name__
__module____qualname____firstlineno__r    __static_attributes__r"   r   r   r   r      s    
0r   r   c                   2    \ rS rSrSrSrSrS rS rS r	Sr
g	)
RemoteUserMiddleware%   a  
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.
REMOTE_USERTc                 .   [        US5      (       d  [        S5      e UR                  U R                     nUR                  R                  (       a?  UR                  R                  5       U R                  X!5      :X  a  g U R                  U5        [        R                  " XS9nU(       a  X1l        [        R                  " X5        g g ! [         a@    U R
                  (       a,  UR                  R                  (       a  U R                  U5         g f = f)Nr   zThe 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.)remote_user)r   r   METAheaderKeyErrorforce_logout_if_no_headerr   is_authenticated_remove_invalid_userget_usernameclean_usernamer   authenticatelogin)r   r   usernamer   s       r   r    $RemoteUserMiddleware.process_request9   s    w''&: 	||DKK0H <<((||((*d.A.A(.TT ))'2   ?  LJJw%	 +  	 --',,2O2O))'2	s   C
 
ADDc                     UR                   [        R                     n[        R                  " U5      n UR	                  U5      nU$ ! [
         a     U$ f = f)zZ
Allow the backend to clean the username, if the backend defines a
clean_username method.
)r   r   BACKEND_SESSION_KEYr   r5   AttributeError)r   r8   r   backend_strbackends        r   r5   #RemoteUserMiddleware.clean_username`   s]    
 ood&>&>?##K0	--h7H   		s   A 
AAc                     [        UR                  R                  [        R                  S5      5      n[        U[        5      (       a  [        R                  " U5        gg! [         a    [        R                  " U5         gf = f)z
Remove the current authenticated user in the request which is invalid
but only if the user is authenticated via the RemoteUserBackend.
 N)	r   r   getr   r;   
isinstancer   logoutImportError)r   r   stored_backends      r   r3   )RemoteUserMiddleware._remove_invalid_userm   si    
		%)##D$<$<bAN .*;<<G$ =	  	!KK 	!s   3A" " BBr"   N)r#   r$   r%   r&   __doc__r/   r1   r    r5   r3   r'   r"   r   r   r)   r)   %   s$      F $%&N%r   r)   c                       \ rS rSrSrSrSrg)PersistentRemoteUserMiddleware~   a  
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.
Fr"   N)r#   r$   r%   r&   rH   r1   r'   r"   r   r   rJ   rJ   ~   s     !&r   rJ   N)	functoolsr   django.contribr   django.contrib.authr   django.contrib.auth.backendsr   django.core.exceptionsr   django.utils.deprecationr   django.utils.functionalr	   r   r   r   r)   rJ   r"   r   r   <module>rS      sL      , : 7 4 4 !0 0V%? V%r&%9 &r   