スタックされた JAAS ログイン・モジュールを使用した動的 UsernameToken の生成

GenericSecurityTokenFactory API を使用して、WS-Security ランタイムで使用される 完全設定済みまたはシンプル UsernameToken セキュリティー・トークンを作成できます。 これらのセキュリティー・トークンは WSSAPI および JAAS ログイン・モジュール、または UNTGenerateLoginModule に使用できますが、使用できるのはこれらに限定されません。

このタスクについて

GenericSecurityTokenFactory は、GenericIssuedTokenGenerateLoginModule での発行が可能な UsernameToken を作成するために使用できるいくつかの API を提供します。

UsernameTokens には以下の 2 つのタイプがあります。
完全 UsernameToken
完全 UsernameToken には XML が含まれ、GenericSecurityTokenFactory ログイン・モジュールで発行できます。
シンプル UsernameToken
シンプル UsernameToken にはユーザー名とパスワードのみが含まれ、XML は含まれません。シンプル UsernameTokens は、UNTGenerateLoginModule、LTPAGenerateLoginModule、および KRBGenerateLoginModule が使用できる動的ユーザー名とパスワードを設定するのに使用します。

完全 UsernameToken が GenericSecurityTokenFactory API を使用して作成される場合、そのトークンは WS-Security ランタイムで発行できる完全形式のセキュリティー・トークンです。使用するトークンを作成するには、作成したいトークンのタイプを決定した後、以下のいずれかの手順で指定するコマンドに類似したコマンドを発行します。トークンの作成後、トークン内のユーザー名とパスワードは変更できません。

シンプル UsernameToken が GenericSecurityTokenFactory API を使用して作成される場合、そのトークンにはユーザー名と、オプションでパスワードのみが含まれます。 シンプル UsernameToken には XML が含まれていないため、GenericIssuedTokenGenerateLoginModule での発行ができません。

