練習 4: Web サービスにおける WSIT セキュリティ

Expected duration: 20 minutes

Introduction:

This exercise explains how to configure a secure Web Service.

Background Information:

Until now, Web Services have relied on transport-based security such as SSL to provide point-to-point security. WSIT implements WS-Security so as to provide interoperable message content integrity and confidentiality, even when messages pass through intermediary nodes before reaching their destination endpoint. WS-Security as provided by WSIT is in addition to existing transport-level security, which may still be used.

WSIT also enhances security by implementing WS-Secure Conversation, which enables a consumer and provider to establish a shared security context when a multiple-message-exchange sequence is first initiated. Subsequent messages use derived session keys that increase the overall security while reducing the security processing overhead for each message.

Further, WSIT implements two additional features to improve security in Web Services:

WSIT implements these features in such a way as to ensure that Web Service binding security requirements, as defined in the WSDL file, can interoperate with and be consumed by WSIT and WCF endpoints.

WSIT Web サービスをセキュアにする

手順:

  1. 前回の練習で使用した Web サービス クライアント と サービス アプリケーション もしくは <lab_home>\exercises\exercises4 から
    NetBeans サンプル プロジェクト CatalogServiceCatalogClient をオープンします



  2. NetBeans プロジェクト ナビゲータで CatalogService に行き、プロジェクトの下の Web サービスノードを展開し、
    CatalogService Web サービス ノードで右クリックして、「Web サービス属性を編集」を選択します。



  3. NetBeans は Web サービス属性編集ウィンドウをオープンします。サービス品質タブは開かれています。 CatalogPortBinding 下の
    セキュアサービスにチェックを入れ、他のチェックボックスはデフォルト設定のままにして置いてください。

  4. さて、サービスを SOAP メッセージがサービスのパブリック X.509 証明書キーで XML-暗号化されたものだけ受け付けるように
    構成します。このサービスはクライアントのパブリック 証明書キーで暗号化されたメッセージで答えます。セキュリティメカニズムは
    リストボックスから「相互証明書セキュリティー」を選択します。

  5. 「開発のデフォルトの使用」チェックボックスはチェックを入れます。もし、独自のサービスとクライアントを開発したいならば、
    チェックを入れないで、証明書を GlassFish にインポートした後に選択します。了解ボタンをクリックします。



  6. CatalogService プロジェクトを右クリックし、配備を選択します。



  7. メッセージ交換を保護するサービスを作成することは今までの手順で全てです。サービスが生成した WSDL を覗いて見ましょう。
    ブラウザで http://localhost:8080/CatalogService/CatalogService?wsdl. の URL を使用します。 Web ページのトップにサービス WSDL
    に追加されたいくつかのセキュリティポリシーが見られます。

    Display WSDL

WSIT Web サービス クライアント をセキュアにする

手順:

  1. クライアントを構成します。クライアントはサービスの WSDL からセキュリティ要求条件を拾い上げます。更に、どの X.509 証明書を
    使うべきかを指示する必要があります。NetBeans プロジェクト ナビゲータでプロジェクトノードの CatalogClient ノードに行き、Web サービス参照ノードを展開します。

  2. CatalogService Web サービス ノードを右クリックし、クライアントの更新を選択します。この操作によりクライアントはサービスの新規セキュリティ設定を拾うことが出来ます。



  3. クライアント更新ウィンドウで、「ローカル WSDL ファイルも、次の場所にある下の WSDL ファイルで置き換える」にチェックを入れ、
    はいのボタンをクリックします。



  4. NetBeans は新規のサービス WSDL を取り込み、クライアントプロキシ コードを再生成します。

  5. NetBeans のフレームでサービスタブをクリックします。サーバーノードを展開し、GlassFish を選択して右マウスクリックで再起動を選択します。 GlassFish が再起動するまで待ちます。



  6. WSIT メッセージ セキュリティ メカニズムは v3 証明書の使用が要求されます。証明書を使用するように設定された Web サービスをデプロイして GlassFish を再起動するときには、GlassFish に証明書がインストールされている必要があります。この事の詳細情報は WSIT Tutorial Configuring Keystores and Truststores. を参照してください。

  7. さて、プロジェクトタブを選択し、 CatalogClient プロジェクトを展開して Web サービス参照CatalogServiceノードを右クリックして「Web サービス属性を編集」を選択します。



  8. Web サービス属性ウィンドウで、サービス品質タブを選択し、「開発のデフォルトを使用」にチェックを入れます。サービスサイドと同様にプレインストールされた証明書を使用することになります。了解ボタンを押してください。



  9. クライアントの構成は以上の手順で全てです。 CatalogClient プロジェクトを右クリックして事項を選択します。するとクライアントがコンパイル、デプロイされて Web ブラウザにクライアントアプリケーションを表示されます。



  10. list items リンクをクリックした際にセキュリティエラーメッセージが出る場合は、GlassFish を再起動したときに正しく証明書がインストールされなかったためなので、 GlassFish をもう一度再起動してください。 これでも旨く行かなかったときは、この練習の最後にある Installing Security Certificates to GlassFish に行ってその指示に従ってコマンドライン ウィンドウと ant スクリプトを使用して GlassFish に証明書をインストールしてください。

  11. catalog item リストを少しブラウズしてみてください。そして NetBeans に戻って出力セクションの主力ウィンドウの中で GlassFish V2.1 タブを選択します。ここでは GlassFish サーバーのログが表示されています。このログは交換されたメッセージの完全なコピーを表示しています。このログが示すように、メッセージが的確に暗号化されていることを目で確かめることが出来ます。

    Display server log

