使用gSOAP开发实例(8) Phase 1 完结篇 自定义header实现用户名令牌认证(Usernametoken Authentication)

上一节介绍了 怎样实现基本认证 (Basic Authentication ,以下简称 basic 方式 ) ,望文生义,也就是最简单的用户验证方式,本节稍微深入一些,介绍用户名令牌认证 (Usernametoken Authentication ,以下简称 usernametoken 方式 )

 

Usernametoken 方式与 basic 方式不同的地方,在于后者会把用户名和密码以摘要 (digest) 的形式,置于 HTTP 信息头,而前者则把用户名以明文的形式、密码以明文或者摘要的形式,嵌入到一段 XML 文本中,再置于 SOAP 消息头当中。

 

如果使用 soapUI 调试客户端程序的话,会发现以下是 basic 方式发出的完整的 SOAP 消息:

POST https://test2.r-secure.com/Services/ECHO HTTP/0.9

Content-Type: text/xml;charset=UTF-8

SOAPAction: ""

User-Agent: Jakarta Commons-HttpClient/3.1

Content-Length: 292

Authorization: Basic VkYtSEstbVNNST0OdlR42EMZaD1BMyE=

Host: test2.r-secure.com

Cookie: $Version=0; MSP2LB=test2.test2f02; $Path=/

 

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:echo="http://echo.rsecure.com/ECHO">

   <soapenv:Header/>

   <soapenv:Body>

      <echo:echo>

         <echo:EchoMessage>hello</echo:EchoMessage>

      </echo:echo>

   </soapenv:Body>

</soapenv:Envelope>

 

以下是 usernametoken 方式发出的完整的 SOAP 消息:

POST https://test.r-secure.com/4.0/services/SecureEcho HTTP/1.1

Content-Type: text/xml;charset=UTF-8

SOAPAction: ""

User-Agent: Jakarta Commons-HttpClient/3.1

Host: test.r-secure.com

Content-Length: xxx

 

<soapenv:Envelope xmlns:echo="http://echo.ws.rsecure.com" 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">

         <wsse:UsernameToken wsu:Id="UsernameToken-32870670" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">

            <wsse:Username>roy</wsse:Username>

            <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">liang</wsse:Password>

            <wsse:Nonce>LX4gh+njbEtCNAtkWkXDYA==</wsse:Nonce>

            <wsu:Created>2010-08-11T06:02:25.874Z</wsu:Created>

         </wsse:UsernameToken>

      </wsse:Security>

      <echo:customerId>G06164</echo:customerId>

   </soapenv:Header>

   <soapenv:Body>

      <echo:sendEcho>

         <echo:message>hello</echo:message>

      </echo:sendEcho>

   </soapenv:Body>

</soapenv:Envelope>

 

其中,加粗部分表示两者的主要区别,红字部分表示各自必不可少的元素。

 

由此可以看出, usernametoken 方式的特点,是在 SOAP header 中加入一个 Security 标签,把 usernametoken 信息放在这个 Security 标签里。至于 header 里的另外一个 customerId 标签,是该应用自身的额外要求。

 

 

gSOAP 实现 basic

  • 1
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 8
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值