手順

  1. UsernameToken を作成します。 以下のいずれかのタイプの UsernameToken を作成できます。
    • ユーザー名とパスワードが含まれた完全な UsernameToken
    • ユーザー名とタイム・スタンプは含まれるが、パスワードは含まれない完全 UsernameToken
    • ユーザー名とパスワードが含まれた単純な UsernameToken
    • ユーザー名とパスワードを含む完全 UsernameToken を作成します。
      import com.ibm.websphere.wssecurity.wssapi.token.GenericSecurityTokenFactory;
      import com.ibm.websphere.wssecurity.wssapi.token.UsernameToken;
      
      ...
      
      GenericSecurityTokenFactory gstFactory = GenericSecurityTokenFactory.getInstance();
      UsernameToken myUnt = gstFactory.getFullUsernameToken("myUsername", "myPassword".toCharArray());
    • ユーザー名とタイム・スタンプを含み、パスワードは含まない完全 UsernameToken を作成します。
      import com.ibm.websphere.wssecurity.wssapi.token.GenericSecurityTokenFactory;
      import com.ibm.websphere.wssecurity.wssapi.token.UsernameToken;
      
      ...
      
      GenericSecurityTokenFactory gstFactory = GenericSecurityTokenFactory.getInstance();
      UsernameToken myUnt = gstFactory.getFullUsernameToken("myUsername", null, true);
    • ユーザー名とパスワードを含むシンプル UsernameToken を作成します。
      import com.ibm.websphere.wssecurity.wssapi.token.GenericSecurityTokenFactory;
      import com.ibm.websphere.wssecurity.wssapi.token.UsernameToken;
      ...
      GenericSecurityTokenFactory gstFactory = GenericSecurityTokenFactory.getInstance();
      UsernameToken myUnt = gstFactory.getSimpleUsernameToken("myUsername", "myPassword".toCharArray());
  2. JAAS ログイン・モジュールを作成します。 前のステップで完全な UsernameToken を作成した場合、完全な UsernameToken を送出するために GenericIssuedTokenGenerateLoginModule の上にスタックできる JAAS ログイン・モジュールを作成する必要があります。前のステップで単純な UsernameToken を作成した場合、動的 UsernameToken を送出するために UNTGenerateLoginModule の上にスタックできる JAAS ログイン・モジュールを作成する必要があります。
    • GenericIssuedTokenGenerateLoginModule の上にスタック可能な JAAS ログイン・モジュールを作成して完全 UsernameToken を発行します。
      以下の例は、バージョン 8.5.0.2 以降をご使用の場合に適用されます。
      package test.tokens;
      
      import java.util.HashMap;
      import java.util.Map;
      
      import javax.security.auth.Subject;
      import javax.security.auth.callback.CallbackHandler;
      import javax.security.auth.login.LoginException;
      import javax.security.auth.spi.LoginModule;
      import com.ibm.websphere.wssecurity.wssapi.token.UsernameToken;
      import com.ibm.websphere.wssecurity.wssapi.token.GenericSecurityTokenFactory;
      import com.ibm.websphere.wssecurity.wssapi.WSSUtilFactory;
      import com.ibm.wsspi.wssecurity.core.config.CallbackHandlerConfig;
      
      import java.util.ArrayList;
      
      public class MyFullUntGenerator implements LoginModule {
      
        private Map _sharedState;
        private Map _options;
        private CallbackHandler _handler;
      
        	public void initialize(Subject subject, CallbackHandler callbackHandler, 
                               Map<String, ?> sharedState, Map<String, ?> options) {
      
          this._handler = callbackHandler;
          this._sharedState = sharedState;
          this._options = options;  
        }
      
        public boolean login() throws LoginException {
          //For the sake of readability, this login module does not
          //protect against all NPE's
      
          GenericSecurityTokenFactory factory = null;
          try {
            factory = GenericSecurityTokenFactory.getInstance();
          } catch (Exception e) {
            throw new LoginException(e.toString());
          }
          if (factory == null) {
            throw new LoginException("GenericSecurityTokenFactory.getInstance() returned null");
          }
      
          //The userid and password can be obtained however you want
      
         // (Optional) Obtain the username and password configured in the callback handler
          Map wssContext = getWSSContext(_handler);            
          CallbackHandlerConfig chc = (CallbackHandlerConfig) wssContext.get(CallbackHandlerConfig.CONFIG_KEY);    
                                                           
          String username = chc.getUserId();                   
          char[] password = chc.getUserPassword();   
      
          UsernameToken unt = factory.getFullUsernameToken("myUsername", "myPassword".toCharArray());
      	
          //Put the token in a list on the shared state where it will be available to be used by
          //stacked login modules
          factory.putGeneratorTokenToSharedState(_sharedState, unt);
      
          return true;
        }
        //implement the rest of the methods required by the
        //LoginModule interface
      }
    • UNTGenerateLoginModule の上にスタック可能な JAAS ログイン・モジュールを作成して動的 UsernameToken を発行します
      package test.tokens;
      
      import java.util.HashMap;
      import java.util.Map;
      
      import javax.security.auth.Subject;
      import javax.security.auth.callback.CallbackHandler;
      import javax.security.auth.login.LoginException;
      import javax.security.auth.spi.LoginModule;
      import com.ibm.websphere.wssecurity.wssapi.token.UsernameToken;
      import com.ibm.websphere.wssecurity.wssapi.token.GenericSecurityTokenFactory;
      import com.ibm.websphere.wssecurity.wssapi.WSSUtilFactory;
      import com.ibm.wsspi.wssecurity.core.config.CallbackHandlerConfig;
      
      import java.util.ArrayList;
      
      public class MySimpleUntGenerator implements LoginModule {
      
        private Map _sharedState;
        private Map _options;
        private CallbackHandler _handler;
      
        	public void initialize(Subject subject, CallbackHandler callbackHandler, 
                               Map<String, ?> sharedState, Map<String, ?> options) {
      
          this._handler = callbackHandler;
          this._sharedState = sharedState;
          this._options = options;  
        }
      
        public boolean login() throws LoginException {
          //For the sake of readability, this login module does not
          //protect against all NPE's
      
          GenericSecurityTokenFactory factory = null;
          try {
            factory = GenericSecurityTokenFactory.getInstance();
          } catch (Exception e) {
            throw new LoginException(e.toString());
          }
          if (factory == null) {
            throw new LoginException("GenericSecurityTokenFactory.getInstance() returned null");
          }
      	
          //The userid and password can be obtained however you want
      
          // (Optional) Obtain the username and password configured in the callback handler
          Map wssContext = getWSSContext(_handler);            
          CallbackHandlerConfig chc = (CallbackHandlerConfig) wssContext.get(CallbackHandlerConfig.CONFIG_KEY);    
                                                           
          String username = chc.getUserId();                   
          char[] password = chc.getUserPassword();   
      
          UsernameToken unt = factory.getSimpleUsernameToken("myUsername", "myPassword".toCharArray());
      
          //Put the token in a list on the shared state where it will be available to be used by
          //stacked login modules
          factory.putGeneratorTokenToSharedState(_sharedState, unt);
      
          return true;
        }
        //implement the rest of the methods required by the
        //LoginModule interface
      }
  3. JAAS ログイン構成を作成します。
    1. 前のステップで作成したカスタム・ログイン・モジュールの完全なクラス名をメモします。 例えば、test.tokens.MyFullUntGenerator です。
    2. スタック先となるログイン・モジュールの完全なクラス名をメモします。 例えば、com.ibm.ws.wssecurity.wssapi.token.impl.UNTGenerateLoginModule や com.ibm.ws.wssecurity.wssapi.token.impl.GenericIssuedTokenGenerateLoginModule です。
    3. 管理コンソールで、「セキュリティー」 > 「グローバル・セキュリティー」に移動します。
    4. 「認証」で、「Java 認証・承認サービス」 > 「システム・ログイン」に移動します。
    5. 「新規」をクリックし、「別名」で test.generate.unt と入力します。
    6. 「JAAS ログイン・モジュール」で「新規」をクリックし、「モジュール・クラス名」でカスタム・ログイン・モジュールの名前を入力します。「ログイン・モジュール・プロキシーを使用」を選択し、「OK」をクリックします。
    7. 「新規」をクリックし、「モジュール・クラス名」でスタック先となるログイン・モジュールの名前を入力します。 「OK」をクリックします。
  4. 新しい JAAS ログイン構成を使用するように UsernameToken トークン生成プログラムを構成します。
    1. 管理コンソールで、変更するバインディング構成を開きます。
    2. 「WS-Security」 > 「認証および保護」を選択します。
    3. 認証トークンの下で、変更するアウトバウンド UsernameToken を選択します。
    4. 「JAAS ログイン」で test.generate.unt を選択します。
    5. オプション: GenericIssuedTokenGenerateLoginModule を使用する場合は、passThroughToken=true カスタム・プロパティーを追加します。
      1. コールバック・ハンドラー」をクリックします。
      2. passThroughToken=true カスタム・プロパティーを 追加します。
      3. 「OK」をクリックします。
  5. 保存」をクリックします。
  6. アプリケーション・サーバーを再始動して JAAS 構成の変更を適用します。
  7. サービスをテストします。

トピックのタイプを示すアイコン タスク・トピック



タイム・スタンプ・アイコン 最終更新: last_date
http://www14.software.ibm.com/webapp/wsbroker/redirect?version=cord&product=was-nd-mp&topic=twbs_createusertokens
ファイル名:twbs_createusertokens.html