Java SE セキュリティー・チュートリアル - ステップ 4

前のステップに基づいて、以下のトピックでは、 分散 eXtreme Scale 環境でクライアント認証を実装する方法を示します。

始める前に

Java SE セキュリティー・チュートリアル - ステップ 3 を完了していなければなりません。SecureSimpleApp.java サンプルの作成および sec_sample.jar ファイルへのコンパイル、ならびに security.xml という構成ファイルの作成が完了していなければなりません。

このタスクについて

クライアント認証が有効になっていると、クライアントは eXtreme Scale サーバーに接続する前に認証されます。 このセクションでは、eXtreme Scale サーバー環境でどのようにすればクライアント認証が可能であるかを、サンプル SecureSimpleApp.java を使用して実証します。 クライアント資格情報

SecureSimpleApp.java サンプルでは、次の 2 つのプラグイン実装を使用してクライアント資格情報を取得します。

com.ibm.websphere.objectgrid.security.plugins.builtins.UserPasswordCredential
com.ibm.websphere.objectgrid.security.plugins.builtins.UserPasswordCredentialGenerator 

これらのプラグインについて詳しくは、クライアント認証プログラミングを参照してください。

サーバー・オーセンティケーター

この例では、テストとサンプルが目的である eXtreme Scale 組み込み実装 KeyStoreLoginAuthenticator を使用します (鍵ストアは単純なユーザー・レジストリーであり、実動には使用しないようにしてください)。 詳しくは、クライアント認証プログラミングのオーセンティケーター・プラグインについてのトピックを参照してください。

