實作自訂安全演算法

您可以實作可在 WSDL 安全編輯器中使用的自訂安全 Java™ 介面,以針對 SOAP 安全設定檔來定義自己的安全演算法。利用自訂安全演算法,您可以實作專有的安全演算法,以便在傳送訊息內容之前及接收訊息內容之後,轉換 XML。

開始之前

產品會隨附自訂安全介面和包含它的 JAR 檔,並放在 com.ibm.rational.ttt.common.models.core 外掛程式的 customsecuritydefinition 資料夾中。您需要這些介面,才能建立自己的演算法。如果您使用 IBM® Rational® Performance TesterIBM Rational Service Tester for SOA Quality,請參閱利用自訂程式碼來延伸測試執行,以取得有關利用 Java 程式碼來延伸測試功能的相關資訊。

程序

  1. 在測試導覽器或專案瀏覽器的 Web 服務測試專案資料夾中,建立新的 Java 類別。
  2. 使用下列介面,在 Java 中實作安全演算法:
    /**
    * ***************************************************************
    * IBM Confidential
    * 
    * (c) Copyright IBM Corporation. 2008. All Rights Reserved. * 
    * The source code for this program is not published or otherwise
    * divested of its trade secrets, irrespective of what has been
    * deposited with the U.S. Copyright Office.
    * *************************************************************** 
    * 
    */
    
    package com.ibm.rational.test.lt.models.wscore.datamodel.security.xmlsec;
    
    import java.util.Properties;
    import org.w3c.dom.Document;
    
    
    public interface ICustomSecurityAlgorithm {
    	
    	/**
    	 	 * The following methods can be used in both case:
    	 	 * Execution in the workbench and execution of the test.
    	 */
    	
    	
    	/**
    	 	 * Called to process de Document that is sent over a transport.
    	 	 * @param subject
    	 */
    		void process(Document subject);
    	/**
    	 	 * Called to un process a document that is received from a server.
    	 	 * @param subject
    	 */
    		void unProcess(Document subject);
    	
    	/**
    	 	 * Properties defined in the UI of the CustomSecurityAlgorithm.
    	 	 * @param map
    	 */
    		void setProperties(Properties map);
    	
    	/**
    	 	 * The following methods can only be used in terms of cast to test service interface,
    	 	 * or in terms of access to the previous XML  information, when the jar containing
    	 	 * the custom security algorithm is deployed in the performance test project. In
    	 	 * this case you cannot use the algorimth directly from the workbench.
    	 */
    	
    	/**
    	 	 * This object corresponds to the ITestExecutionService object.
    	 	 * This applies only to an algorithm that must link to the execution of the test.
    	 	 * If you plan to use this object you will need to deploy the jar containing the
    	 	 * implementation into your performance test project and not directly into the JRE.
    	 * 
    	 	 * In case of a need of the previous xml document received from the execution you can 
    	 	 * obtain the value using:
    	 	 * IDataArea area = ((ITestExecutionService)executionObject).findDataArea(IDataArea.VIRTUALUSER);
    	 	 *String previousXML = (String) area.get("PREVIOUS_XML"); //$NON-NLS-1$
    	 * 
    	 */
    		void setExecutionContext(Object executionObject);

    將 XML 傳送給伺服器之前,process 方法會先修改 XML。

    在收到伺服器傳來的 XML 之後,unprocess 方法會修改該 XML。

    setProperties 方法會擷取在安全編輯器中針對這個自訂安全介面所定義的任何內容。

    在測試期間,會使用 ITestExecutionServices 物件來呼叫 setExecutionContext 方法,此物件對應至使用這個自訂安全介面的訊息。

  3. 自訂安全介面可以在 Web 服務的「WSDL 安全編輯器」中使用,或在 XML 呼叫元素的本端 XML 安全標籤中使用。
    • 如果您正在測試 WSDL 型 Web 服務,請在測試導覽器或專案瀏覽器中,用滑鼠右鍵按一下 WSDL 檔,以開啟 WSDL 安全編輯器,然後選取安全演算法頁面;接著,在所選安全演算法堆疊的詳細資料之下,按一下新增 > 自訂安全演算法
    • 如果您正在測試 XML 呼叫,請在測試編輯器中開啟 XML 呼叫元素,選取本端 XML 安全標籤,然後按一下新增 > 自訂安全演算法
  4. 在自訂安全中,按一下瀏覽類別,選取自訂安全演算法的類別名稱,例如 ICustomSecurityAlgorithm
  5. 為自訂安全演算法,輸入一個演算法名稱
  6. 在內容清單中,使用新增移除編輯,指定您自訂安全演算法中 setProperties 方法所使用的任何內容。

下一步

儲存安全配置或呼叫元素之後,「Web 服務通訊協定資料」視圖會顯示安全演算法對 Web 服務之 XML 資料的影響。

意見