CMDBuild Forum

Python WEBservice -Username Token error

Version 2.2.1

language  :Python

 

code:

#!/usr/bin/env python

# -*- coding:utf-8 -*-

from suds.wsse import *

from suds.client import Client

from suds.sax.text import Text

import logging

 

 

 

if __name__ == '__main__':

        USER="test"

        PASSWD="test"

        URL="http://172.31.9.13:8080/cmdbuild/services/soap/Webservices?wsdl"

 

    client = Client(URL)   

    logging.basicConfig(level=logging.INFO)

        logging.getLogger('suds.client').setLevel(logging.DEBUG)

 

 

    security = Security()

    token = UsernameToken('test', 'test')

    security.tokens.append(token)

    client.set_options(wsse=security)

 

    print client

    card = client.service.getCard("test", 25, "", )

 

Error:

DEBUG:suds.client:sending to (http://172.31.9.13:8080/cmdbuild/services/soap/Webservices)

message:

<?xml version="1.0" encoding="UTF-8"?>

<SOAP-ENV:Envelope xmlns:ns0="http://soap.services.cmdbuild.org" xmlns:ns1="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">

   <SOAP-ENV:Header>

      <wsse:Security mustUnderstand="true">

         <wsse:UsernameToken>

            <wsse:Username>test</wsse:Username>

            <wsse:Password>test</wsse:Password>

         </wsse:UsernameToken>

      </wsse:Security>

   </SOAP-ENV:Header>

   <ns1:Body>

      <ns0:getCard>

         <ns0:className>test</ns0:className>

         <ns0:cardId>25</ns0:cardId>

         <ns0:attributeList></ns0:attributeList>

      </ns0:getCard>

   </ns1:Body>

</SOAP-ENV:Envelope>

DEBUG:suds.client:headers = {'SOAPAction': u'""', 'Content-Type': 'text/xml; charset=utf-8'}

ERROR:suds.client:<?xml version="1.0" encoding="UTF-8"?>

<SOAP-ENV:Envelope xmlns:ns0="http://soap.services.cmdbuild.org" xmlns:ns1="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">

   <SOAP-ENV:Header>

      <wsse:Security mustUnderstand="true">

         <wsse:UsernameToken>

            <wsse:Username>test</wsse:Username>

            <wsse:Password>test</wsse:Password>

         </wsse:UsernameToken>

      </wsse:Security>

   </SOAP-ENV:Header>

   <ns1:Body>

      <ns0:getCard>

         <ns0:className>test</ns0:className>

         <ns0:cardId>25</ns0:cardId>

         <ns0:attributeList></ns0:attributeList>

      </ns0:getCard>

   </ns1:Body>

</SOAP-ENV:Envelope>

DEBUG:suds.client:http failed:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><soap:Fault><faultcode xmlns:ns1="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">ns1:InvalidSecurityToken</faultcode><faultstring>An invalid security token was provided (An error happened processing a Username Token "{0}")</faultstring></soap:Fault></soap:Body></soap:Envelope>

Traceback (most recent call last):

  File "test.py", line 26, in <module>

    card = client.service.getCard("test", 25, "", )

  File "build/bdist.linux-x86_64/egg/suds/client.py", line 542, in __call__

  File "build/bdist.linux-x86_64/egg/suds/client.py", line 602, in invoke

  File "build/bdist.linux-x86_64/egg/suds/client.py", line 649, in send

  File "build/bdist.linux-x86_64/egg/suds/client.py", line 702, in failed

  File "build/bdist.linux-x86_64/egg/suds/bindings/binding.py", line 265, in get_fault

suds.WebFault: Server raised fault: 'An invalid security token was provided (An error happened processing a Username Token "{0}")'

 

 

Does anyone know why?

Thanks

 

From my digging, it appears that CMDBuild only accepts digest passwords. I have been playing with the code on this page (https://gist.github.com/copitux/5029872), and with a bit of massaging have it working. You just add that to your module, fix the syntax errors :-), and replace your call to UsernameToken() with UsernameDigestToken().

 

Unfortunately now I'm getting the error that was reported in http://www.cmdbuild.org/forum/forum-in-english/931364090. Suds/sax cannot parse the XML returned from CMDBuild.

 

Previously Qiming wrote:

Version 2.2.1

language  :Python

 

code:

#!/usr/bin/env python

# -*- coding:utf-8 -*-

from suds.wsse import *

from suds.client import Client

from suds.sax.text import Text

import logging

 

 

 

if __name__ == '__main__':

        USER="test"

        PASSWD="test"

        URL="http://172.31.9.13:8080/cmdbuild/services/soap/Webservices?wsdl"

 

    client = Client(URL)   

    logging.basicConfig(level=logging.INFO)

        logging.getLogger('suds.client').setLevel(logging.DEBUG)

 

 

    security = Security()

    token = UsernameToken('test', 'test')

    security.tokens.append(token)

    client.set_options(wsse=security)

 

    print client

    card = client.service.getCard("test", 25, "", )

 

Error:

DEBUG:suds.client:sending to (http://172.31.9.13:8080/cmdbuild/services/soap/Webservices)

message:

<?xml version="1.0" encoding="UTF-8"?>

<SOAP-ENV:Envelope xmlns:ns0="http://soap.services.cmdbuild.org" xmlns:ns1="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">

   <SOAP-ENV:Header>

      <wsse:Security mustUnderstand="true">

         <wsse:UsernameToken>

            <wsse:Username>test</wsse:Username>

            <wsse:Password>test</wsse:Password>

         </wsse:UsernameToken>

      </wsse:Security>

   </SOAP-ENV:Header>

   <ns1:Body>

      <ns0:getCard>

         <ns0:className>test</ns0:className>

         <ns0:cardId>25</ns0:cardId>

         <ns0:attributeList></ns0:attributeList>

      </ns0:getCard>

   </ns1:Body>

</SOAP-ENV:Envelope>

DEBUG:suds.client:headers = {'SOAPAction': u'""', 'Content-Type': 'text/xml; charset=utf-8'}

ERROR:suds.client:<?xml version="1.0" encoding="UTF-8"?>

<SOAP-ENV:Envelope xmlns:ns0="http://soap.services.cmdbuild.org" xmlns:ns1="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">

   <SOAP-ENV:Header>

      <wsse:Security mustUnderstand="true">

         <wsse:UsernameToken>

            <wsse:Username>test</wsse:Username>

            <wsse:Password>test</wsse:Password>

         </wsse:UsernameToken>

      </wsse:Security>

   </SOAP-ENV:Header>

   <ns1:Body>

      <ns0:getCard>

         <ns0:className>test</ns0:className>

         <ns0:cardId>25</ns0:cardId>

         <ns0:attributeList></ns0:attributeList>

      </ns0:getCard>

   </ns1:Body>

</SOAP-ENV:Envelope>

DEBUG:suds.client:http failed:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><soap:Fault><faultcode xmlns:ns1="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">ns1:InvalidSecurityToken</faultcode><faultstring>An invalid security token was provided (An error happened processing a Username Token "{0}")</faultstring></soap:Fault></soap:Body></soap:Envelope>

Traceback (most recent call last):

  File "test.py", line 26, in <module>

    card = client.service.getCard("test", 25, "", )

  File "build/bdist.linux-x86_64/egg/suds/client.py", line 542, in __call__

  File "build/bdist.linux-x86_64/egg/suds/client.py", line 602, in invoke

  File "build/bdist.linux-x86_64/egg/suds/client.py", line 649, in send

  File "build/bdist.linux-x86_64/egg/suds/client.py", line 702, in failed

  File "build/bdist.linux-x86_64/egg/suds/bindings/binding.py", line 265, in get_fault

suds.WebFault: Server raised fault: 'An invalid security token was provided (An error happened processing a Username Token "{0}")'

 

 

Does anyone know why?

Thanks

 

 

Dear Daniel,
 
unfortunately we are not able to give you support for Python. CMDBuild also supports plain passwords but it's not the default behavior and it can be enabled. You can edit the "auth.conf" file and set this property:
 
force.ws.password.digest=false
 
Best regards.
 
-- CMDBuild Team
 
Previously Daniel wrote:

From my digging, it appears that CMDBuild only accepts digest passwords. I have been playing with the code on this page (https://gist.github.com/copitux/5029872), and with a bit of massaging have it working. You just add that to your module, fix the syntax errors :-), and replace your call to UsernameToken() with UsernameDigestToken().

 

Unfortunately now I'm getting the error that was reported in http://www.cmdbuild.org/forum/forum-in-english/931364090. Suds/sax cannot parse the XML returned from CMDBuild.

 

Previously Qiming wrote:

Version 2.2.1

language  :Python

 

code:

#!/usr/bin/env python

# -*- coding:utf-8 -*-

from suds.wsse import *

from suds.client import Client

from suds.sax.text import Text

import logging

 

 

 

if __name__ == '__main__':

        USER="test"

        PASSWD="test"

        URL="http://172.31.9.13:8080/cmdbuild/services/soap/Webservices?wsdl"

 

    client = Client(URL)   

    logging.basicConfig(level=logging.INFO)

        logging.getLogger('suds.client').setLevel(logging.DEBUG)

 

 

    security = Security()

    token = UsernameToken('test', 'test')

    security.tokens.append(token)

    client.set_options(wsse=security)

 

    print client

    card = client.service.getCard("test", 25, "", )

 

Error:

DEBUG:suds.client:sending to (http://172.31.9.13:8080/cmdbuild/services/soap/Webservices)

message:

<?xml version="1.0" encoding="UTF-8"?>

<SOAP-ENV:Envelope xmlns:ns0="http://soap.services.cmdbuild.org" xmlns:ns1="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">

   <SOAP-ENV:Header>

      <wsse:Security mustUnderstand="true">

         <wsse:UsernameToken>

            <wsse:Username>test</wsse:Username>

            <wsse:Password>test</wsse:Password>

         </wsse:UsernameToken>

      </wsse:Security>

   </SOAP-ENV:Header>

   <ns1:Body>

      <ns0:getCard>

         <ns0:className>test</ns0:className>

         <ns0:cardId>25</ns0:cardId>

         <ns0:attributeList></ns0:attributeList>

      </ns0:getCard>

   </ns1:Body>

</SOAP-ENV:Envelope>

DEBUG:suds.client:headers = {'SOAPAction': u'""', 'Content-Type': 'text/xml; charset=utf-8'}

ERROR:suds.client:<?xml version="1.0" encoding="UTF-8"?>

<SOAP-ENV:Envelope xmlns:ns0="http://soap.services.cmdbuild.org" xmlns:ns1="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">

   <SOAP-ENV:Header>

      <wsse:Security mustUnderstand="true">

         <wsse:UsernameToken>

            <wsse:Username>test</wsse:Username>

            <wsse:Password>test</wsse:Password>

         </wsse:UsernameToken>

      </wsse:Security>

   </SOAP-ENV:Header>

   <ns1:Body>

      <ns0:getCard>

         <ns0:className>test</ns0:className>

         <ns0:cardId>25</ns0:cardId>

         <ns0:attributeList></ns0:attributeList>

      </ns0:getCard>

   </ns1:Body>

</SOAP-ENV:Envelope>

DEBUG:suds.client:http failed:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><soap:Fault><faultcode xmlns:ns1="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">ns1:InvalidSecurityToken</faultcode><faultstring>An invalid security token was provided (An error happened processing a Username Token "{0}")</faultstring></soap:Fault></soap:Body></soap:Envelope>

Traceback (most recent call last):

  File "test.py", line 26, in <module>

    card = client.service.getCard("test", 25, "", )

  File "build/bdist.linux-x86_64/egg/suds/client.py", line 542, in __call__

  File "build/bdist.linux-x86_64/egg/suds/client.py", line 602, in invoke

  File "build/bdist.linux-x86_64/egg/suds/client.py", line 649, in send

  File "build/bdist.linux-x86_64/egg/suds/client.py", line 702, in failed

  File "build/bdist.linux-x86_64/egg/suds/bindings/binding.py", line 265, in get_fault

suds.WebFault: Server raised fault: 'An invalid security token was provided (An error happened processing a Username Token "{0}")'

 

 

Does anyone know why?

Thanks