Python suds UsernameToken

the code:

security = Security()
token = UsernameToken('b77a5c561934e089', 'kmfHkNZyn1U/pGAiY3+h0BoHdKI=')
security.tokens.append(token)
client.set_options(wsse=security)

My problem is this: when I turn on the UsernameToken, I get this header:

   <SOAP-ENV:Header>
      <wsse:Security mustUnderstand="true">
         <wsse:UsernameToken>
            <wsse:Username>b77a5c561934e089</wsse:Username>
            <wsse:Password>kmfHkNZyn1U/pGAiY3+h0BoHdKI=</wsse:Password>
         </wsse:UsernameToken>
      </wsse:Security>
   </SOAP-ENV:Header>

But I need an answer to this requirement in a web service:

<sp:SignedSupportingTokens xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
  <wsp:Policy>
    <sp:UsernameToken sp:IncludeToken="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/AlwaysToRecipient">
      <wsp:Policy>
        <sp:WssUsernameToken10 />
      </wsp:Policy>
    </sp:UsernameToken>
  </wsp:Policy>
</sp:SignedSupportingTokens>

How can I do this with foam? I searched the entire Internet, but could not find a solution.

+4
source share
1 answer

Your code is a general SOAP solution. It seems your web service requires a custom response.

I assume your authentication does not work?

Try marshallyour answer in your interrogator class. This plugin allows you to change your envelope soap. You can add your own attributes.

class MyRequesterClass(object):

    class _myServiceMarshalled(MessagePlugin):

        def marshalled(self, context):
            commons.set_service_common_header(context, "yourService")

            body = context.envelope.getChild('Body')
            service = body.getChild("childWhereYouWantAddYourCustomXML")

            service.attributes.append(Attribute("sp:IncludeToken", "http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/AlwaysToRecipient"))

            etc, etc
0
source

All Articles