mò
8xÚCc           @   sW   d  Z  d k Z d k l Z d „  Z d „  Z d „  Z d „  Z d f  d „  ƒ  YZ d S(	   sX  
    MoinMoin - modular authentication code

    Here are some methods moin can use in cfg.auth authentication method list.
    The methods from that list get called (from request.py) in that sequence.
    They get request as first argument and also some more kw arguments:
       name: the value we did get from a POST of the UserPreferences page
             in the "name" form field (or None)
       password: the value of the password form field (or None)
       login: True if user has clicked on Login button
       logout: True if user has clicked on Logout button
       (we maybe add some more here)

    Use code like this to get them:
        name = kw.get('name') or ''
        password = kw.get('password') or ''
        login = kw.get('login')
        logout = kw.get('logout')
        request.log("got name=%s len(password)=%d login=%r logout=%r" % (name, len(password), login, logout))
    
    The called auth method then must return a tuple (user_obj, continue_flag).
    user_obj is either a User object or None if it could not make one.
    continue_flag is a boolean indication whether the auth loop shall continue
    trying other auth methods (or not).

    There are the possible cases for the returned tuple:
    user, False == we managed to authentify a user and we don't need to continue
    user, True  == makes no sense (unused)
    None, False == we could not authenticate the user and this is final, we
                   don't want to try other auth methods to authenticate him
    None, True  == we could not authentifacte the user, but we want to continue
                   trying with other auth methods

    The methods give a kw arg "auth_attribs" to User.__init__ that tells
    which user attribute names are DETERMINED and set by this auth method and
    must not get changed by the user using the UserPreferences form.
    It also gives a kw arg "auth_method" that tells the name of the auth
    method that authentified the user.
    
    @copyright: (c) Bastian Blank, Florian Festi, Thomas Waldmann
    @copyright: MoinMoin:AlexanderSchremmer
    @license: GNU GPL, see COPYING for details.
N(   s   userc         K   sJ  | i d ƒ ox | i d ƒ } | i d ƒ } t i |  d | d | d d ƒ} | i o! | |  _ |  i	 ƒ  | t
 f Sn d t f Sn | i d ƒ o |  i ƒ  d t f Sn y t i |  i ƒ } Wn t i j
 o d } n X| oT | i d ƒ oD t i |  d | d i d d	 d
 f  ƒ} | i o | t
 f Sq@n d t f S(   s%    authenticate via the MOIN_ID cookie t   logint   namet   passwordt   auth_methodt   login_userpasswordt   logoutt   MOIN_IDt   idt   moin_cookiet   auth_attribsN(   t   kwt   getR   R   t   usert   Usert   requestt   ut   validt	   setCookiet   Falset   Nonet   Truet   deleteCookiet   Cookiet   SimpleCookiet   saved_cookiet   cookiet   CookieErrort   has_keyt   value(   R   R
   R   R   R   R   (    (    t@   /p/gems/public/moin/lib/python2.4/site-packages/MoinMoin/auth.pyR   1   s0     
	


c   	   
   K   sc  d k  l } l } d } t |  | ƒ oI |  i i ƒ  } |  i i
 ƒ  } t i |  d | d | d d d f  ƒ} n° t |  | ƒ pŸ |  i } | i d d ƒ } | d	 d
 d d g j og | i d d ƒ } | d j o# | i d ƒ d } | i ƒ  } n t i |  d | d d d d ƒ} q!n | o | i ƒ  n | o | i o | t f Sn d t f Sd S(   s.    authenticate via http basic/digest/ntlm auth (   s   RequestTwisteds
   RequestCLIt   auth_usernameR   R   t   httpR	   t	   AUTH_TYPEt    t   Basict   Digestt   NTLMt	   Negotiatet   REMOTE_USERs   \iÿÿÿÿR   N(   R$   R%   (   s   nameR   (   t   MoinMoin.requestt   RequestTwistedt
   RequestCLIR   R   t
   isinstanceR   t   twistdt   getUsert   usernamet   getPasswordR   R   R   t   envR   t	   auth_typet   splitt   titlet   create_or_updateR   R   R   (	   R   R
   R-   R(   R   R0   R/   R   R)   (    (    R   R   \   s.     	c         K   s{  d k  l } d }	 t } t |  | ƒ o |	 Sn|  i } | i	 d d ƒ d j oã | i	 d d ƒ }
 |
 i ƒ  } | i	 d d ƒ } | i ƒ  } | p | o• x’ t i ƒ  D]z } t i |  | d d	 d
 f  ƒ}	 | o$ |	 i
 i ƒ  | j o d |	 _ Pn | o$ |	 i i ƒ  | j o d |	 _ Pqª qª Wd }	 q6n |	 o |	 i | ƒ n |	 o |	 i o |	 t f Sn d t f Sd S(   s)    authenticate via SSL client certificate (   s   RequestTwistedt   SSL_CLIENT_VERIFYt   FAILUREt   SUCCESSt   SSL_CLIENT_S_DN_EmailR!   t   SSL_CLIENT_S_DN_CNR   t   sslclientcertR	   t   emailR   R   N(   s   emails   password(   s   names   password(   R'   R(   R   R   R   t   changedR*   R   R/   R   R:   t   lowert   email_lowert
   commonnamet   commonname_lowerR   t   getUserListt   uidR   R	   R   R3   R   R   (   R   R
   R(   RA   R>   R;   R=   R/   R?   R   R:   (    (    R   R9   ƒ   s:     	 			c      	   K   su  |  i i d ƒ o |  i d d } n d  Sd  } |  i i d ƒ o |  i d d } n t i | ƒ \ } } } } | p | |  i i j o d  Sn | oÓ d  k } | i | d ƒ }
 |
 i | | ƒ } t | t ƒ o d  Sn t i |  d | ƒ} xP | i ƒ  D]B \ } }	 | d d d d	 d d
 d g j o t | | |	 ƒ qqW| i ƒ  | |  _ |  i ƒ  | Sn d  S(   NR   i    t   passwds   ?action=xmlrpc2R   t   mayR   R   t   trustedauth_usernamet	   aliasnamet
   enc_passwd(   R   t   formR   R-   R   RB   t   wikiutilt   resolve_wikit   wikitagt   wikiurlt   wikitailt   errt   cfgt   trusted_wikist	   xmlrpclibt   Servert   homewikiR,   t   account_dataR*   t   strR   R   R   t	   iteritemst   keyR   t   setattrt   saveR   (   R   R
   R-   RK   RS   RV   RM   RB   RP   R   RR   RL   R   RJ   (    (    R   t	   interwiki¸   s0    	 "
	
t   php_sessionc           B   s,   t  Z d  Z d g d d d „ Z d „  Z RS(   sn   Authentication module for PHP based frameworks
        Authenticates via PHP session cookie. Currently supported systems:

        * eGroupware 1.2 ("egw")
         * You need to configure eGroupware in the "header setup" to use
           "php sessions plus restore"

        @copyright: 2005 by MoinMoin:AlexanderSchremmer
            - Thanks to Spreadshirt
    t   egws   /tmpt   sess_c         C   s   | |  _  | |  _ | |  _ d S(   så    @param apps A list of the enabled applications. See above for
            possible keys.
            @param s_path The path where the PHP sessions are stored.
            @param s_prefix The prefix of the session files.
        N(   t   s_patht   selft   s_prefixt   apps(   R^   R`   R]   R_   (    (    R   t   __init__ì   s     		c         K   sÃ  d „  } d  k } d  k }
 d k l } d k l } y | i | i	 ƒ } Wn | i j
 o d  } n X| oHx¦ | i ƒ  D]Ž }	 |
 i | |	 i ƒ i d ƒ } | i | d |  i d |  i ƒ} | oA d |  i j o- | i d d  ƒ o | | ƒ \ } } } Pqq~ q~ Wd  t f S| | d	 | d
 | ƒ} t } | | i! j o | | _! t } n | | i j o | | _ t } n | o | i" | ƒ n | o | i# o | t f Sq¹n d  t f S(   Nc   
      C   sÆ   |  d d i d d ƒ d } |  d d d d	 } g  } | i ƒ  D]( \ } } | d
 | j o | | qE qE ~ d } | i	 d d ƒ } | i	 d d ƒ }	 d „  } | | ƒ | |	 ƒ | | ƒ f S(   s5    Extracts name, fullname and email from the session. t   egw_sessiont   session_lidt   @i   i    t   egw_info_cachet   accountst   cacheRS   t   account_lidt   fullnameR!   R:   c         C   s   |  o |  i d ƒ S(   Ns
   iso-8859-1(   t   xt   decode(   Rj   (    (    R   t   <lambda>  s    N(   t   sessionR1   R-   t   known_accountst   _[1]t   itemsRV   R   t	   user_infoR   R   R:   t   dec(
   Rm   R-   R   Rn   R   Ro   Rq   RV   Rr   R:   (    (    R   t   handle_egroupwareø   s     F	(   s   User(   s   sessionParsers
   iso-8859-1t   patht   prefixR[   Rb   R   R   ($   Rs   R   t   urllibt   MoinMoin.userR   t   MoinMoin.utilt   sessionParserR   R   R   R   R   R   t   keyst
   cookienamet   unquoteR   Rk   t   cookievaluet   loadSessionR^   R]   R_   Rm   R`   R   R-   R:   R   R   R   R   R;   RE   R3   R   (   R^   R   R
   R-   R   Ry   R   R}   R;   R{   Rv   Rm   R   Rs   R   R:   R   (    (    R   t   __call__÷   s@    			 !#
	
	
(   t   __name__t
   __module__t   __doc__Ra   R   (    (    (    R   RZ   à   s   
 (	   R‚   R   t   MoinMoinR   R   R   R9   RY   RZ   (   RY   R   R9   R   R   R   RZ   (    (    R   t   ?,   s   		+	'	5	(