
    i*                        d dl Z d dlZ	 d dlZdZn# e$ r dZY nw xY w	 d dlmZ dZn# e$ r dZY nw xY w	 d dlmZ n# e$ r dZY nw xY w ej        e	          Z
dZ G d de          Z G d d	e          Z G d
 de          Z G d de          Z G d de          Z G d de          ZeZ G d de          Z G d de          Z G d de          Z G d de          Z G d de          ZdS )    NTF)
SASLClientProxyExecutec                       e Zd ZdZd ZdS )AuthProviderz
    An abstract class that defines the interface that will be used for
    creating :class:`~.Authenticator` instances when opening new
    connections to Cassandra.

    .. versionadded:: 2.0.0
    c                     t                      )z
        Implementations of this class should return a new instance
        of :class:`~.Authenticator` or one of its subclasses.
        NotImplementedErrorselfhosts     `/Users/user/workspace/sujinbaek/cqa-test-app/venv/lib/python3.11/site-packages/cassandra/auth.pynew_authenticatorzAuthProvider.new_authenticator4   s    
 "###    N)__name__
__module____qualname____doc__r    r   r   r   r   +   s-         $ $ $ $ $r   r   c                   *    e Zd ZdZdZ	 d Zd Zd ZdS )Authenticatora3  
    An abstract class that handles SASL authentication with Cassandra servers.

    Each time a new connection is created and the server requires authentication,
    a new instance of this class will be created by the corresponding
    :class:`~.AuthProvider` to handler that authentication. The lifecycle of the
    new :class:`~.Authenticator` will the be:

    1) The :meth:`~.initial_response()` method will be called. The return
    value will be sent to the server to initiate the handshake.

    2) The server will respond to each client response by either issuing a
    challenge or indicating that the authentication is complete (successful or not).
    If a new challenge is issued, :meth:`~.evaluate_challenge()`
    will be called to produce a response that will be sent to the
    server. This challenge/response negotiation will continue until the server
    responds that authentication is successful (or an :exc:`~.AuthenticationFailed`
    is raised).

    3) When the server indicates that authentication is successful,
    :meth:`~.on_authentication_success` will be called a token string that
    the server may optionally have sent.

    The exact nature of the negotiation between the client and server is specific
    to the authentication mechanism configured server-side.

    .. versionadded:: 2.0.0
    Nc                     dS )z
        Returns a message to send to the server to initiate the SASL handshake.
        :const:`None` may be returned to send an empty message.
        Nr   r   s    r   initial_responsezAuthenticator.initial_response]   s	    
 tr   c                     t                      )z
        Called when the server sends a challenge message.  Generally, this method
        should return :const:`None` when authentication is complete from a
        client perspective.  Otherwise, a string should be returned.
        r   r   	challenges     r   evaluate_challengez Authenticator.evaluate_challenged   s     "###r   c                     dS )z
        Called when the server indicates that authentication was successful.
        Depending on the authentication mechanism, `token` may be :const:`None`
        or a string.
        Nr   )r   tokens     r   on_authentication_successz'Authenticator.on_authentication_successl   s	     	r   )r   r   r   r   server_authenticator_classr   r   r    r   r   r   r   r   <   sV         : "&8  $ $ $    r   r   c                       e Zd ZdZd Zd ZdS )PlainTextAuthProvidera  
    An :class:`~.AuthProvider` that works with Cassandra's PasswordAuthenticator.

    Example usage::

        from cassandra.cluster import Cluster
        from cassandra.auth import PlainTextAuthProvider

        auth_provider = PlainTextAuthProvider(
                username='cassandra', password='cassandra')
        cluster = Cluster(auth_provider=auth_provider)

    .. versionadded:: 2.0.0
    c                 "    || _         || _        d S Nusernamepasswordr   r'   r(   s      r   __init__zPlainTextAuthProvider.__init__         r   c                 6    t          | j        | j                  S r%   )PlainTextAuthenticatorr'   r(   r
   s     r   r   z'PlainTextAuthProvider.new_authenticator   s    %dmT]CCCr   Nr   r   r   r   r*   r   r   r   r   r#   r#   u   sA         ! ! !D D D D Dr   r#   c                       e Zd ZdZd Zd ZdS )%TransitionalModePlainTextAuthProvidera@  
    An :class:`~.AuthProvider` that works with DSE TransitionalModePlainTextAuthenticator.

    Example usage::

        from cassandra.cluster import Cluster
        from cassandra.auth import TransitionalModePlainTextAuthProvider

        auth_provider = TransitionalModePlainTextAuthProvider()
        cluster = Cluster(auth_provider=auth_provider)

    .. warning:: TransitionalModePlainTextAuthProvider will be removed in cassandra-driver
                 4.0. The transitional mode will be handled internally without the need
                 of any auth provider.
    c                 :    t                               d           d S )NzTransitionalModePlainTextAuthProvider will be removed in cassandra-driver 4.0. The transitional mode will be handled internally without the need of any auth provider.)logwarningr   s    r   r*   z.TransitionalModePlainTextAuthProvider.__init__   s'     , 	- 	- 	- 	- 	-r   c                     t                      S r%   )&TransitionalModePlainTextAuthenticatorr
   s     r   r   z7TransitionalModePlainTextAuthProvider.new_authenticator   s    5777r   Nr.   r   r   r   r0   r0      s<          - - -8 8 8 8 8r   r0   c                       e Zd ZdZd Zd ZdS )SaslAuthProvidera  
    An :class:`~.AuthProvider` supporting general SASL auth mechanisms

    Suitable for GSSAPI or other SASL mechanisms

    Example usage::

        from cassandra.cluster import Cluster
        from cassandra.auth import SaslAuthProvider

        sasl_kwargs = {'service': 'something',
                       'mechanism': 'GSSAPI',
                       'qops': 'auth'.split(',')}
        auth_provider = SaslAuthProvider(**sasl_kwargs)
        cluster = Cluster(auth_provider=auth_provider)

    .. versionadded:: 2.1.4
    c                 f    t           t          d          d|v rt          d          || _        d S )N+The puresasl library has not been installedr   zTkwargs should not contain 'host' since it is passed dynamically to new_authenticator)r   ImportError
ValueErrorsasl_kwargs)r   r<   s     r   r*   zSaslAuthProvider.__init__   s?    KLLL[  sttt&r   c                 &    t          |fi | j        S r%   )SaslAuthenticatorr<   r
   s     r   r   z"SaslAuthProvider.new_authenticator   s     ::)9:::r   Nr.   r   r   r   r7   r7      s<         &' ' '; ; ; ; ;r   r7   c                   &    e Zd ZdZddZd Zd ZdS )r>   z
    A pass-through :class:`~.Authenticator` using the third party package
    'pure-sasl' for authentication

    .. versionadded:: 2.1.4
    GSSAPIc                 Z    t           t          d          t          |||fi || _        d S )Nr9   )r   r:   sasl)r   r   service	mechanismr<   s        r   r*   zSaslAuthenticator.__init__   s6    KLLLtWiGG;GG			r   c                 4    | j                                         S r%   rB   processr   s    r   r   z"SaslAuthenticator.initial_response   s    y  """r   c                 6    | j                             |          S r%   rF   r   s     r   r   z$SaslAuthenticator.evaluate_challenge   s    y  +++r   N)r@   )r   r   r   r   r*   r   r   r   r   r   r>   r>      sT         H H H H
# # #, , , , ,r   r>   c                        e Zd ZdZddZd ZdS )	DSEGSSAPIAuthProviderz
    Auth provider for GSS API authentication. Works with legacy `KerberosAuthenticator`
    or `DseAuthenticator` if `kerberos` scheme is enabled.
    dseauthTc                     t           st          d          t          st          d          || _        || _        || _        || _        dS )a  
        :param service: name of the service
        :param qops: iterable of "Quality of Protection" allowed; see ``puresasl.QOP``
        :param resolve_host_name: boolean flag indicating whether the authenticator should reverse-lookup an FQDN when
            creating a new authenticator. Default is ``True``, which will resolve, or return the numeric address if there is no PTR
            record. Setting ``False`` creates the authenticator with the numeric address known by Cassandra
        :param properties: additional keyword properties to pass for the ``puresasl.mechanisms.GSSAPIMechanism`` class.
            Presently, 'principal' (user) is the only one referenced in the ``pure-sasl`` implementation
        r9   z+The kerberos library has not been installedN)_have_puresaslr:   _have_kerberosrC   qopsresolve_host_name
properties)r   rC   rQ   rR   rS   s        r   r*   zDSEGSSAPIAuthProvider.__init__   sU      	MKLLL 	MKLLL	!2$r   c                     | j         rt          j        |dfd          d         }t          || j        | j        | j                  S )Nr   )rR   socketgetnameinfoGSSAPIAuthenticatorrC   rQ   rS   r
   s     r   r   z'DSEGSSAPIAuthProvider.new_authenticator   sB    ! 	7%tQi33A6D"4ty$/RRRr   N)rK   rL   Tr.   r   r   r   rJ   rJ      sF         % % % %&S S S S Sr   rJ   c                        e Zd Zd Zd Zd ZdS )BaseDSEAuthenticatorc                      t          d          )Nzget_mechanism not implementedr   r   s    r   get_mechanismz"BaseDSEAuthenticator.get_mechanism   s    !"ABBBr   c                      t          d          )Nz%get_initial_challenge not implementedr   r   s    r   get_initial_challengez*BaseDSEAuthenticator.get_initial_challenge   s    !"IJJJr   c                     | j         dk    r|                                 S |                     |                                           S )Nz0com.datastax.bdp.cassandra.auth.DseAuthenticator)r!   r[   r   r]   r   s    r   r   z%BaseDSEAuthenticator.initial_response  sC    *.```%%'''**4+E+E+G+GHHHr   N)r   r   r   r[   r]   r   r   r   r   rY   rY      sL        C C CK K KI I I I Ir   rY   c                   &    e Zd Zd Zd Zd Zd ZdS )r-   c                 "    || _         || _        d S r%   r&   r)   s      r   r*   zPlainTextAuthenticator.__init__  r+   r   c                     dS )Ns   PLAINr   r   s    r   r[   z$PlainTextAuthenticator.get_mechanism  s    xr   c                     dS )N   PLAIN-STARTr   r   s    r   r]   z,PlainTextAuthenticator.get_initial_challenge  s    ~r   c                 x    |dk    r&d| j         d| j        }|                                S t          d          )Nrc    z6Did not receive a valid challenge response from server)r'   r(   encode	Exception)r   r   datas      r   r   z)PlainTextAuthenticator.evaluate_challenge  sA    &&&%)]]]DMMBD;;== PQQQr   Nr   r   r   r*   r[   r]   r   r   r   r   r-   r-   
  sU        ! ! !    R R R R Rr   r-   c                   "     e Zd ZdZ fdZ xZS )r5   zc
     Authenticator that accounts for DSE authentication is configured with transitional mode.
    c                 Z    t          t          |                               dd           d S )N )superr5   r*   )r   	__class__s    r   r*   z/TransitionalModePlainTextAuthenticator.__init__"  s*    4d;;DDRLLLLLr   )r   r   r   r   r*   __classcell__)rn   s   @r   r5   r5     sK         M M M M M M M M Mr   r5   c                   &    e Zd Zd Zd Zd Zd ZdS )rW   c                 :    |pi }t          ||dfd|i|| _        d S )Nr@   rQ   )r   rB   )r   r   rC   rQ   rS   s        r   r*   zGSSAPIAuthenticator.__init__'  s0    %2
tWhPPTPZPP			r   c                     dS )Ns   GSSAPIr   r   s    r   r[   z!GSSAPIAuthenticator.get_mechanism+  s    yr   c                     dS Ns   GSSAPI-STARTr   r   s    r   r]   z)GSSAPIAuthenticator.get_initial_challenge.  s    r   c                 t    |dk    r| j                                         S | j                             |          S rt   rF   r   s     r   r   z&GSSAPIAuthenticator.evaluate_challenge1  s7    ''9$$&&&9$$Y///r   Nri   r   r   r   rW   rW   &  sS        Q Q Q    0 0 0 0 0r   rW   )rU   loggingkerberosrP   r:   puresasl.clientr   rO   	getLoggerr   r2   _proxy_execute_keyobjectr   r   r#   r0   r7   r>   DSEPlainTextAuthProviderrJ   rY   r-   r5   rW   r   r   r   <module>r}      s  "  OOONN   NNN******NN   NNN*******   JJJ g!! $ $ $ $ $ $6 $ $ $"6 6 6 6 6F 6 6 6rD D D D DL D D D08 8 8 8 8F 8 8 86; ; ; ; ;| ; ; ;>, , , , , , , ,( 1 S S S S SL S S S<I I I I I= I I IR R R R R1 R R R&M M M M M-C M M M0 0 0 0 0. 0 0 0 0 0s'    ( 22= AA