練習 4: Web サービスにおける WSIT セキュリティ
Expected duration: 20 minutes
This exercise explains how to configure a secure Web Service.
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:
- Web Services Security Policy--Enables Web Services to use
security assertions to clearly represent security preferences and
requirements for Web Service endpoints.
- Web Services Trust--Enables Web Service applications to use SOAP
messages to request security tokens that can then be used to establish
trusted communications between a client and a Web Service.
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.
- 前回の練習で使用した Web サービス クライアント と サービス アプリケーション もしくは <lab_home>\exercises\exercises4 から
NetBeans サンプル プロジェクト CatalogService と CatalogClient をオープンします
- NetBeans プロジェクト ナビゲータで CatalogService に行き、プロジェクトの下の Web サービスノードを展開し、
CatalogService Web サービス ノードで右クリックして、「Web サービス属性を編集」を選択します。
- NetBeans は Web サービス属性編集ウィンドウをオープンします。サービス品質タブは開かれています。 CatalogPortBinding 下の
セキュアサービスにチェックを入れ、他のチェックボックスはデフォルト設定のままにして置いてください。
- さて、サービスを SOAP メッセージがサービスのパブリック X.509 証明書キーで XML-暗号化されたものだけ受け付けるように
構成します。このサービスはクライアントのパブリック 証明書キーで暗号化されたメッセージで答えます。セキュリティメカニズムは
リストボックスから「相互証明書セキュリティー」を選択します。
- 「開発のデフォルトの使用」チェックボックスはチェックを入れます。もし、独自のサービスとクライアントを開発したいならば、
チェックを入れないで、証明書を GlassFish にインポートした後に選択します。了解ボタンをクリックします。
- CatalogService プロジェクトを右クリックし、配備を選択します。
- メッセージ交換を保護するサービスを作成することは今までの手順で全てです。サービスが生成した WSDL を覗いて見ましょう。
ブラウザで http://localhost:8080/CatalogService/CatalogService?wsdl. の URL を使用します。 Web ページのトップにサービス WSDL
に追加されたいくつかのセキュリティポリシーが見られます。
- クライアントを構成します。クライアントはサービスの WSDL からセキュリティ要求条件を拾い上げます。更に、どの X.509 証明書を
使うべきかを指示する必要があります。NetBeans プロジェクト ナビゲータでプロジェクトノードの CatalogClient ノードに行き、Web サービス参照ノードを展開します。
- CatalogService Web サービス ノードを右クリックし、クライアントの更新を選択します。この操作によりクライアントはサービスの新規セキュリティ設定を拾うことが出来ます。
- クライアント更新ウィンドウで、「ローカル WSDL ファイルも、次の場所にある下の WSDL ファイルで置き換える」にチェックを入れ、
はいのボタンをクリックします。
- NetBeans は新規のサービス WSDL を取り込み、クライアントプロキシ コードを再生成します。
- NetBeans のフレームでサービスタブをクリックします。サーバーノードを展開し、GlassFish を選択して右マウスクリックで再起動を選択します。 GlassFish が再起動するまで待ちます。
- WSIT メッセージ セキュリティ メカニズムは v3 証明書の使用が要求されます。証明書を使用するように設定された Web サービスをデプロイして GlassFish を再起動するときには、GlassFish に証明書がインストールされている必要があります。この事の詳細情報は WSIT
Tutorial Configuring Keystores and Truststores. を参照してください。
- さて、プロジェクトタブを選択し、 CatalogClient プロジェクトを展開して Web サービス参照の CatalogServiceノードを右クリックして「Web サービス属性を編集」を選択します。
- Web サービス属性ウィンドウで、サービス品質タブを選択し、「開発のデフォルトを使用」にチェックを入れます。サービスサイドと同様にプレインストールされた証明書を使用することになります。了解ボタンを押してください。
- クライアントの構成は以上の手順で全てです。
CatalogClient プロジェクトを右クリックして事項を選択します。するとクライアントがコンパイル、デプロイされて Web ブラウザにクライアントアプリケーションを表示されます。
- list items リンクをクリックした際にセキュリティエラーメッセージが出る場合は、GlassFish を再起動したときに正しく証明書がインストールされなかったためなので、 GlassFish をもう一度再起動してください。 これでも旨く行かなかったときは、この練習の最後にある Installing Security Certificates to
GlassFish に行ってその指示に従ってコマンドライン ウィンドウと ant スクリプトを使用して GlassFish に証明書をインストールしてください。
- catalog item リストを少しブラウズしてみてください。そして NetBeans に戻って出力セクションの主力ウィンドウの中で GlassFish V2.1 タブを選択します。ここでは GlassFish サーバーのログが表示されています。このログは交換されたメッセージの完全なコピーを表示しています。このログが示すように、メッセージが的確に暗号化されていることを目で確かめることが出来ます。
Web サービスをセキュアにしました。クライアントは設定を自動的に拾いました。サービスとクライアントの両方とも GlassFish にインストールされている証明書を利用しました。アプリケーションをテストしてメッセージ交換がセキュアであることを確認できました。
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:
- 'v3 certificates' is shorthand for Internet X.509 v3 Public Key
Infrastructure Certificate. A copy of the standard for this technology
can be viewed at IETF
pages.
- In a future release you will be able to directly use the default
GlassFish certificates without this workaround.
- 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/.
- Unzip this file and change into its directory
cd copyv3
- 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
.
- 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
- 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
- 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
- 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.