
    -ek%                    (   d Z ddlmZ ddlZ ej        e          ZddlZddl	m
Z
 ddlmZ ddlmZmZmZmZ ddlmZ ddlmZ d	d
lmZ erd	dlmZ dZ ede          Z G d d          Z G d de          Z G d de          ZddZ ddZ!dS )zK Provide a hook for supplying authorization mechanisms to a Bokeh server.

    )annotationsN)isfile)
ModuleType)TYPE_CHECKING	AwaitableCallableNewType)HTTPServerRequest)RequestHandler   )make_globally_unique_id)PathLike)
AuthModuleAuthProviderNullAuthUserc                      e Zd ZdZddZedd            Zedd            Zedd
            Zedd            Z	edd            Z
edd            Zedd            Zedd            ZddZdS )r   a   Abstract base class for implementing authorization hooks.

    Subclasses must supply one of: ``get_user`` or ``get_user_async``.

    Subclasses must also supply one of ``login_url`` or ``get_login_url``.

    Optionally, if ``login_url`` provides a relative URL, then ``login_handler``
    may also be supplied.

    The properties ``logout_url`` and ``get_logout_handler`` are analogous to
    the corresponding login properties, and are optional.

    returnNonec                .    |                                   d S N)	_validateselfs    :lib/python3.11/site-packages/bokeh/server/auth_provider.py__init__zAuthProvider.__init__E   s        &list[tuple[str, type[RequestHandler]]]c                    g }| j         r*| j        J |                    | j        | j         f           | j        r*| j        J |                    | j        | j        f           |S )z3 URL patterns for login/logout endpoints.

        )login_handler	login_urlappendlogout_handler
logout_url)r   	endpointss     r   r%   zAuthProvider.endpointsH   s    
 =?	 	C>---dnd.@ABBB 	E?...dot/BCDDDr   )Callable[[HTTPServerRequest], str] | Nonec                    dS )a;   A function that computes a URL to redirect unathenticated users
        to for login.

        This property may return None, if a ``login_url`` is supplied
        instead.

        If a function is returned, it should accept a ``RequestHandler``
        and return a login URL for unathenticated users.

        N r   s    r   get_login_urlzAuthProvider.get_login_urlV   s	     	r   *Callable[[HTTPServerRequest], User] | Nonec                    dS )a   A function to get the current authenticated user.

        This property may return None, if a ``get_user_async`` function is
        supplied instead.

        If a function is returned, it should accept a ``RequestHandler``
        and return the current authenticated user.

        Nr(   r   s    r   get_userzAuthProvider.get_userd   	     	r   5Callable[[HTTPServerRequest], Awaitable[User]] | Nonec                    dS )a    An async function to get the current authenticated user.

        This property may return None, if a ``get_user`` function is supplied
        instead.

        If a function is returned, it should accept a ``RequestHandler``
        and return the current authenticated user.

        Nr(   r   s    r   get_user_asynczAuthProvider.get_user_asyncq   r-   r   type[RequestHandler] | Nonec                    dS )a   A request handler class for a login page.

        This property may return None, if ``login_url`` is supplied
        instead.

        If a class is returned, it must be a subclass of RequestHandler,
        which will used for the endpoint specified by ``logout_url``

        Nr(   r   s    r   r    zAuthProvider.login_handler~   r-   r   
str | Nonec                    dS )z A URL to redirect unauthenticated users to for login.

        This proprty may return None, if a ``get_login_url`` function is
        supplied instead.

        Nr(   r   s    r   r!   zAuthProvider.login_url   s	     	r   c                    dS )z A request handler class for a logout page.

        This property may return None.

        If a class is returned, it must be a subclass of RequestHandler,
        which will used for the endpoint specified by ``logout_url``

        Nr(   r   s    r   r#   zAuthProvider.logout_handler   s	     	r   c                    dS )zf A URL to redirect authenticated users to for logout.

        This proprty may return None.

        Nr(   r   s    r   r$   zAuthProvider.logout_url   s	     	r   c                v   | j         r| j        rt          d          | j         s| j        r| j        s| j        st          d          | j        r| j        rt          d          | j        r| j        rt          d          | j        r)t          | j        t                    st          d          | j        r#t          | j                  st          d          | j	        r)t          | j	        t                    st          d          | j
        r#t          | j
                  st          d          d S d S )	Nz9Only one of get_user or get_user_async should be suppliedzWWhen user authentication is enabled, one of login_url or get_login_url must be suppliedz<At most one of login_url or get_login_url should be suppliedz;LoginHandler cannot be used with a get_login_url() functionz-LoginHandler must be a Tornado RequestHandlerz7LoginHandler can only be used with a relative login_urlz.LogoutHandler must be a Tornado RequestHandlerz9LogoutHandler can only be used with a relative logout_url)r,   r0   