サマリー:

Web サービスをセキュアにしました。クライアントは設定を自動的に拾いました。サービスとクライアントの両方とも GlassFish にインストールされている証明書を利用しました。アプリケーションをテストしてメッセージ交換がセキュアであることを確認できました。

Resources



Installing Security Certificates to GlassFish

(note only do this if you have problems running the above exercise after deploying the CatalogService and restarting Glassfish).  The WSIT message security mechanisms require the use of v3 certificates. The default GlassFish keystore and truststore do not contain v3 certificates at this time. GlassFish instances installed using JDK 1.6 do have a v3 certificate but the certificate lacks a particular extension required for supporting some secure WSIT mechanisms. When you deploy a WebService configured to use certificates and restart Glassfish, the certificates should get installed on Glassfish, if this does not work then
in order to use message security mechanisms with GlassFish, it is necessary to download keystore and truststore files that contain v3 certificates and import the appropriate certificates into the default GlassFish stores.

Note:

Steps to follow:

  1. Follow this link to the file copyv3.zip. It contains the certificates and the Ant scripts to install the certificates in GlassFish. You can also download the file from http://xwss.dev.java.net/.
  2. Unzip this file and change into its directory
    cd copyv3
  3. Create an environment variable named AS_HOME that it specifies the full path to the location of your GlassFish installation. For example on Unix:
    export AS_HOME=/opt/glassfish
    On Windows open the command line and enter:
    set AS_HOME=C:\glassfish
    Note: Some releases of GlassFish may have different default passwords for the keystores. If you are using a different version of GlassFish than the one recommended at wsit.dev.java.net, edit the file build.xml and specify the correct default password in the AS_KEYSTORE_PASSWORD field. Default passwords for GlassFish might be adminadmin or changeit.
  4. From the copyv3 directory, execute the Ant command that will copy the keystore and truststore files to the appropriate location, and import the appropriate certificates into the GlassFish keystore and truststore. This ant command is simply:
    <AS_HOME>\lib\ant\bin\ant
  5. Next steps will verify the installation has been successful. Change to the directory containing the GlassFish keystore and truststore files:
    cd <AS_HOME>/domains/domain1/config
  6. Verify that the v3 certificate has been imported into the GlassFish truststore. To do this, run the following keytool command:
    <JDK_HOME>/bin/keytool -list -keystore cacerts.jks -alias wssip -storepass changeit
  7. Verify that the v3 certificate has been imported into the GlassFish keystore. To do this, run the following keytool commands:
     <JDK_HOME>/bin/keytool -list -keystore keystore.jks -alias xws-security-server -storepass changeit
    <JDK_HOME>/bin/keytool -list -keystore keystore.jks -alias xws-security-client -storepass changeit
Note: The XWSS keystore(s) are sample keystores containing sample v3 Certificates. These sample keystores can be used for development and testing of security with WSIT technology. Once an application is in production, you should definitely use your own v3 certificates issued by a trusted authority. In order to use WSIT security on GlassFish, you will have to import your trusted stores into GlassFish's keystore and specify those certificates from NetBeans IDE. For more information about this see the WSIT Tutorial Configuring Keystores and Truststores.