[Fedora-suds-list] Need Help with suds.wsse.Security to attach security token to the soap header

Michael Sommerville msommerville at gmail.com
Fri Apr 13 15:45:31 UTC 2012


On Fri, Apr 13, 2012 at 4:00 PM, Sankumani Sarma <ssarma at liquidnet.com> wrote:
> I am developing a webservice client, which need to first get a security
> token from the service to invoke the next ServiceAvailabilityCheck()
> service.
>
> Successfully got the following security token from the webservice.
>
>
>
> (RequestedSecurityTokenType){
>
>    Assertion =
>
>       (Assertion){
>
>          _Version = "2.0"
>
>          _IssueInstant = "2012-04-12T18:13:29.948Z"
>
>          _ID = "saml-1334254409948"
>
>          Issuer = "com.jpmc.morcom.pathway.sts"
>
>          Subject =
>
>             (Subject){
>
>                NameID = "LQSCEAPC"
>
>                SubjectConfirmation =
>
>                   (SubjectConfirmation){
>
>                      _Method = "urn oasis:names:tc SAML:2.0:cm:bearer"
>
>                   }
>
>             }
>
>          Conditions =
>
>             (Conditions){
>
>                _NotOnOrAfter = "2012-04-13T05:13:29.000Z"
>
>                _NotBefore = "2012-04-12T18:13:29.948Z"
>
>             }
>
>          AuthnStatement =
>
>             (AuthnStatement){
>
>                _AuthnInstant = "2012-04-12T18:13:29.948Z"
>
>                AuthnContext =
>
>                   (AuthnContext){
>
>                      AuthnContextDecl =
> "AuthenticationMethod="urn:oasis:names:tc:SAML:2.0:am:password""
>
>                   }
>
>             }
>
>          AttributeStatement =
>
>             (AttributeStatement){
>
>                Attribute =
>
>                   (Attribute){
>
>                      _Name = "scToken"
>
>                      AttributeValue =
> "AAAAAgABAGgZTFPtW4euBwB63wAdaFYmic81bDHDWpwQ2kmQYeh..cP4tEAXAQE31CS24tltmBzkm406IyKG4e0qLI9hHRthxHHq0pDZNJxR9zqv0jDgm6VOtAYUx6WHt2D6ULUZu6wVhMsT54TqVA__!!57P89XlXgJqBySvo7B2MTCK4lmzPn6Oqn78kAeJiMwS2aRwqUxyEjoazKz.m8Xxlw2WUTbITcESwxN.dvNnfvQGD4kudgMZ5IatTcW9hTir36jEphw41F8zRmRXtUQ7PkJR9yw__"
>
>                   }
>
>             }
>
>       }
>
> }
>
>
>
>
>
> Now the problem is how to set that security token in  the soap header while
> invoking the ServiceAvailabilityCheck() service.
>
>
>
> I have tried the following:
>
>
>
> # getting an instance of the Security module
>
> security =suds.wsse.Security()
>
>
>
> # getting an instance of the Token module
>
> token = suds.wsse.Token()
>
>
>
> # setting the security token RequestedSecurityTokenType  object received
> earlier
>
> token.__setattr__('RequestedSecurityTokenType', requestedSecurityTokenType)
>
> security.tokens.append(token)
>
>
>
> # setting the client with the security header
>
> client.set_options(wsse=security)
>
>
>
> # calling the service now
>
> serviceAvailibility = client_eap.service.ServiceAvailabilityCheck()
>
>
>
>
>
> I am getting the following error:
>
>
>
>   File "build\bdist.win32\egg\suds\client.py", line 539, in __call__
>
>     return client.invoke(args, kwargs)
>
>   File "build\bdist.win32\egg\suds\client.py", line 592, in invoke
>
>     msg = binding.get_message(self.method, args, kwargs)
>
>   File "build\bdist.win32\egg\suds\bindings\binding.py", line 116, in
> get_message
>
>   File "build\bdist.win32\egg\suds\bindings\binding.py", line 338, in
> headercontent
>
>   File "build\bdist.win32\egg\suds\wsse.py", line 79, in xml
>
>     root.append(t.xml())
>
> AttributeError: Token instance has no attribute 'xml'

I've not looked closely, but it would appear you'll need to create a
new sub-class in wsse.py to suit your purposes.  This will need to
return an xml root node with the data your WS expects. Look at how the
Timestamp() token is implemented in that same file as an example, it
should be fairly straightforward.

-Mike


More information about the suds mailing list