
    `f/                         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	 Z G d
 de          Z G d de          Z G d de          ZdS )    )partial)auth)load_backend)RemoteUserBackend)ImproperlyConfigured)MiddlewareMixin)SimpleLazyObjectc                 b    t          | d          st          j        |           | _        | j        S )N_cached_user)hasattrr   get_userr   requests    P/var/www/html/env/lib/python3.11/site-packages/django/contrib/auth/middleware.pyr   r      s/    7N++ 6#}W55    c                 r   K   t          | d          st          j        |            d {V | _        | j        S )N_acached_user)r   r   	aget_userr   r   s    r   auserr      sE      7O,, >&*nW&=&= = = = = = =  r   c                       e Zd Zd ZdS )AuthenticationMiddlewarec                     t          d          st          d          t          fd          _        t	          t
                    _        d S )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                     S )N)r   r   s   r   <lambda>z:AuthenticationMiddleware.process_request.<locals>.<lambda>!   s    0A0A r   )r   r   r	   userr   r   )selfr   s    `r   process_requestz(AuthenticationMiddleware.process_request   s]    w	** 	&M   ((A(A(A(ABBw//r   N)__name__
__module____qualname__r    r   r   r   r      s#        
0 
0 
0 
0 
0r   r   c                   ,    e Zd ZdZdZdZd Zd Zd ZdS )RemoteUserMiddlewarea  
    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                    t          |d          st          d          	 |j        | j                 }n9# t          $ r, | j        r!|j        j        r|                     |           Y d S w xY w|j        j        rH|j        	                                | 
                    ||          k    rd S |                     |           t          j        ||          }|r||_        t          j        ||           d S d S )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   z$RemoteUserMiddleware.process_request9   s,   w'' 	&:  	|DK0HH 	 	 	 - 3',2O 3))'222FF	 <( 	3|((**d.A.A(G.T.TTT ))'222  h??? 	&  GLJw%%%%%		& 	&s   4 2A*)A*c                     |j         t          j                 }t          j        |          }	 |                    |          }n# t
          $ r Y nw xY w|S )zr
        Allow the backend to clean the username, if the backend defines a
        clean_username method.
        )r   r   BACKEND_SESSION_KEYr   r/   AttributeError)r   r2   r   backend_strbackends        r   r/   z#RemoteUserMiddleware.clean_username`   sb    
 od&>?#K00	--h77HH 	 	 	D	s   A 
AAc                    	 t          |j                            t          j        d                    }t          |t                    rt          j        |           dS dS # t          $ r t          j        |           Y dS w xY w)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   r4   
isinstancer   logoutImportError)r   r   stored_backends      r   r-   z)RemoteUserMiddleware._remove_invalid_userm   s    
		%)##D$<bAA N .*;<< %G$$$$$% %	  	! 	! 	!K      	!s   2A! !BBN)	r   r    r!   __doc__r)   r+   r   r/   r-   r"   r   r   r$   r$   %   sY           F $%& %& %&N  % % % % %r   r$   c                       e Zd ZdZdZdS )PersistentRemoteUserMiddlewarea  
    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.
    FN)r   r    r!   r?   r+   r"   r   r   rA   rA   ~   s"          !&r   rA   N)	functoolsr   django.contribr   django.contrib.authr   django.contrib.auth.backendsr   django.core.exceptionsr   django.utils.deprecationr   django.utils.functionalr	   r   r   r   r$   rA   r"   r   r   <module>rI      s3               , , , , , , : : : : : : 7 7 7 7 7 7 4 4 4 4 4 4 4 4 4 4 4 4     ! ! !0 0 0 0 0 0 0 0V% V% V% V% V%? V% V% V%r& & & & &%9 & & & & &r   