用户名密码令牌验证失败 - 在 Postman 中调用 SOAP 服务

问题描述 投票:0回答:1

我正在尝试使用带有以下 XML 正文的 POSTMAN 来调用 SOAP Web 服务。通过邮递员调用它后,我遇到身份验证问题:

xmlns:niec="http://www.xxxxxxx.com/ws/xxxxxxxCustservice/v1/xxxxxxxCustLookup"
    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">
    <soapenv:Header>
        <wsse:Security soapenv:mustUnderstand="1">
            <wsse:UsernameToken>
                <wsse:Username>username</wsse:Username>
                <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">password</wsse:Password>
                <wsse:Nonce>ZHNoYmFzZGE5OA==</wsse:Nonce>
                <wsu:Created>2024-02-01T14:07:00Z</wsu:Created>
            </wsse:UsernameToken>
            <wsu:Timestamp>
                <wsu:Created>2024-02-02T14:16:00Z</wsu:Created>
                <wsu:Expires>2024-02-02T14:21:00Z</wsu:Expires>
            </wsu:Timestamp>
        </wsse:Security>
    </soapenv:Header>
    <soapenv:Body>
        <niec:xxxxxxxCustLookupRequest>
            <niec:prnNum>819977777770</niec:prNum>
            <niec:versionNumber>1.0</niec:versionNumber>
        </niec:xxxxxxxCustLookupRequest>
    </soapenv:Body>
</soapenv:Envelope> 

我尝试使用相同的凭据通过 SOAP UI 工具调用相同的服务,但没有收到错误。在 POSTMAN 中我收到此错误:

<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
    <env:Header/>
    <env:Body>
        <env:Fault>
            <faultcode>env:Client</faultcode>
            <faultstring> com.sun.xml.wss.impl.WssSoapFaultException: Authentication of Username Password Token Failed; nested exception is com.sun.xml.wss.XWSSecurityException:   com.sun.xml.wss.impl.WssSoapFaultException: Authentication of Username Password Token Failed</faultstring>
        </env:Fault>
    </env:Body>
</env:Envelope>

这背后的原因是,当我能够通过 POSTMAN 调用此 SOAP 服务时,我将能够使用此 XML 正文将其用作我的 Java 代码中的 XML 字符串,其中我使用 REST 模板来调用这个 SOAP Web 服务..

java rest authentication soap postman
1个回答
0
投票

这有点猜测,但我怀疑您没有计算要在字段中传递的密码摘要值

<wsse:Password />
。我的理论是,SoapUI 在幕后为您执行此操作,但在邮递员中,您可能需要在预请求脚本中执行此操作。

根据UsernameToken规范,密码摘要必须根据以下算法计算:

Password_Digest = Base64 ( SHA-1 ( nonce + created + password ) )

你必须这样做,因为根据文档:

这有助于隐藏密码并为防止重放攻击提供基础

将此应用到您的情况,您需要:

  1. 将随机数、创建的值和密码值连接在一起
  2. 应用哈希
  3. 应用base64编码
  4. 使用结果作为您请求中的密码
© www.soinside.com 2019 - 2024. All rights reserved.