ó
Xé?_c           @   sS   d  Z  d Z d Z d d l Z d d l m Z d d l Z d „  Z e d „ Z	 d S(   sV  This module provides a CherryPy 3.x tool which implements
the server-side of HTTP Basic Access Authentication, as described in
:rfc:`2617`.

Example usage, using the built-in checkpassword_dict function which uses a dict
as the credentials store::

    userpassdict = {'bird' : 'bebop', 'ornette' : 'wayout'}
    checkpassword = cherrypy.lib.auth_basic.checkpassword_dict(userpassdict)
    basic_auth = {'tools.auth_basic.on': True,
                  'tools.auth_basic.realm': 'earth',
                  'tools.auth_basic.checkpassword': checkpassword,
    }
    app_config = { '/' : basic_auth }

t   visteyas
   April 2009iÿÿÿÿN(   t   base64_decodec            s   ‡  f d †  } | S(   s.  Returns a checkpassword function which checks credentials
    against a dictionary of the form: {username : password}.

    If you want a simple dictionary-based authentication scheme, use
    checkpassword_dict(my_credentials_dict) as the value for the
    checkpassword argument to basic_auth().
    c            s%   ˆ  j  | ƒ } | r! | | k p$ t S(   N(   t   gett   False(   t   realmt   usert   passwordt   p(   t   user_password_dict(    s~   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/auth_basic.pyt   checkpassword&   s    (    (   R   R	   (    (   R   s~   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/auth_basic.pyt   checkpassword_dict   s    c   	      C   s+  d |  k r t  d ƒ ‚ n  t j j } | j j d ƒ } | d
 k	 rþ y‡ | j d d ƒ \ } } | j ƒ  d k rË t	 | ƒ j d d ƒ \ } } | |  | | ƒ rË | r» t j
 d d	 ƒ n  | | _ d
 Sn  Wqþ t  t j f k
 rú t j d d ƒ ‚ qþ Xn  d |  t j j j d <t j d d ƒ ‚ d
 S(   s‚  A CherryPy tool which hooks at before_handler to perform
    HTTP Basic Access Authentication, as specified in :rfc:`2617`.

    If the request has an 'authorization' header with a 'Basic' scheme, this
    tool attempts to authenticate the credentials supplied in that header.  If
    the request has no 'authorization' header, or if it does but the scheme is
    not 'Basic', or if authentication fails, the tool sends a 401 response with
    a 'WWW-Authenticate' Basic header.

    realm
        A string containing the authentication realm.

    checkpassword
        A callable which checks the authentication credentials.
        Its signature is checkpassword(realm, username, password). where
        username and password are the values obtained from the request's
        'authorization' header.  If authentication succeeds, checkpassword
        returns True, else it returns False.

    t   "s-   Realm cannot contain the " (quote) character.t   authorizationt    i   t   basict   :s   Auth succeededs   TOOLS.AUTH_BASICNi  s   Bad Requests   Basic realm="%s"s   www-authenticatei‘  s.   You are not authorized to access that resource(   t
   ValueErrort   cherrypyt   servingt   requestt   headersR   t   Nonet   splitt   lowerR   t   logt   logint   binasciit   Errort	   HTTPErrort   response(	   R   R	   t   debugR   t   auth_headert   schemet   paramst   usernameR   (    (    s~   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/auth_basic.pyt
   basic_auth-   s&    	(
   t   __doc__t
   __author__t   __date__R   t   cherrypy._cpcompatR   R   R
   R   R#   (    (    (    s~   /local/mnt/workspace/CRMBuilds/Saipan.LA.2.0-00145-STD.PROD-1_20200821_083004/b/common/sectools/ext/cherrypy/lib/auth_basic.pyt   <module>   s   	