|
|
Web Services using apache axis2 報告人:高明權 DATE :2010/05/29 Released V1.00 BLOG:http://tommykao.blogspot.com EMAIL : MCK6214@gmail.com
Web Services Agenda Background Case 01: Say Hello, pojo Case 02: File Upload & Download Case 03: Using the SoapMonitor module Case 04: SSL Transport Security Case 05: Message Level Security Case 06: Customized Module Case 07: Stateful Case 08: Clustering 2 著作人:高明權
Case 04: SSL Transport Security Sample code: webservices_workspace_03_A.zip 3 著作人:高明權
About SSL Transport Security 1/2 HTTP 不安全 由於 Web Services 調用與回傳資料的過程多經由 TCP/IP ,使用封包攔截工具(ex: Sniffer)就可以輕易獲得各種敏感資訊,介已達到入侵、破壞的可能。 Transport Layer Security 加密傳輸通道可有效防堵封包攔截工具,資訊放入通道前會被加密過,即便封包被攔截,也無法有效解密,從而確保資安。 著作人:高明權 4
About SSL Transport Security 2/2 HTTPS 安全性高 HTTPS加密傳輸通道主要是透過 SSL (Secure Sockets Layer)方式建立,HTTPS 是一種Transport Layer Security。 結合基本驗證(使用者帳號/密碼驗證) 將可提高服務的安全性 用PKI 建立信任關係 單向:Client 端信任 Server 端為基礎,Client 取得 Server 端的公鑰。 雙向:Client 端與Server 端建立互信,相互取得對方的公鑰。 著作人:高明權 5
SSL (Secure Sockets Layer) 著作人:高明權 6
SSL handshake with two way authentication 資料來源:http://commons.wikimedia.org/wiki/File:SSL_handshake_with_two_way_authentication_with_certificates.svg 著作人:高明權 7
Apache Rampart Rampart is the security module of Axis2. With Rampary module, you can secure Axis2 web services for authentication, integrity, confidentiality and non - repudiation. Rampart supports the following specifications WS - Secure Conversation - February 2005 WS - Trust - February 2005 WS - Trust - WS-SX WS - Security 1.0 WS - Security 1.1 WS - Security Policy - 1.1 – July 2005 WS - Security Policy - 1.2 SAML 1.1 SAML 2.0 – Issuance 著作人:高明權 8 資料來源:http://ws.apache.org/rampart
環境配置 – Apache Rampart Rampart 是 AXIS2 的安全擴充模組 下載並安裝 Apache Rampart 從 RAMPART 官方網站下載 網址: http://ws.apache.org/rampart/ 解壓縮 rahas-1.5.mar, rampart-1.5.mar 模組至 <<Tomcat 安裝路徑 >> \webapps\axis2\WEB-INF\modules 解壓縮 rampart 相關 lib 至 <<Tomcat 安裝路徑 >>\webapps\axis2\WEB-INF\lib 重新啟動 TOMCAT 進入AXIS2管理介面 網址: http://localhost:8080/axis2/ 確認 Rampart 模組安裝成功 著作人:高明權 9
環境配置 – Keystore 建立Server 端的非對稱金鑰(公鑰、私鑰) 在 Tomcat 當中建立 Keystore 目錄 用 JDK 的 keytool 命令產生金鑰 在 Server 端執行 Keytool 指令產生金鑰,並將結果放到 Keystore 目錄當中 指令:<<JDK安裝路徑 >>\bin\keytool -genkey -alias tomcat -keyalg RSA -keystore <<Tomcat 安裝路徑 >>\keystore 確認 TOMCAT 的 HTTPS 配置 編輯 <<Tomcat 安裝路徑 >>\ \conf\server.xml 檔案,設定 https 當中的keystoreFile & keystorePass 參數 重新啟動 TOMCAT ,連線到以下網址確認 HTTPS 配置成功 網址: https://localhost:8443 著作人:高明權 10
3rd Web Service Project 建立 Java 專案 選單[File]/[New]/[Other…] 選擇[Java Project]/[Next] 輸入專案名稱後點選[Finish] 專案名稱: WebServicesTutorial 滑鼠右鍵[New]/[Folder] 建立 META-INF 目錄 著作人:高明權 11
StockQuote Service Classes IStockQuote.class package sample.webservice. case04; public interface IStockQuote { /** * Get stock quote for a company Symbol * @param symbol * @return */ public double getStockQuote(String symbol); } StockQuoteService.class package sample.webservice.case04; public class StockQuoteService implements IStockQuote { /** * Default constructor. */ public StockQuoteService() { } public double getStockQuote(String symbol) { double result = 0.0; if ("goog".equalsIgnoreCase(symbol)) result = 490; if ("aapl".equalsIgnoreCase(symbol)) result = 257; if ("msft".equalsIgnoreCase(symbol)) result = 25.8; return result; } } 著作人:高明權 12
declare the StockQuote Web Service META-INF\Services.xml <serviceGroup> <!-- defines the name of the service. Axis2 uses the name of the service to create the endpoint address of the service as http://localhost:<port>/axis2/services/<nameofservice> So for the StockQuoteService, the service endpoint will be http://localhost:8080/axis2/services/StockQuoteService --> <service name="StockQuoteService" scope="application"> <description>Stock Quote Service</description> <!-- ServiceClass parameter specifies the service implementation class. --> <parameter name="ServiceClass">sample.webservice.case04.StockQuoteService</parameter> <messageReceivers> <messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-out" class="org.apache.axis2.rpc.receivers.RPCMessageReceiver" /> <messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-only" class="org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver" /> </messageReceivers> <!-- use rampart module --> <module ref="rampart" /> </service> </serviceGroup> 著作人:高明權 13
Pack the StockQuote Web Service 打包 StockQuote Web Service 滑鼠右鍵[Export] 選定 [JAR file]/[Next] 指定檔案輸出路徑 AXIS2路徑: <<Tomcat 安裝路徑 >>\ \webapps\axis2\WEB-INF\services\ WebServicesTutorial.aar 注意: 包名必須以 .aar 結尾 須含 META-INF\services.xml 著作人:高明權 14
Deploy the StockQuote Web Service 佈署 StockQuote Web Service 連線到 AXIS2 管理介面 網址: http://localhost:8080/axis2/axis2-admin/ 上傳 Web Service 檔案包 (*.aar ),選擇[Tools]/[Upload Service] 指定檔案並點選[Upload] 連線並確認 StockQuote 服務已開放 網址: http://localhost:8080/axis2/services/listServices 查看 StockQuote Web Service 取得該 Web Service 的描述 (WSDL) http://<host>:<port>/axis2/services/<ServiceName>?wsdl 本例為: http://localhost:8080/axis2/services/StockQuoteService?wsdl 著作人:高明權 15
Test the StockQuote Web Service 1/2 直接連線測試 (HTTP) 經由瀏覽器連線測試,連線方式為 http://<host>:<port>/axis2/services/<ServiceName>/<OperationName>?<parameters_key_pair> 本例為: http://localhost:8080/axis2/services/StockQuoteService/getStockQuote?symbol=goog 直接連線測試 (HTTPS) 經由瀏覽器連線測試,連線方式為 https://<host>:<port>/axis2/services/<ServiceName>/<OperationName>?<parameters_key_pair> 本例為: https://localhost:8443/axis2/services/StockQuoteService/getStockQuote?symbol=goog 著作人:高明權 16 正常情況下,透過 HTTPS 連線會出現類似的警告訊息,原因在於本金鑰為測試用途,正式對外服務前,應透過合法的 CA 機構申請金鑰。
Test the StockQuote Web Service 2/2 用 SoapUI 連線測試 建立新專案,選擇 [File]/[New soapUI Project] 專案名稱 : StockQuoteService WSDL路徑 : http://localhost:8080/axis2/services/StockQuoteService?wsdl 展開服務項目並著手編輯 soap request message 注意:送出soap request 之前,請選擇連線方式 https or http 送出 soap request message,並檢視回傳結果。 若採用 https 連線將可看到回傳結果當中包含了 SSL 相關訊息 著作人:高明權 17
參考資料 JAVA Cryptography Apache Rampart Knowledge Base 著作人:高明權 18
以上為基礎,務必照表操課 Know-How, ExAct, Knowledge
Summary: Case 04: SSL Transport Security (A)
| URL: |
No comments posted yet
Comments