o
    +if7                     @   s   zd dl mZ W n ey   d dlmZ Y nw zd dlmZ W n ey/   d dlmZ Y nw d dlZee	Z
dd Zdd ZG d	d
 d
eZdS )    )urlparse)cElementTree)ElementTreeNc                 C   s   d | dgt| d   S )N/z..   )joinlen)route_to_leaf r
   A/var/www/html/corbot_env/lib/python3.10/site-packages/msal/mex.py_xpath_of_root)   s   r   c                 K   sP   |j | fi |}|  zt|j W S  tjy'   td|j	|j  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_respr
   r
   r   send_request.   s   
r   c                   @   sn   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d Zdd Zdd Zdd Z	dd Z
dd Zdd ZdS )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                 C   s   t || _d S )N)r   
fromstringdom)selfmex_documentr
   r
   r   __init__N   s   zMex.__init__c                    s8   dj d  t fddjt|j D S )Nz{%s}Idr   c                    s.   g | ]}|  jd urd|qS )Nz#{})findNSformatr   ).0policybinding_xpathid_attrr,   r
   r   
<listcomp>S   s
    z'Mex._get_policy_ids.<locals>.<listcomp>)r0   setr+   findallr   )r,   components_to_leafr5   r
   r4   r   _get_policy_idsQ   s   zMex._get_policy_idsc                 C   s2   g d}|  |d}g d}||  |d |S )N)
wsp:Policywsp:ExactlyOnewsp:Allz"sp:SignedEncryptedSupportingTokensr<   zsp:UsernameTokenr<   zsp:WssUsernameToken10z.//sp:TransportBinding)r<   r=   r>   zsp2005:SignedSupportingTokensr<   zsp2005:UsernameTokenr<   zsp2005:WssUsernameToken10.//sp2005:TransportBinding)r;   update)r,   pathpoliciespath2005r
   r
   r   !_get_username_password_policy_idsX   s
   z%Mex._get_username_password_policy_idsc                 C   s   |  g ddS )N)r<   r=   r>   zhttp:NegotiateAuthenticationr?   )r;   )r,   r
   r
   r   _get_iwa_policy_idsc   s   zMex._get_iwa_policy_idsc                 C   sz   i }| j d| jD ]0}|d| jddkrq
|d| jd}|d| jD ]}|d|d	||d
< q*q
|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)r+   r9   r0   r/   r   )r,   bindingsbindingrJ   prr
   r
   r   _get_bindingsh   s    
zMex._get_bindingsc                 C   s   g }| j d| jD ]7}|ddd }||}|rA|d |v rA|d| j}|d urA|j drA|	|j|d d	 q
|S )
Nzwsdl:service/wsdl:portrM   :rI   z%wsa10:EndpointReference/wsa10:Addresszhttps://rJ   )addressrJ   )
r+   r9   r0   r   splitr/   r   lower
startswithappend)r,   rL   
policy_ids	endpointsportbinding_namerM   rR   r
   r
   r   _get_endpointsu   s   
zMex._get_endpointsc                 C   sD   |  |  |  }|D ]}|d | jkr|  S q|r |d S dS )zDReturns {"address": "https://...", "action": "the soapAction value"}rJ   r   N)r[   rO   rD   	ACTION_13)r,   rX   er
   r
   r   r      s   z*Mex.get_wstrust_username_password_endpointN)__name__
__module____qualname__r0   r\   ACTION_2005r.   r;   rD   rE   rO   r[   r   r
   r
   r
   r   r   9   s2    r   )urllib.parser   ImportError	xml.etreer   r   r   logging	getLoggerr^   r   r   r   objectr   r
   r
   r
   r   <module>   s   
