このトピックでは、WebSphere Application Server でデフォルトの許可トークンを使用する方法について 説明します。ダウンストリームに伝搬されるストリング属性を追加する場所を探している場合には、 デフォルトの許可トークンの使用を検討してみてください。
ただし、許可トークンに追加する属性が、 認証済みサブジェクトに関連付けられたユーザーに固有のものであることを確認してください。 ユーザーに固有のものではない場合、その属性はおそらく、 同様に要求により伝搬される伝搬トークンに属しています。伝搬トークンについて詳しくは、 例: デフォルトの伝搬トークンの使用 を参照してください。属性を許可トークンに追加するには、カスタム・ログイン・モジュールを、 構成済みの各種のシステム・ログイン・モジュールにプラグインする必要があります。 構成済みのインプリメンテーション com.ibm.ws.security.server.lm.wsMapDefaultInboundLoginModule を持つすべてのログイン・モジュール構成は、 伝搬済み情報を受信でき、別のサーバーへアウトバウンドに送信可能な伝搬情報を生成できます。
最初のログイン中に、伝搬済み属性がログイン構成に提示されない場合には、 ログインが ltpaLoginModule ログイン・モジュール内で行われた後、 デフォルトの許可トークンが wsMapDefaultInboundLoginModule ログイン・モジュール内に作成されます。 sharedState hashmap を使用して、 デフォルトの許可トークンへの参照を login メソッドから取得できます。 デフォルトの許可トークンを調べるには、 WebSphere Application Server への wsMapDefaultInboundLoginModule インプリメンテーションの後、 カスタム・ログイン・モジュールにプラグインする必要があります。
Java Authentication and Authorization Service (JAAS) プログラミング・モデルについて詳しくは、 セキュリティー: 学習用リソース を参照してください。
public customLoginModule() { public void initialize(Subject subject, CallbackHandler callbackHandler, Map sharedState, Map options) { // (For more information on initialization, see // システム・ログイン構成用のカスタム・ログイン・モジュール開発 .) // Get a reference to the sharedState map that is passed in during initialization. _sharedState = sharedState; } public boolean login() throws LoginException { // (For more information on what to do during login, see // システム・ログイン構成用のカスタム・ログイン・モジュール開発 .) // Look for the default AuthorizationToken in the shared state defaultAuthzToken = (com.ibm.wsspi.security.token.AuthorizationToken) sharedState.get (com.ibm.wsspi.security.auth.callback.Constants.WSAUTHZTOKEN_KEY); // Might not always have one of these generated. It depends on the login // configuration setup. if (defaultAuthzToken != null) { try { // Add a custom attribute defaultAuthzToken.addAttribute("key1", "value1"); // Determine all of the attributes and values that exist in the token. java.util.Enumeration listOfAttributes = defaultAuthorizationToken. getAttributeNames(); while (listOfAttributes.hasMoreElements()) { String key = (String) listOfAttributes.nextElement(); String[] values = (String[]) defaultAuthorizationToken.getAttributes (key); for (int i=0; i<values.length; i++) { System.out.println ("Key: " + key + ", Value[" + i + "]: " + values[i]); } } // Read the existing uniqueID attribute. String[] uniqueID = defaultAuthzToken.getAttributes (com.ibm.wsspi.security.token.AttributeNameConstants. WSCREDENTIAL_UNIQUEID); // Getthe uniqueID from the String[] String unique_id = (uniqueID != null && uniqueID[0] != null) ? uniqueID[0] : ""; // Read the existing expiration attribute. String[] expiration = defaultAuthzToken.getAttributes (com.ibm.wsspi.security.token.AttributeNameConstants. WSCREDENTIAL_EXPIRATION); // An example of getting a long expiration value from the string array. long expire_time = 0; if (expiration != null && expiration[0] != null) expire_time = Long.parseLong(expiration[0]); // Read the existing display name attribute. String[] securityName = defaultAuthzToken.getAttributes (com.ibm.wsspi.security.token.AttributeNameConstants. WSCREDENTIAL_SECURITYNAME); // Get the display name from the String[] String display_name = (securityName != null && securityName[0] != null) ? securityName[0] : ""; // Read the existing long securityName attribute. String[] longSecurityName = defaultAuthzToken.getAttributes (com.ibm.wsspi.security.token.AttributeNameConstants. WSCREDENTIAL_LONGSECURITYNAME); // Get the long security name from the String[] String long_security_name = (longSecurityName != null && longSecurityName[0] != null) ? longSecurityName[0] : ""; // Read the existing group attribute. String[] groupList = defaultAuthzToken.getAttributes (com.ibm.wsspi.security.token.AttributeNameConstants. WSCREDENTIAL_GROUPS); // Get the groups from the String[] ArrayList groups = new ArrayList(); if (groupList != null) { for (int i=0; i<groupList.length; i++) { System.out.println ("group[" + i + "] = " + groupList[i]); groups.add(groupList[i]); } } } catch (Exception e) { throw new WSLoginFailedException (e.getMessage(), e); } } } public boolean commit() throws LoginException { // (For more information on what to do during commit, see // システム・ログイン構成用のカスタム・ログイン・モジュール開発 .) } private java.util.Map _sharedState = null; private com.ibm.wsspi.security.token.AuthorizationToken defaultAuthzToken = null; }.