インバウンド ID マッピングでは、カスタム・ログイン・モジュールを作成し、 システム・ログイン構成の中でログイン・モジュールを最初に実行するように WebSphere Application Server を構成します。 カスタム・ログイン・モジュールを作成する場合は、次のステップを考慮してください。
javax.security.auth.callback.Callback callbacks[] = new javax.security.auth.callback.Callback[3]; callbacks[0] = new javax.security.auth.callback.NameCallback(""); callbacks[1] = new javax.security.auth.callback.PasswordCallback("Password: ", false); callbacks[2] = new com.ibm.websphere.security.auth.callback. WSCredTokenCallbackImpl(""); callbacks[3] = new com.ibm.wsspi.security.auth.callback. WSTokenHolderCallback(""); try { callbackHandler.handle(callbacks); } catch (Exception e) { // Handles exceptions throw new WSLoginFailedException (e.getMessage(), e); } // Shows which callbacks contain information boolean identitySwitched = false; String uid = ((NameCallback) callbacks[0]).getName(); char password[] = ((PasswordCallback) callbacks[1]).getPassword(); byte[] credToken = ((WSCredTokenCallbackImpl) callbacks[2]).getCredToken(); java.util.List authzTokenList = ((WSTokenHolderCallback) callbacks[3]).getTokenHolderList(); if (credToken != null) { try { String uniqueID = WSSecurityPropagationHelper.validateLTPAToken(credToken); String realm = WSSecurityPropagationHelper.getRealmFromUniqueID (uniqueID); // Now set the string to the UID so that you can use the result for either // mapping or logging in. uid = WSSecurityPropagationHelper.getUserFromUniqueID (uniqueID); } catch (Exception e) { // Handles the exception } } else if (uid == null) { // Throws an exception if authentication data is not valid. // You must have either UID or CredToken throw new WSLoginFailedException("invalid authentication data."); } else if (uid != null && password != null) { // This is a typical authentication. You can choose to map this ID to // another ID or you can skip it and allow WebSphere Application Server // to log in for you. When passwords are presented, be very careful to not // validate the password because this is the initial authentication. return true; } // If desired, map this uid to something else and set the identitySwitched // boolean. If the identity was changed, clear the propagated attributes // below so they are not used incorrectly. uid = myCustomMappingRoutine (uid); // Clear the propagated attributes because they are no longer applicable // to the new identity if (identitySwitched) { ((WSTokenHolderCallback) callbacks[3]).setTokenHolderList(null); }
boolean requiresLogin = ((com.ibm.wsspi.security.auth.callback.WSTokenHolderCallback) callbacks[2]).requiresLogin();許可の実行に必要な WSCredential および WSPrincipal オブジェクトを形成するのに 十分な属性が存在しない場合、上記のコード・サンプルは true の結果を戻します。 結果が false の場合、Subject を作成するのに必要な情報が存在するため、追加のリモート・ユーザー・レジストリー呼び出しを実行することなく、処理の中止を選択することができます。
if (requiresLogin || identitySwitched) { // Retrieves the default InitialContext for this server. javax.naming.InitialContext ctx = new javax.naming.InitialContext(); // Retrieves the local UserRegistry implementation. com.ibm.websphere.security.UserRegistry reg = (com.ibm.websphere.security.UserRegistry) ctx.lookup("UserRegistry"); // Retrieves the user registry uniqueID based on the uid specified // in the NameCallback. String uniqueid = reg.getUniqueUserId(uid); uid = WSSecurityPropagationHelper.getUserFromUniqueID (uniqueID); // Retrieves the display name from the user registry based on the uniqueID. String securityName = reg.getUserSecurityName(uid); // Retrieves the groups associated with the uniqueID. java.util.List groupList = reg.getUniqueGroupIds(uid); // Creates the java.util.Hashtable with the information that you gathered // from the UserRegistry implementation. java.util.Hashtable hashtable = new java.util.Hashtable(); hashtable.put(com.ibm.wsspi.security.token.AttributeNameConstants. WSCREDENTIAL_UNIQUEID, uniqueid); hashtable.put(com.ibm.wsspi.security.token.AttributeNameConstants. WSCREDENTIAL_SECURITYNAME, securityName); hashtable.put(com.ibm.wsspi.security.token.AttributeNameConstants. WSCREDENTIAL_GROUPS, groupList); // Adds a cache key that is used as part of the lookup mechanism for // the created Subject. The cache key can be an object, but should have // an implemented toString method. Make sure that the cacheKey contains // enough information to scope it to the user and any additional attributes // that you are using. If you do not specify this property the Subject is // scoped to the returned WSCREDENTIAL_UNIQUEID, by default. hashtable.put(com.ibm.wsspi.security.token.AttributeNameConstants. WSCREDENTIAL_CACHE_KEY, "myCustomAttribute" + uniqueid); // Adds the hashtable to the sharedState of the Subject. _sharedState.put(com.ibm.wsspi.security.token.AttributeNameConstants. WSCREDENTIAL_PROPERTIES_KEY,hashtable); }
java.util.Hashtable オブジェクトが Subject 内または共有状態領域で検出された場合、 次のプロパティーがハッシュ・テーブルにあるか検査してください。
サード・パーティーの許可プロバイダーがユーザーから役割へのマッピングをオーバーライドする場合は、 サード・パーティーの許可プロバイダーがフォーマットを定義します。 固有の ID 値のために WebSphere Application Server のデフォルトのインプリメンテーションとの互換性を確実にするには、 WebSphere Application Server の public String getUniqueUserId(String userSecurityName) UserRegistry メソッドを呼び出します。
レルム | フォーマット (uniqueUserId) |
---|---|
Lightweight Directory Access Protocol (LDAP) | ldaphost.austin.ibm.com:389/cn=user,o=ibm,c=us |
Windows | MYWINHOST/S-1-5-21-963918322-163748893-4247568029-500 |
UNIX | MYUNIXHOST/32 |
com.ibm.wsspi.security.cred.uniqueId プロパティーが必要です。
レルム | フォーマット (uniqueUserId) |
---|---|
LDAP | ユーザー (LDAP UID) |
Windows | ユーザー (Windows username) |
UNIX | ユーザー (UNIX username) |
com.ibm.wsspi.security.cred.securityName プロパティーが必要です。
レルム | 形式 |
---|---|
LDAP | ldap1.austin.ibm.com:389/cn=group1,o=ibm,c=us |
Windows | MYWINREALM/S-1-5-32-544 |
UNIX | MY/S-1-5-32-544 |
com.ibm.wsspi.security.cred.groups プロパティーは必要ではありません。 ユーザーは関連グループを持っている必要はありません。
com.ibm.wsspi.security.cred.cacheKey プロパティーは必要ではありません。 このプロパティーが指定されない場合、キャッシュ・ルックアップは WSCREDENTIAL_UNIQUEID に指定される値です。 この情報が java.util.Hashtable オブジェクトにある場合、少なくとも、LTPA の場合、WebSphere Application Server は、 通常のログイン・プロセスを行う Subject に似た Subject を作成します。 新規 Subject には、 ハッシュ・テーブル・オブジェクトで検出される情報が完全に取り込まれている WSCredential オブジェクトおよび WSPrincipal オブジェクトが含まれます。