Ë
    "ïàj¥  ã                   ó^   — d Z ddlmZ ddlmZ dZ ej                  e«      Z G d„ de«      Z	y)aÝ  
Implementation of a domain controller that uses realm/user_name/password mappings
from the configuration file and uses the share path as realm name.

user_mapping is defined a follows::

    simple_dc: {
        user_mapping = {
            "realm1": {
                "John Smith": {
                    "password": "YouNeverGuessMe",
                },
                "Dan Brown": {
                    "password": "DontGuessMeEither",
                    "roles": ["editor"]
                }
            },
            "realm2": {
                ...
            }
        },
    }

The "*" pseudo-share is used to pass a default definition::

    user_mapping = {
        "*": {  // every share except for 'realm2'
            "Dan Brown": {
                "password": "DontGuessMeEither",
                "roles": ["editor"]
            }
        },
        "realm2": {
            ...
        }
    },

A share (even the "*" pseudo-share) can be set to True to allow anonymous access::

    user_mapping = {
        "*": {
            "Dan Brown": {
                "password": "DontGuessMeEither",
                "roles": ["editor"]
            },
        },
        "realm2": True
    },

The SimpleDomainController fulfills the requirements of a DomainController as
used for authentication with http_authenticator.HTTPAuthenticator for the
WsgiDAV application.

Domain Controllers must provide the methods as described in
DomainControllerBase_

.. _DomainControllerBase : dc/base_dc.py

é    )Úutil)ÚBaseDomainControllerÚreStructuredTextc                   óJ   ‡ — e Zd Zˆ fd„Zd„ Zd	d„Zd„ Zd„ Zd„ Zd„ Z	d„ Z
ˆ xZS )
ÚSimpleDomainControllerc                 óD  •— t         ‰| �  ||«       t        j                  |dd¬«      }|j	                  d«      | _        | j
                  €t        d«      ‚| j
                  j                  «       D ]-  \  }}t        |«      t        t        fvs|rŒ t        d|›d�«      ‚ y )NÚ	simple_dcT)Úas_dictÚuser_mappingz&Missing option: simple_dc.user_mappingz'Invalid option: simple_dc.user_mapping[z"]: must be True or non-empty dict.)ÚsuperÚ__init__r   Úget_dict_valueÚgetÚuser_mapÚRuntimeErrorÚitemsÚtypeÚboolÚdict)ÚselfÚwsgidav_appÚconfigÚdc_confÚshareÚdataÚ	__class__s         €úC/srv/dav/.venv/lib/python3.12/site-packages/wsgidav/dc/simple_dc.pyr   zSimpleDomainController.__init__J   s�   ø€ Ü‰Ñ˜ fÔ-ä×%Ñ% f¨kÀ4ÔHˆàŸ™ NÓ3ˆŒØ�=‰=Ð ÜÐGÓHÐHàŸ=™=×.Ñ.Ó0ò 	‰KˆE�4Ü�D‹z¤$¬ Ñ-²TÜ"Ø=¸e¸YÐFhÐióð ð	ð
 	ó    c                 ó4   — | j                   j                  › d�S )Nz())r   Ú__name__©r   s    r   Ú__str__zSimpleDomainController.__str__Z   s   € Ø—.‘.×)Ñ)Ð*¨"Ð-Ð-r   c                 ó    — | j                   j                  |«      }|€| j                   j                  d«      }|�|€|S |j                  |«      S )zHReturn the matching user_map entry (falling back to default '*' if any).Ú*)r   r   )r   ÚrealmÚ	user_nameÚrealm_entrys       r   Ú_get_realm_entryz'SimpleDomainController._get_realm_entry]   sP   € à—m‘m×'Ñ'¨Ó.ˆØÐØŸ-™-×+Ñ+¨CÓ0ˆKØÐ Ð 3ØÐØ�‰˜yÓ)Ð)r   c                 ó*   — | j                  ||«      }|S )z5Resolve a relative url to the appropriate realm name.)Ú_calc_realm_from_path_provider)r   Ú	path_infoÚenvironr%   s       r   Úget_domain_realmz'SimpleDomainController.get_domain_realmf   s   € à×3Ñ3°I¸wÓGˆØˆr   c                 ób   — | j                  |«      }|€t        j                  d|› d�«       |duS )zUReturn True if this realm requires authentication (grant anonymous access otherwise).z.Missing configuration simple_dc.user_mapping["z%"] (or "*"): realm is not accessible!T)r(   Ú_loggerÚerror)r   r%   r,   r'   s       r   Úrequire_authenticationz-SimpleDomainController.require_authenticationk   sC   € à×+Ñ+¨EÓ2ˆØÐÜ�M‰MØ@ÀÀð H+ð +ôð  $Ð&Ð&r   c                 ó€   — | j                  ||«      }|�*||j                  d«      k(  r|j                  dg «      |d<   yy)z|Returns True if this user_name/password pair is valid for the realm,
        False otherwise. Used for basic authentication.ÚpasswordÚrolesúwsgidav.auth.rolesTF)r(   r   )r   r%   r&   r3   r,   Úusers         r   Úbasic_auth_userz&SimpleDomainController.basic_auth_useru   sH   € ð ×$Ñ$ U¨IÓ6ˆàÐ ¨D¯H©H°ZÓ,@Ò @Ø,0¯H©H°W¸bÓ,AˆGÐ(Ñ)ØØr   c                  ó   — y)NT© r!   s    r   Úsupports_http_digest_authz0SimpleDomainController.supports_http_digest_auth   s   € àr   c                 óž   — | j                  ||«      }|€y|j                  d«      }|j                  dg «      |d<   | j                  |||«      S )zComputes digest hash A1 part.Fr3   r4   r5   )r(   r   Ú_compute_http_digest_a1)r   r%   r&   r,   r6   r3   s         r   Údigest_auth_userz'SimpleDomainController.digest_auth_userƒ   sU   € à×$Ñ$ U¨IÓ6ˆØˆ<ØØ—8‘8˜JÓ'ˆØ(,¯©°¸"Ó(=ˆÐ$Ñ%Ø×+Ñ+¨E°9¸hÓGÐGr   )N)r    Ú
__module__Ú__qualname__r   r"   r(   r-   r1   r7   r:   r=   Ú__classcell__)r   s   @r   r   r   I   s,   ø„ ôò .ó*òò
'òòöHr   r   N)
Ú__doc__Úwsgidavr   Úwsgidav.dc.base_dcr   Ú__docformat__Úget_module_loggerr    r/   r   r9   r   r   ú<module>rF      s;   ðñ
:õx Ý 3à"€à
 ˆ$×
 Ñ
  Ó
*€ôAHÐ1õ AHr   