
    9i7                         	 d dl mZ 	 d dlmZ d dlZ ej                  e	      Z
d Zd Z G d de      Zy# e$ r	 d dlmZ Y <w xY w# e$ r	 d dlmZ Y Fw xY w)	    )urlparse)cElementTree)ElementTreeNc                 J    dj                  | dgt        |       dz
  z  z         S )N/z..   )joinlen)route_to_leafs    ;/var/www/html/venv/lib/python3.12/site-packages/msal/mex.py_xpath_of_rootr   )   s'    88MTFc-.@.B$CCDD    c                     |j                   | fi |}|j                          	 t        |j                        j	                         S # t
        j                  $ r- t        j                  d|j                  |j                          w xY w)NzMalformed MEX document: %s, %s)
getraise_for_statusMextext&get_wstrust_username_password_endpointET
ParseErrorlogger	exceptionstatus_code)mex_endpointhttp_clientkwargsmex_resps       r   send_requestr   .   sv    {|6v6H8==!HHJJ== ,h.B.BHMM	Ss   "A A Bc                   `    e Zd Zdddddddddd	d
d
dddZdZdZd Zd Zd Zd Z	d Z
d Zd Zy)r   z http://schemas.xmlsoap.org/wsdl/z9http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702z4http://schemas.xmlsoap.org/ws/2005/07/securitypolicyzRhttp://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsdz$http://www.w3.org/2005/08/addressingz3http://schemas.microsoft.com/ws/06/2004/policy/httpz'http://schemas.xmlsoap.org/wsdl/soap12/z,http://schemas.xmlsoap.org/ws/2004/09/policyz'http://www.w3.org/2003/05/soap-envelopez0http://docs.oasis-open.org/ws-sx/ws-trust/200512z%urn:oasis:names:tc:SAML:1.0:assertionz+http://schemas.xmlsoap.org/ws/2005/02/trust)wsdlspsp2005wsuwsawsa10httpsoap12wspswsttrustsamlwst2005z:http://docs.oasis-open.org/ws-sx/ws-trust/200512/RST/Issuez5http://schemas.xmlsoap.org/ws/2005/02/trust/RST/Issuec                 8    t        j                  |      | _        y )N)r   
fromstringdom)selfmex_documents     r   __init__zMex.__init__N   s    ==.r   c           
      0   d| j                   d   z  }t        | j                  j                  t	        |      | j                         D cg c]>  }|j                  || j                          dj                  |j                  |            @ c}      S c c}w )Nz{%s}Idr#   z#{})NSsetr0   findallr   findformatr   )r1   components_to_leafbinding_xpathid_attrpolicys        r   _get_policy_idszMex._get_policy_idsQ   s    TWWU^+((**>:L+MtwwW@{{=$''2> LLG!45 @ A 	A @s   	ABc                 |    g d}| j                  |d      }g d}|j                  | j                  |d             |S )N)
wsp:Policywsp:ExactlyOnewsp:Allz"sp:SignedEncryptedSupportingTokensr@   zsp:UsernameTokenr@   zsp:WssUsernameToken10z.//sp:TransportBinding)r@   rA   rB   zsp2005:SignedSupportingTokensr@   zsp2005:UsernameTokenr@   zsp2005:WssUsernameToken10.//sp2005:TransportBinding)r>   update)r1   pathpoliciespath2005s       r   !_get_username_password_policy_idsz%Mex._get_username_password_policy_idsX   sH    G ''.FGO 	,,X7STUr   c                 *    | j                  g dd      S )N)r@   rA   rB   zhttp:NegotiateAuthenticationrC   )r>   )r1   s    r   _get_iwa_policy_idszMex._get_iwa_policy_idsc   s    ##W(* 	*r   c                    i }| j                   j                  d| j                        D ]  }|j                  d| j                        j	                  d      dk7  r2|j                  d| j                        j	                  d      }|j                  d| j                        D ](  }|j	                  d      |d	||j	                  d
      <   *  |S )Nzwsdl:bindingzsoap12:binding	transportz$http://schemas.xmlsoap.org/soap/httpzwsdl:operation/soap12:operation
soapActionzwsp:PolicyReferenceURI)
policy_uriactionname)r0   r7   r5   r8   r   )r1   bindingsbindingrP   prs        r   _get_bindingszMex._get_bindingsh   s    xx''@ 	CG-tww7;;KH:;\\1477<<?C<M oo&;TWWE C"$&&-61CV,-C	C r   c                    g }| j                   j                  d| j                        D ]  }|j                  d      j	                  d      d   }|j                  |      }|s:|d   |v sB|j                  d| j                        }|a|j                  j                         j                  d      s|j                  |j                  |d   d	        |S )
Nzwsdl:service/wsdl:portrS   :rO   z%wsa10:EndpointReference/wsa10:Addresszhttps://rP   )addressrP   )
r0   r7   r5   r   splitr8   r   lower
startswithappend)r1   rR   
policy_ids	endpointsportbinding_namerS   rY   s           r   _get_endpointszMex._get_endpointsu   s    	HH$$%=twwG 	PD88I.44S9"=Lll<0G7<0J>))$KTWWU&7<<+=+=+?+J+J:+V$$$+LLGH<MNP	P r   c                     | j                  | j                         | j                               }|D ]  }|d   | j                  k(  s|c S  |r|d   S dS )zDReturns {"address": "https://...", "action": "the soapAction value"}rP   r   N)rb   rU   rH   	ACTION_13)r1   r_   es      r   r   z*Mex.get_wstrust_username_password_endpoint   sa    ''""$d&L&L&NP	 	A{dnn,	  )y|2d2r   N)__name__
__module____qualname__r5   rd   ACTION_2005r3   r>   rH   rJ   rU   rb   r    r   r   r   r   9   sf     3IHc57E;=6AC7@

B  MIIK/A	*

3r   r   )urllib.parser   ImportError	xml.etreer   r   r   logging	getLoggerrf   r   r   r   objectr   rj   r   r   <module>rq      sn   8"%,,  
		8	$E
O3& O37  "!"  ,+,s    7 A AAAA