我尝试使用usernameToken调用合作伙伴WS。我使用php5.2.x下的ws02 wsf_2.0.0和它的岩石。现在我们希望在基于php5.3的不同解决方案上进行迁移,幸运的是,ws02提供了一个与php5.3兼容的2.1.0标记。我花时间阅读这个新版本的新特性和文档,特别是关于usernameToken的内容。我理解这个版本通过证书和私钥对usernameToken使用签名。我猜是AsymetricTransportBinding政策的b/c。在我的例子中,我不想通过证书或其他方式签署任何东西。我还读到,ws02在单独的xml文件中提供了一种后备功能,以避免任何签名。
在阅读了许多帖子,论坛后,我需要社区的一些帮助,我完全被困住了。
下面是在php5.3-WSF2.1.0(使用HTTP )中请求WS的代码
$policy = new \WSPolicy( $policy ); ( $policy is the one from the call_back folder with a file_get_contents() )
$security = new \WSSecurityToken( array(
'user' => 'my_username',
'password' => 'my_password',
'passwordType' => 'Digest',
'ttl' => '300'
));
$this->oSoapClient = new \WSClient( array(
wsdl: http://www.xxx.xx/comparatorservices/CalculationService?WSDL
to: http://www.xxx.xx/comparatorservices/CalculationService
useWSA: true
useSOAP: 1.1,
policy: $policy,
securityToken: $security
));
$proxy = $this->oSoapClient->getProxy();
$response = $proxy->wykonajKalkulacje( $MySuperRequestObject );
在这一步:
现在,我从调试日志中捕捉到以下内容:
[Wed Jul 25 05:22:53 2012] [error] rampart_in_handler.c(91) [rampart]SOAP header cannot be found.
[Wed Jul 25 05:22:53 2012] [error] phase.c(224) Handler RampartInHandler invoke failed within phase Security
[Wed Jul 25 05:22:53 2012] [error] engine.c(657) Invoking phase Security failed
[Wed Jul 25 05:22:53 2012] [error] engine.c(262) Invoking operation specific phases failed for operation __OPERATION_OUT_IN__
[Wed Jul 25 05:22:53 2012] [error] /home/agruet/08_KRK_sources/wso2-wsf-php-src-2.1.0/src/wsf_wsdl.c(1226) [wsf_wsdl] Response envelope not found
因此,我的第一个想法是嗅探流量,特别是工作( wsf_2.0.0 / php5.2.x )和中断( wsf_2.1.0 / php5.3 )之间的SOAP头。
这是2.0.0 (工作)
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header>
<wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<wsse:UsernameToken xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsse:Username>my_username</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">
hashed(my_password)
</wsse:Password>
<wsse:Nonce>hashed</wsse:Nonce>
<wsu:Created>2012-07-26T20:40:26.991Z</wsu:Created>
</wsse:UsernameToken>
</wsse:Security>
</soapenv:Header>
和2.1.0 (不工作/断裂)
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header>
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" soapenv:mustUnderstand="1">
<wsse:UsernameToken xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsse:Username>my_username</wsse:Username>
<wsse:Password
Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">hashed(my_password)</wsse:Password>
<wsse:Nonce>hashed</wsse:Nonce>
<wsu:Created>2012-07-25T00:44:56.758Z</wsu:Created>
</wsse:UsernameToken>
</wsse:Security>
</soapenv:Header>
如您所见,唯一的区别来自wsse:Security命名空间。(缺失xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/“)
就这样..。
根据调试日志检查第91行的rampart_in_handler.c时说:
soap_header = axiom_soap_envelope_get_header(soap_envelope, env);
if(!soap_header)
{
/*No SOAP header, so no point of proceeding. FAIL*/
AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "[rampart]SOAP header cannot be found.");
return AXIS2_FAILURE;
}
意思是是的..。soap_header是假的。但是为什么呢?有什么聪明的人来解释出什么事了吗?
注1:我检查了从工作中发送给合作伙伴WS的策略( 2.0.0 ),它似乎使用了AsymetricBinding .wich在2.0.0中很奇怪,我们没有提供任何证书或密钥。
注2:我还尝试在经典的WSPolicy对象数组params中使用签名的用户名标记--我创建了一个x509证书和私钥,然后使用函数加载这些文件,并使用数组params将其加载到WSSecurity构造函数中.但是我收到同样的错误/嗅探是一个痛苦的b/c数据被加密或类似的东西(在这种方式看来是正常的)
nota 3:目前在Ubuntu10.04-3LTS上使用apt-get预编译的php包进行了测试。
救命啊!
发布于 2012-07-28 12:49:42
我终于发现了这个问题,我修复了rampart_in_handler.c:91
问题来自于回应而不是请求..。我通过tcp嗅探器进行了检查,来自合作伙伴WS的响应没有任何soap:Header。
无论是否符合标准,它的上一个版本( 2.0.0 )都在工作。所以我决定稍微修改一下rampart_in_handler.c文件中的代码,以便在缺少soap头的情况下返回一个成功的.
在我看来,如果我错了请纠正我:
对soapHeader响应的测试当然是添加了asymetricBinding传输的b/c和新签名的usernametoken情况。但是,如果我们想使用usernametoken而不进行签名(通过基本的policy.xml )和,则响应是在没有任何soap:Header的情况下进行的;那么,rampart将始终返回一个失败.
此外,我还分析了脚本/文件夹中有关wsf处理响应的方式的php代码,并在这个文件上看到:wsf_wsdl.php
,函数wsf_process_response()
:
if($response_header_string && !empty($response_header_string)) {
$header_dom = new DomDocument();
$header_dom->preserveWhiteSpace = FALSE;
$header_dom->loadXML($response_header_string);
}
在php端,当收到数据时,wsf/php假设没有任何soapHeader.(如果soapHeader丢失了,就不会失败)超级奇怪!?
最后但并非最不重要的是,我在wsf_wsdl_serialization.php
和wsf_wsdl_deserialization.php
文件中发现了一个奇怪的bug。
例如,如果您计划用这样的字符串发送和/或接收params/值:
"110% Sigma of something"
它将失败,并在序列化/非序列化过程中创建分段错误!
现在我在想为什么?但在第一次看到,肯定,"110%的Sig..“包含"% S“,它很接近于”%s“.
我想这个bug就是这里提到的那个:
serialization.php---td24329956.html
如果我用D来换S或者别的什么都行.
好痛..。
https://stackoverflow.com/questions/11687135
复制相似问题