ValueErrorr!   r)   r    
issubclassr   probably_relative_urlr#   r$   r   s    r   r   zAuthProvider._validate   s~   = 	ZT0 	ZXYYYM 	xT0 	x4> 	xTM_ 	xvwww> 	]d0 	][\\\ 	\$"4 	\Z[[[ 	Nj1C^&T&T 	NLMMM> 	X"7"G"G 	XVWWW 	Oz$2E~'V'V 	OMNNN? 	Z#8#I#I 	ZXYYY	Z 	Z 	Z 	Zr   N)r   r   )r   r   )r   r&   )r   r*   )r   r.   )r   r1   )r   r3   )__name__
__module____qualname____doc__r   propertyr%   r)   r,   r0   r    r!   r#   r$   r   r(   r   r   r   r   6   sL               X    X 
 
 
 X
 
 
 
 X
 
 
 
 X
    X 	 	 	 X	    XZ Z Z Z Z Zr   r   c                       e Zd ZdZd fdZed             Zed             Zed	             Zed
             Z	ed             Z
ed             Zed             Z xZS )r   a   An AuthProvider configured from a Python module.

    The following properties return the corresponding values from the module if
    they exist, or None otherwise:

    * ``get_login_url``,
    * ``get_user``
    * ``get_user_async``
    * ``login_url``
    * ``logout_url``

    The ``login_handler`` property will return a ``LoginHandler`` class from the
    module, or None otherwise.

    The ``logout_handler`` property will return a ``LogoutHandler`` class from
    the module, or None otherwise.

    module_pathr   r   r   c                    t          |          st          d|          t          |          | _        t	                                                       d S )Nzno file exists at module_path: )r   r8   load_auth_module_modulesuperr   )r   rA   	__class__s     r   r   zAuthModule.__init__   sV    k"" 	PN{NNOOO'44r   c                .    t          | j        dd           S )Nr,   getattrrD   r   s    r   r,   zAuthModule.get_user   s    t|Z666r   c                .    t          | j        dd           S )Nr0   rH   r   s    r   r0   zAuthModule.get_user_async   s    t|%5t<<<r   c                .    t          | j        dd           S )Nr!   rH   r   s    r   r!   zAuthModule.login_url   s    t|[$777r   c                .    t          | j        dd           S )Nr)   rH   r   s    r   r)   zAuthModule.get_login_url       t|_d;;;r   c                .    t          | j        dd           S )NLoginHandlerrH   r   s    r   r    zAuthModule.login_handler   s    t|^T:::r   c                .    t          | j        dd           S )Nr$   rH   r   s    r   r$   zAuthModule.logout_url   s    t|\4888r   c                .    t          | j        dd           S )NLogoutHandlerrH   r   s    r   r#   zAuthModule.logout_handler   rM   r   )rA   r   r   r   )r;   r<   r=   r>   r   r?   r,   r0   r!   r)   r    r$   r#   __classcell__)rF   s   @r   r   r      s        &      7 7 X7 = = X= 8 8 X8 < < X< ; ; X; 9 9 X9 < < X< < < < <r   r   c                      e Zd ZdZed             Zed             Zed             Zed             Zed             Z	ed             Z
ed             Zd	S )
r   z_ A default no-auth AuthProvider.

    All of the properties of this provider return None.

    c                    d S r   r(   r   s    r   r,   zNullAuth.get_user       tr   c                    d S r   r(   r   s    r   r0   zNullAuth.get_user_async  rV   r   c                    d S r   r(   r   s    r   r!   zNullAuth.login_url  rV   r   c                    d S r   r(   r   s    r   r)   zNullAuth.get_login_url	  rV   r   c                    d S r   r(   r   s    r   r    zNullAuth.login_handler  rV   r   c                    d S r   r(   r   s    r   r$   zNullAuth.logout_url  rV   r   c                    d S r   r(   r   s    r   r#   zNullAuth.logout_handler  rV   r   N)r;   r<   r=   r>   r?   r,   r0   r!   r)   r    r$   r#   r(   r   r   r   r      s         
   X   X   X   X   X   X   X  r   r   rA   r   r   r   c                   dt                                          dd          z   }t          j                            ||           }t          j                            |          }|j                            |           |S )z Load a Python source file at a given path as a module.

    Arguments:
        module_path (str): path to a Python source file

    Returns
        module

    zbokeh.auth_- )r   replace	importlibutilspec_from_file_locationmodule_from_specloaderexec_module)rA   module_namespecmodules       r   rC   rC     sl      "9";";"C"CC"L"LLK>11+{KKD^,,T22FKF###Mr   urlstrboolc                .    |                      d           S )z Return True if a URL is not one of the common absolute URL formats.

    Arguments:
        url (str): a URL string

    Returns
        bool

    )zhttp://zhttps://z//)
startswith)rj   s    r   r:   r:   -  s     ~~;<<<<r   )rA   r   r   r   )rj   rk   r   rl   )"r>   
__future__r   logging	getLoggerr;   logimportlib.utilra   os.pathr   typesr   typingr   r   r   r	   tornado.httputilr
   tornado.webr   util.serializationr   
core.typesr   __all__objectr   r   r   r   rC   r:   r(   r   r   <module>r}      s    # " " " " " g!!                            / . . . . . & & & & & & 9 8 8 8 8 8 &%%%%%% wvvGZ GZ GZ GZ GZ GZ GZ GZR6< 6< 6< 6< 6< 6< 6< 6<p         |      L    
= 
= 
= 
= 
= 
=r   