posts - 11,  comments - 14,  trackbacks - 0
          Webservice交互經常需要驗證用戶,用戶名和密碼的傳遞采用SOAPHeader傳遞不失為一種好辦法。在Axis1中設置很簡單:
          客戶端:
          ((org.apache.axis.client.Call) call).addHeader(new SOAPHeaderElement("Authorization","username",username));
          ((org.apache.axis.client.Call) call).addHeader(new SOAPHeaderElement("Authorization","password",password));

          經包裝后傳遞的內容如下
          <soapenv:Header>
            <ns1:username
             soapenv:actor="http://schemas.xmlsoap.org/soap/actor/next"
             soapenv:mustUnderstand="0" xsi:type="soapenc:string"
             xmlns:ns1="Authorization"
             xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
             admin
            </ns1:username>
            <ns2:password
             soapenv:actor="http://schemas.xmlsoap.org/soap/actor/next"
             soapenv:mustUnderstand="0" xsi:type="soapenc:string"
             xmlns:ns2="Authorization"
             xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
             1
            </ns2:password>
           </soapenv:Header>

          服務端通過Handler取得用戶名和密碼進行驗證:
          username = (String) messageContext.getRequestMessage().getSOAPEnvelope()
          .getHeaderByName("Authorization","username").getValue();
          password = (String) messageContext.getRequestMessage().getSOAPEnvelope()
          .getHeaderByName("Authorization","password").getValue();

          如果覺得這樣不安全,可雙方約定一種加密解密規則,將用戶名和密碼加密后進行傳輸。

          我曾試過使用如下方法,
          客戶端:
          ((org.apache.axis.client.Call) call).setUsername(username);
          ((org.apache.axis.client.Call) call).setPassword(password);

          包裝后傳遞內容(多了最后一句:Authorization: Basic emphZG1pbjox。Axis將用戶名和密碼經Base64加密后傳遞):
          POST /web/services/GenericServer HTTP/1.0
          Content-Type: text/xml; charset=utf-8
          Accept: application/soap+xml, application/dime, multipart/related, text/*
          User-Agent: Axis/1.4
          Host: localhost:8083
          Cache-Control: no-cache
          Pragma: no-cache
          SOAPAction: ""
          Content-Length: 807
          Authorization: Basic emphZG1pbjox

          服務端的Handle:
          username =messageContext.getUsername();
          password = messageContext.getPassword();

          這樣是沒問題,看起來更簡單。可惜調用部署在weblogic上的ws時,會被weblogic攔截,必須在weblogic安全域中配置相應的用戶才能通過驗證,這不是我們所需要的,通常我們有自己的用戶管理機制,調用WS的用戶也作為系統中的一個用戶納入我們的管理,而不是跟weblogic安全域用戶綁在一起。

          posted on 2008-07-18 13:18 jinn 閱讀(5947) 評論(1)  編輯  收藏 所屬分類: Jave/Webservice

          FeedBack:
          # re: Axis中用戶名、密碼傳遞
          2008-07-19 10:10 | 高手
          http://www.HelloCTO.com
          成千視頻,上萬文章,技術資料與您共享``  回復  更多評論
            

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          <2008年7月>
          293012345
          6789101112
          13141516171819
          20212223242526
          272829303112
          3456789

          常用鏈接

          留言簿(3)

          隨筆分類

          文章分類

          相冊

          網站鏈接

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 中卫市| 柘荣县| 新源县| 海原县| 娄底市| 黑龙江省| 德江县| 香河县| 方正县| 林州市| 来安县| 南和县| 无锡市| 长沙县| 内黄县| 呼伦贝尔市| 五河县| 巍山| 阳城县| 长兴县| 芜湖市| 大方县| 长宁县| 三原县| 灵山县| 甘肃省| 江口县| 光山县| 五台县| 渑池县| 庆城县| 绩溪县| 福泉市| 湾仔区| 宝山区| 金华市| 姜堰市| 尚志市| 鄂尔多斯市| 全南县| 大庆市|