Savon Security 中的 mustUnderstand="1" Header
mustUnderstand="1" in Savon Security Header
服务应该是这样的(来自 Soap UI):
<wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsse:UsernameToken wsu:Id="UsernameToken-044848C648B0DCCFBC14248931953381">
<wsse:Username>26613</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">h3hzoxJgSNIrNsJTc8gGwdNGhe0=</wsse:Password>
<wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">JvR9+Aefno3PVz++ik/47w==</wsse:Nonce>
<wsu:Created>2015-02-25T19:39:55.336Z</wsu:Created>
</wsse:UsernameToken>
</wsse:Security>
这里是 savon 生产的产品:
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="UsernameToken-1">
<wsse:Username>26613</wsse:Username>
<wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">NmU4NWNiYWIxM2M0ZmYyN2IxZjJiNGQ0MGZmZDJkNjJiODJmNmM5OQ==</wsse:Nonce>
<wsu:Created>2015-02-25T16:55:40Z</wsu:Created>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">lr8M7oMCjEsh7Maj07AyW4CoTlE=</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
我注意到有一点不同,那就是 mustUnderstand 行。我试过这样添加:
client = Savon.client(
wsdl: 'gofish?wsdl',
pretty_print_xml: true,
log: true,
log_level: :debug,
env_namespace: :soapenv,
soap_header: {'wsse:Security' => 'mustUnderstand="1"'}
)
但这会生成以下内容:
<wsse:Security>mustUnderstand="1"</wsse:Security>
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
这不是我想要的。关于如何像 SoapUI 那样进入 wsse:Security 元素有什么想法吗?
编辑:
根据 Steffen 的建议,我得到以下结果:
<soapenv:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:cmn="http://www.sircon.com/WebServices/services/OnboardingServices.wsdl" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" soapenv:mustUnderstand="1">
<soapenv:Header>
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="UsernameToken-1">
<wsse:Username>26613</wsse:Username>
<wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">NTcyN2QyNjliYmMxZjg2Yjc2YjA0MTY0NjE5MjdjZjQ4ZGY0YzlhYQ==
</wsse:Nonce>
<wsu:Created>2015-02-25T21:28:53Z</wsu:Created>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">h8Qfcn6gA4swa/l+LmJR+RdCSto=</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</soapenv:Header>
<soapenv:Body>
<cmn:RecruiterOnboardingRequest>
<some>key</some>
<and>another one</and>
</cmn:RecruiterOnboardingRequest>
</soapenv:Body>
</soapenv:Envelope>
编辑 2:
在此处就此问题开了一张票:https://github.com/savonrb/savon/issues/667。请随时查看以了解更多信息。
我认为您需要在客户端中定义名称空间,例如。
client = Savon.client(
wsdl: 'gofish?wsdl',
pretty_print_xml: true,
log: true,
log_level: :debug,
env_namespace: :soapenv,
namespaces: {'soapenv:mustUnderstand' => "1"}
)
您可能还必须列出您需要的所有其他命名空间。
你可以尝试一些疯狂的事情。转到 gem 目录并找到该文件
...akami-1.2.2/lib/akami/wsse.rb
从
更改第 158 行
:attributes! => { "wsse:Security" => { "xmlns:wsse" => WSE_NAMESPACE } }
到
:attributes! => { "wsse:Security" =>
{ "mustUnderstand" => "1",
"xmlns:wsse" => WSE_NAMESPACE} }
这不太好,但它可能有用
服务应该是这样的(来自 Soap UI):
<wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsse:UsernameToken wsu:Id="UsernameToken-044848C648B0DCCFBC14248931953381">
<wsse:Username>26613</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">h3hzoxJgSNIrNsJTc8gGwdNGhe0=</wsse:Password>
<wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">JvR9+Aefno3PVz++ik/47w==</wsse:Nonce>
<wsu:Created>2015-02-25T19:39:55.336Z</wsu:Created>
</wsse:UsernameToken>
</wsse:Security>
这里是 savon 生产的产品:
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="UsernameToken-1">
<wsse:Username>26613</wsse:Username>
<wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">NmU4NWNiYWIxM2M0ZmYyN2IxZjJiNGQ0MGZmZDJkNjJiODJmNmM5OQ==</wsse:Nonce>
<wsu:Created>2015-02-25T16:55:40Z</wsu:Created>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">lr8M7oMCjEsh7Maj07AyW4CoTlE=</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
我注意到有一点不同,那就是 mustUnderstand 行。我试过这样添加:
client = Savon.client(
wsdl: 'gofish?wsdl',
pretty_print_xml: true,
log: true,
log_level: :debug,
env_namespace: :soapenv,
soap_header: {'wsse:Security' => 'mustUnderstand="1"'}
)
但这会生成以下内容:
<wsse:Security>mustUnderstand="1"</wsse:Security>
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
这不是我想要的。关于如何像 SoapUI 那样进入 wsse:Security 元素有什么想法吗?
编辑:
根据 Steffen 的建议,我得到以下结果:
<soapenv:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:cmn="http://www.sircon.com/WebServices/services/OnboardingServices.wsdl" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" soapenv:mustUnderstand="1">
<soapenv:Header>
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="UsernameToken-1">
<wsse:Username>26613</wsse:Username>
<wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">NTcyN2QyNjliYmMxZjg2Yjc2YjA0MTY0NjE5MjdjZjQ4ZGY0YzlhYQ==
</wsse:Nonce>
<wsu:Created>2015-02-25T21:28:53Z</wsu:Created>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">h8Qfcn6gA4swa/l+LmJR+RdCSto=</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</soapenv:Header>
<soapenv:Body>
<cmn:RecruiterOnboardingRequest>
<some>key</some>
<and>another one</and>
</cmn:RecruiterOnboardingRequest>
</soapenv:Body>
</soapenv:Envelope>
编辑 2:
在此处就此问题开了一张票:https://github.com/savonrb/savon/issues/667。请随时查看以了解更多信息。
我认为您需要在客户端中定义名称空间,例如。
client = Savon.client(
wsdl: 'gofish?wsdl',
pretty_print_xml: true,
log: true,
log_level: :debug,
env_namespace: :soapenv,
namespaces: {'soapenv:mustUnderstand' => "1"}
)
您可能还必须列出您需要的所有其他命名空间。
你可以尝试一些疯狂的事情。转到 gem 目录并找到该文件 ...akami-1.2.2/lib/akami/wsse.rb
从
更改第 158 行:attributes! => { "wsse:Security" => { "xmlns:wsse" => WSE_NAMESPACE } }
到
:attributes! => { "wsse:Security" =>
{ "mustUnderstand" => "1",
"xmlns:wsse" => WSE_NAMESPACE} }
这不太好,但它可能有用