liferay 6.2GA2 使用 Python suds 客户端进行 SOAP 认证
我在使用liferay 6.2的soap API时遇到了一些问题:我需要用python的suds客户端来搜索用户。
在liferay 6.1中,我用以下代码,运行得很好:
from suds.client import Client
c = Client('http://liferay62instance.domain.com/api/secure/axis/Portal_UserService?wsdl', username='liferayuser', password='liferaypassword')
c.service.getUserByScreenName(companyId=10154, screenName='user')
但是在liferay 6.2中,wsdl的链接变了,而且默认情况下不需要http认证,所以用以下代码就出错了:
from suds.client import Client
c = Client('http://liferay62instance.domain.com/api/axis/Portal_UserService?wsdl', username='liferayuser', password='liferaypassword')
c.service.getUserByScreenName(companyId=10154, screenName='user')
错误信息是:
Server raised fault: 'java.rmi.RemoteException: Authenticated access required'
还有服务器端的错误追踪信息:
14:50:45,030 ERROR [ajp-bio-9009-exec-8][UserServiceSoap:845]
java.lang.SecurityException: Authenticated access required
java.lang.SecurityException: Authenticated access required
你知道怎么在liferay 6.2中进行soap认证吗?
谢谢你的任何回答。
Jérôme.
1 个回答
0
最后,我通过使用HttpAuthenticated传输方式,解决了我的问题,这个方式来自suds.transport.http。
使用这个方式会在每个SOAP请求中添加一个新的头部Authorization,这个头部包含了用户名和密码的组合,并且是经过base64编码的。
下面是一个例子:
from suds.client import Client
from suds.transport.http import HttpAuthenticated
t = HttpAuthenticated(username='liferayuser', password='liferaypassword')
c = Client('http://liferay62instance.domain.com/api/axis/Portal_UserService?wsdl', transport=t)
result = c.service.getUserByScreenName(companyId=10154, screenName='user')