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

チュートリアルの残りの部分は、eXtreme Scale サーバーに接続する前にクライアント認証を有効にする方法を示しています。 このチュートリアルの次のステップに備えるために、SecureSimpleApp.java プログラムを JAR にパッケージ化し、構成ファイルのセットを作成します。これらの構成ファイルは、security.xml ファイルと 2 つの JAAS 構成ファイルを含みます。 security.xml ファイルは、認証を環境に書き込めるようにします。JAAS 構成ファイルは、サーバーへの接続時に認証メカニズムを提供します。

手順

  1. コマンド行ウィンドウで、Java SE セキュリティー・チュートリアル - ステップ 1 で作成した wxs_home/applib ディレクトリーに移動します。
  2. 次の SecureSimpleApp.java クラスを作成してコンパイルします。
    SecureSimpleApp.java
    package com.ibm.websphere.objectgrid.security.sample.guide;
    
    import com.ibm.websphere.objectgrid.ClientClusterContext;
    import com.ibm.websphere.objectgrid.ObjectGrid;
    import com.ibm.websphere.objectgrid.ObjectGridManager;
    import com.ibm.websphere.objectgrid.ObjectGridManagerFactory;
    import com.ibm.websphere.objectgrid.security.config.ClientSecurityConfiguration;
    import com.ibm.websphere.objectgrid.security.config.ClientSecurityConfigurationFactory;
    import com.ibm.websphere.objectgrid.security.plugins.CredentialGenerator;
    import com.ibm.websphere.objectgrid.security.plugins.builtins.UserPasswordCredentialGenerator;
    
    public class SecureSimpleApp extends SimpleApp {
    
        public static void main(String[] args) throws Exception {
    
            SecureSimpleApp app = new SecureSimpleApp();
            app.run(args);
        }
    
        /**
         * Get the ObjectGrid
         * @return an ObjectGrid instance
         * @throws Exception
         */
        protected ObjectGrid getObjectGrid(String[] args) throws Exception {
            ObjectGridManager ogManager = ObjectGridManagerFactory.getObjectGridManager();
            ogManager.setTraceFileName("logs/client.log");
            ogManager.setTraceSpecification("ObjectGrid*=all=enabled:ORBRas=all=enabled");
    
            // Creates a ClientSecurityConfiguration object using the specified file
            ClientSecurityConfiguration clientSC = ClientSecurityConfigurationFactory
                    .getClientSecurityConfiguration(args[0]);
            
            // Creates a CredentialGenerator using the passed-in user and password.
            CredentialGenerator credGen = new UserPasswordCredentialGenerator(args[1], args[2]);
            clientSC.setCredentialGenerator(credGen);
            
            // Create an ObjectGrid by connecting to the catalog server 
            ClientClusterContext ccContext = ogManager.connect("localhost:2809", clientSC, null);
            ObjectGrid og = ogManager.getObjectGrid(ccContext, "accounting");
    
            return og;
    
        }
    
    }
  3. これらのファイルを使用してパッケージをコンパイルし、JAR に sec_sample.jar という名前を付けます。
  4. wxs_home ディレクトリーに切り替えます。
  5. security というディレクトリーを作成します。
  6. security.xml という構成ファイルを作成します。 このファイルにはサーバー・セキュリティー・プロパティーが指定されます。 これらのプロパティーは、カタログ・サーバーとコンテナー・サーバーの両方に共通します。
    security.xml
    <?xml version="1.0" encoding="UTF-8"?>
    <securityConfig xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
        xsi:schemaLocation="http://ibm.com/ws/objectgrid/config/security ../objectGridSecurity.xsd"
    	xmlns="http://ibm.com/ws/objectgrid/config/security">
    
    	<security securityEnabled="true" loginSessionExpirationTime="300" >
            
            <authenticator className ="com.ibm.websphere.objectgrid.security.plugins.builtins.	
    					KeyStoreLoginAuthenticator">
            </authenticator>
        </security>
    	
    </securityConfig>