手順

  1. コマンド行ウィンドウで、wxs_home ディレクトリーに移動します。
  2. Java SE セキュリティー・チュートリアル - ステップ 3 で作成した wxs_home/security ディレクトリーに切り替えます。
  3. サーバーに対する認証の方法を実施する JAAS 構成ファイル (og_jaas.config) を作成します。 security.xml ファイルで参照されている KeyStoreLoginAuthenticator は、JAAS ログイン・モジュール「KeyStoreLogin」を使用することによって鍵ストアを使用します。 鍵ストアは、KeyStoreLoginModule クラスに対するオプションとして構成できます。
    og_jaas.config
    KeyStoreLogin{
    com.ibm.websphere.objectgrid.security.plugins.builtins.KeyStoreLoginModule required
         keyStoreFile="../security/sampleKS.jks" debug = true;
    };
  4. パスワードが sampleKS1 である鍵ストア sampleKS.jks を作成します。
  5. java_home/bin ディレクトリーに切り替え、keytool を実行します。
  6. wxs_home /security ディレクトリーに切り替え、それぞれ独自のパスワードを持つ 2 人のユーザー「manager」および「cashier」を作成します。
    1. keytool を使用して、パスワード「manager1」を持つユーザー「manager」を鍵ストア sampleKS.jks に作成します。
      keytool -genkey -v -keystore ./sampleKS.jks -storepass sampleKS1 
      -alias manager -keypass manager1 
      -dname CN=manager,O=acme,OU=OGSample -validity 10000
    2. keytool を使用して、パスワード「cashier1」を持つユーザー「cashier」を鍵ストア sampleKS.jks に作成します。
      keytool -genkey -v -keystore ./sampleKS.jks -storepass sampleKS1 
      -alias cashier -keypass cashier1 -dname CN=cashier,O=acme,OU=OGSample 
      -validity 10000
  7. wxs_home/properties ディレクトリーに切り替えます。
  8. sampleClient.properties ファイルをコピーします。
    cp ../properties/sampleClient.properties client.properties
  9. wxs_home/security ディレクトリーで、これを client.properties として保存します。
    client.properties ファイルに対して以下の変更を行います。
    1. securityEnabled: securityEnabled を true (デフォルト値) に設定します。認証を含むクライアント・セキュリティーが有効になります。
    2. credentialAuthentication: credentialAuthentication を Supported (デフォルト値) に設定すると、クライアントで資格情報認証がサポートされます。
    3. transportType: transportType を TCP/IP に設定すると、SSL は使用されません。
  10. sampleServer.properties ファイルをコピーします。
    cp ../properties/sampleServer.properties server.properties
  11. wxs_home/security ディレクトリーで、これを server.properties として保存します。
    server.properties ファイルで以下の変更を行います。
    1. securityEnabled: securityEnabled 属性を true に設定します。
    2. transportType: transportType 属性を TCP/IP に設定します。すなわち、SSL は使用されません。
    3. secureTokenManagerType: secureTokenManagerType 属性を none に設定します。これで、セキュア・トークン・マネージャーが構成されなくなります。
  12. wxs_home/bin ディレクトリーに移動し、ご使用のプラットフォームに応じて、次のいずれかのコマンドを実行してカタログ・サーバーを始動します。 セキュリティー・プロパティーを渡すために、-clusterFile および -serverProps のコマンド行オプションを実行する必要があります。
    • [Unix][Linux]
      startOgServer.sh catalogServer -clusterSecurityFile ../security/security.xml 
      -serverProps ../security/server.properties -jvmArgs 
      -Djava.security.auth.login.config="../security/og_jaas.config"
    • [Windows]
      startOgServer.bat catalogServer -clusterSecurityFile ../security/security.xml 
      -serverProps ../security/server.properties -jvmArgs 
      -Djava.security.auth.login.config="../security/og_jaas.config" 
  13. 次のいずれかのスクリプトを使用して、c0 という名前のコンテナー・サーバーを始動します。-serverProps を発行するとサーバー・プロパティー・ファイルが渡されます。
      • [Linux][Unix]
        startOgServer.sh c0 -objectgridFile ../xml/SimpleApp.xml 
        -deploymentPolicyFile ../xml/SimpleDP.xml 
        -catalogServiceEndPoints localhost:2809 
        -serverProps ../security/server.properties 
        -jvmArgs -Djava.security.auth.login.config="../security/og_jaas.config"
      • [Windows]
        startOgServer.bat c0 -objectgridFile ../xml/SimpleApp.xml 
        -deploymentPolicyFile ../xml/SimpleDP.xml 
        -catalogServiceEndPoints localhost:2809 
        -serverProps ../security/server.properties 
        -jvmArgs -Djava.security.auth.login.config="../security/og_jaas.config"
  14. カタログ・サーバーとコンテナー・サーバーが始動されたならば、次のようにして sec_sample.jar サンプルを実行します。
    java -classpath ../lib/objectgrid.jar;../applib/sec_sample.jar
    		com.ibm.websphere.objectgrid.security.sample.guide.SecureSimpleApp
    		../security/client.properties manager manager1

    [Linux] 前の例にあるように、セミコロン (;) ではなくコロン (:) をクラスパスの分離文字として使用します。

    クラスを発行すると、以下の出力が得られます。

    The customer name for ID 0001 is fName lName.

  15. 次のように xscmd コマンド・ユーティリティーを実行して、「accounting」グリッドに挿入された「customer」マップのサイズを確認します。
    • [Unix][Linux] xscmd.sh -c showMapSizes -g accounting -m customer -username manager -password manager1
    • [Windows] xscmd.bat -c showMapSizes -g accounting -m customer -username manager -password manager1
  16. オプション: コンテナー・サーバーまたはカタログ・サーバーを停止する場合は、stopOgServer を使用することができます。 ただし、セキュリティー構成ファイルを指定する必要があります。 サンプル・クライアント・プロパティー・ファイルは、以下の 2 つのプロパティーを定義して、ユーザー ID とパスワードの資格情報 (manager/manager1) を生成します。
    credentialGeneratorClass=com.ibm.websphere.objectgrid.security.plugins.builtins.UserPasswordCredentialGenerator 
    credentialGeneratorProps=manager manager1

    次のコマンドを使用してコンテナー c0 を停止します。

    • [Unix][Linux] stopOgServer.sh c0 -catalogServiceEndPoints localhost:2809 -clientSecurityFile ..¥security¥client.properties
    • [Windows] stopOgServer.bat c0 -catalogServiceEndPoints localhost:2809 -clientSecurityFile ..¥security¥client.properties

    -clientSecurityFile オプションを指定しないと、次のメッセージを伴う例外が表示されます。

    >> SERVER (id=39132c79, host=9.10.86.47) TRACE START:

    >> org.omg.CORBA.NO_PERMISSION: Server requires credential authentication but there is no security context from the client. This usually happens when the client does not pass a credential the server.

    vmcid: 0x0

    minor code: 0

    completed: No

    また、以下のコマンドを使用してカタログ・サーバーをシャットダウンすることもできます。 ただし、チュートリアルの次のステップに続行する場合は、このカタログ・サーバーを実行させたままにしておいてかまいません。

    • [Unix][Linux] stopOgServer.sh catalogServer -catalogServiceEndPoints localhost:2809 -clientSecurityFile ..¥security¥client.properties
    • [Windows] stopOgServer.bat catalogServer -catalogServiceEndPoints localhost:2809 -clientSecurityFile ..¥security¥client.properties

    カタログ・サーバーをシャットダウンすると、次の出力が表示されます。

    CWOBJ2512I: ObjectGrid server catalogServer stopped

    これで、認証を有効にすることにより、正常にシステムが部分的にセキュアになりました。 サーバーを構成してユーザー・レジストリーをプラグインし、クライアントを構成してクライアント資格情報を提供するようにし、クライアント・プロパティー・ファイルおよびクラスター XML ファイルを変更して認証を有効にしています。

    無効なパスワードを入力すると、ユーザー名およびパスワードが誤っていることを示す例外が表示されます。

    クライアント認証について詳しくは、アプリケーション・クライアントの認証を参照してください。

    次のチュートリアル・ステップ