kingpub

          海內存知己,博客若比鄰

           

          運用Web Services安全機制對SOAP消息加密(3)

          2.4 WEBSPHERE IICE WEB SERVICE SOAP消息安全實現細節

            A. 配置

            WebSphere IICE Web Services安全機制的配置工作是由客戶端和服務器端兩部分組成的。就如下面的配置文件實例說描述的一樣,SOAP消息會在它被發送到目標服務器之前分別被不同的句柄簽名和加密。相對應的,它也會在服務器端被驗證和解密。

            列表2:AXIS客戶端配置文件示例

          <globalConfiguration>
          ????? <requestFlow>????
          ????? <handler
          ?? type="java:com.venetica.vbr.webservices.handler.X509SignHandler"/>
          ????? <handler
          ?? type="java:com.venetica.vbr.webservices.handler.EncryptHandler"/>?????
          ?? </requestFlow>??
          ?? <responseFlow>
          ??? <handler
          ?type="java:com.venetica.vbr.webservices.handler.X509SignHandler"/>
          ??? <handler
          ?type="java:com.venetica.vbr.webservices.handler.DecryptHandler"/>
          ?? </responseFlow>??
          ?</globalConfiguration>

            服務器端的配置文件和客戶端的配置文件非常相像。

            B. 簽名和加密/解密過程:

            SOAP消息的簽名和加密/解密過程如圖2所示:

            圖2:SOAP消息的簽名和加密/解密過程

            列表3: XML簽名示例代碼

          public Message signSOAPEnvelope(SOAPEnvelope unsignedEnvelope) throws Exception
          ?? {? // WSSignEnvelope signs a SOAP envelope according to the
          ????? // WS Specification (X509 profile) and adds the signature data
          ????? // to the envelope.
          ????? WSSignEnvelope signer = new WSSignEnvelope();
          ????? String alias = "username";
          ????? String password = "password";
          ????? signer.setUserInfo(alias, password);
          ????? Document doc = unsignedEnvelope.getAsDocument();????
          ????? Document signedDoc = signer.build(doc, crypto);
          ????? // Convert the signed document into a SOAP message.
          ????? Message signedSOAPMsg =???????? (org.apache.axis.Message)AxisUtil.toSOAPMessage(signedDoc);
          ????? return signedSOAPMsg;
          ?? }

            列表3顯示了XML簽名的過程:首先得到SOAP信封,接下來是獲得用戶證書信息、產生簽名對象,然后是用此簽名對象對信封進行簽名,最后是從被簽名的信封中產生新的SOAP消息。

            列表4:XML加密示例代碼

          public Message encryptSOAPEnvelope(
          ????? SOAPEnvelope unsignedEnvelope, Message axisMessage)
          ????? throws Exception
          ?? {
          ????? WSEncryptBody encrypt = new WSEncryptBody();
          ????? // build the encrypted SOAP part
          ????? Document doc = unsignedEnvelope.getAsDocument();
          ????? Document encryptedDoc = encrypt.build(doc, crypto);
          ????? // Convert the document into a SOAP message
          ????? Message encryptedMsg =
          ???????? (Message)AxisUtil.toSOAPMessage(encryptedDoc);
          ????? // Retrieve the desired SOAP part
          ????? String soapPart = encryptedMsg.getSOAPPartAsString();
          ????? ((SOAPPart)axisMessage.getSOAPPart()). setCurrentMessage(soapPart, SOAPPart.FORM_STRING);
          ????? encryptedDoc =axisMessage.getSOAPEnvelope().getAsDocument();
          ????? // Convert the document into a SOAP message
          ????? Message encryptedSOAPMsg = Message)AxisUtil.toSOAPMessage(encryptedDoc);
          ????? return encryptedSOAPMsg;
          ?? }

          posted on 2006-06-08 18:01 xiaofeng 閱讀(279) 評論(0)  編輯  收藏


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


          網站導航:
           

          導航

          統計

          常用鏈接

          留言簿(2)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          收藏夾

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 乐亭县| 丹寨县| 昌吉市| 五莲县| 德钦县| 海南省| 伊通| 武强县| 石台县| 莱州市| 洱源县| 博乐市| 五家渠市| 青田县| 通化市| 临汾市| 灵寿县| 类乌齐县| 武鸣县| 平顶山市| 星子县| 汽车| 荣成市| 灌云县| 曲水县| 垦利县| 东丽区| 三穗县| 鄂托克前旗| 梓潼县| 江阴市| 万载县| 遂溪县| 台南市| 和林格尔县| 南溪县| 隆安县| 辰溪县| 怀集县| 泰安市| 扬州市|