【问题标题】:Ruby - Savon web services authenticationRuby - Savon Web 服务身份验证
【发布时间】:2011-10-25 13:39:27
【问题描述】:

我正在尝试利用 ruby​​ gem Savon 连接到由 propertyware (http://propertyware.com/apidocs/Getting-Started) 提供的 Web 服务。我已经通过 SoapUI 成功连接到服务并执行了 echoString 请求。当我尝试通过 Ruby 执行相同操作时,我得到一个空用户身份验证错误。

这是我在 Ruby 中尝试过的...

require 'rubygems'
require 'savon'

client = Savon::Client.new do
  wsdl.document = 'http://propertyware.com/pw/services/PWServices?wsdl'
  wsse.credentials 'username', 'pwd'
end

response = client.request :web, :echo_string, :body => {:arg => "Hello world."} 

这会产生以下 xml...

<env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:web="http://propertyware.com/pw/services/PWServices" 
    xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" 
    xmlns:ins0="http://propertyware.com/pw/services/PWServices" 
    xmlns:ins1="http://criteria.soap.propertyware.com" 
    xmlns:ins2="urn:PWServices" 
    xmlns:ins3="http://soap.propertyware.com" 
    xmlns:ins4="http://xml.apache.org/xml-soap">
    <env: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>user</wsse:Username>
                <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">pwd</wsse:Password>
            </wsse:UsernameToken>
        </wsse:Security>
    </env:Header>
    <env:Body>
        <web:echoString>
            <arg>Hello world.</arg>
        </web:echoString>
    </env:Body>
</env:Envelope>

这是由 SoapUI 生成的 xml...

<soapenv:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
    xmlns:web="http://webservices" >
   <soapenv:Header>
      <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
         <wsse:UsernameToken wsu:Id="UsernameToken-1" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
            <wsse:Username>user</wsse:Username>
            <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">pwd</wsse:Password>
            <wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">R41mCRd+tY+xthhE/YISLQ==</wsse:Nonce>
            <wsu:Created>2011-10-25T09:52:40.220Z</wsu:Created>
         </wsse:UsernameToken>
      </wsse:Security>
   </soapenv:Header>
   <soapenv:Body>
      <web:echoString soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
         <arg xsi:type="xsd:string">?</arg>
      </web:echoString>
   </soapenv:Body>
</soapenv:Envelope>

一个明显的区别是 SoapUI 包含一个 nonce 键和一个 createdAt 时间戳。我不确定如何让 savon 在不消化身份验证的情况下做到这一点。 (而且这不起作用)。

我在 Web 服务方面并不是真正的 savoy - 任何指导将不胜感激。

另外 - 这是我尝试通过 savon 连接时的响应:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <soapenv:Body>
        <soapenv:Fault>
            <faultcode xmlns:ns1="http://xml.apache.org/axis/">ns1:Server.Unauthenticated</faultcode>
            <faultstring>User 'null' not authenticated (unknown user)</faultstring>
            <detail>
                <ns2:hostname xmlns:ns2="http://xml.apache.org/axis/">rcpppwwwapt012.realpage.com</ns2:hostname>
            </detail>
        </soapenv:Fault>
    </soapenv:Body>
</soapenv:Envelope>

TIA! 鲍勃

【问题讨论】:

    标签: ruby web-services soap savon


    【解决方案1】:

    尝试将 wsse 中的摘要设置为 true。这将指示 Savon 将 nonce 和 createdAt 添加到请求中:

    wsse.credentials 'username', 'pwd', :digest
    

    this object for more info的cmets

    【讨论】:

    • 感谢您的建议。不幸的是,正如我在问题中指出的那样,将摘要设置为 true 会加密密码,这不起作用。
    【解决方案2】:

    在 Savon 版本 2 中,您需要以下内容:

    client = Savon.client do
      wsdl 'https://webservice/theservice.wsdl'  
      wsse_auth("user", "pass", :digest)
    end
    

    【讨论】:

      【解决方案3】:

      我相信第一步是处理错误。

      <faultstring>User 'null' not authenticated (unknown user)</faultstring>
      

      您的凭据未传递给服务。

      【讨论】:

      • 是的。这就是这个问题要问的——为什么会这样?该请求看起来像是发送给我的 - 不知道为什么服务器不承认这一点。
      猜你喜欢
      • 1970-01-01
      • 2012-04-18
      • 1970-01-01
      • 1970-01-01
      • 2016-06-10
      • 2013-06-22
      • 2020-11-13
      • 2013-11-12
      • 2023-03-24
      相关资源
      最近更新 更多