共通メソッド、前提条件ステップ、および Virtual member manager アプリケーションを作成するプログラマーが必要とするその他の情報について、ここで説明します。
Virtual member manager の機能をアプリケーションに組み込むには、Virtual member manager パッケージおよびその他の関連パッケージを事前にインポートする必要があります。次の例は、インポートする必要があるパッケージ、およびクラスの定義方法を示しています。
import java.util.Hashtable;
import java.util.List;
import com.ibm.websphere.wim.SchemaConstants;
import com.ibm.websphere.wim.Service;
import com.ibm.websphere.wim.client.LocalServiceProvider;
import com.ibm.websphere.wim.ras.WIMTraceHelper;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import javax.security.auth.Subject;
import javax.security.auth.login.LoginContext;
import com.ibm.websphere.security.auth.WSSubject;
import com.ibm.websphere.security.auth.callback.WSCallbackHandlerImpl;
import commonj.sdo.DataObject;
アプリケーションが WebSphere Application Server 内部で実行されている場合、Virtual member manager サービスを、リモート EJB またはローカル JVM から取得できます。
以下の基本アプリケーションのサンプルには、Virtual member manager サービスを取得する方法を示す locateService() メソッドと、さまざまな Virtual member manager 操作のコード・サンプルで使用されるその他の共通メソッドが含まれています。以下のコードでイタリックで示されている変数 は、必要な実際の値に置き換えてください。
/**
* This is a base application which defines common methods that are
* used by other code samples.
**/
public class BaseApp implements SchemaConstants
{
/**
* Common variable declaration: update based on the environment
**/
static final String HOST = "localhost"; // host name of the WebSphere Application Server
static final String BOOTSTRAP_PORT = "2809"; // Bootstrap/RMI port number
// Virtual member manager service that is used to make API calls
static Service service = null;
/**
* Locates virtual member manager service using a remote EJB
* @param ejbJndiName JNDI name of the EJB.
* Default EJB name is "ejb/com/ibm/websphere/wim/ejb/WIMServiceHome"
**/
public static Service locateService(String ejbJndiName)
{
try {
// Remote access virtual member manager Service EJB
Hashtable environment = new Hashtable();
String providerURL = "corbaloc:iiop:" + HOST + ":" + BOOTSTRAP_PORT;
environment.put(LocalServiceProvider.PROVIDER_URL, providerURL);
if (ejbJndiName == null) {
ejbJndiName = "ejb/com/ibm/websphere/wim/ejb/WIMServiceHome";
}
environment.put(LocalServiceProvider.EJB_JNDI_NAME, ejbJndiName);
service = new LocalServiceProvider(environment);
}
catch (Exception e) {
e.printStackTrace();
}
return service;
}
/**
* Locates virtual member manager service in local JVM
**/
public static Service locateService()
{
try {
// Local access virtual member manager Service
return new LocalServiceProvider(null);
}
catch (Exception e)
{
e.printStackTrace();
}
return null;
}
/**
* Runs action as specified user
* @param user user name
* @param password password of the user
* @param action Action to invoke after successful login of the user
* @return Object returned by the action
**/
public static Object runAsUser(String user, String password, PrivilegedExceptionAction action) throws Exception
{
LoginContext loginContext;
Subject subject;
// Login using the userid and password that was passed, which has the required role
loginContext = new LoginContext("WSLogin", new WSCallbackHandlerImpl(user, "", password));
loginContext.login();
subject = loginContext.getSubject();
try {
return WSSubject.doAs(subject, action);
}
catch (PrivilegedActionException excp) {
throw (Exception) excp.getCause();
}
}
public static String printDO(DataObject obj)
{
return WIMTraceHelper.printDataObject(obj);
}
/**
* Loop through the entities in the DataObject and print its uniqueName
* @param root input DataObject
*/
@SuppressWarnings("unchecked")
public static void printIdentifiers(DataObject root) throws Exception
{
// Get all entities in the DataObject
List entities = root.getList(SchemaConstants.DO_ENTITIES);
for (int i = 0; i < entities.size(); i++) {
DataObject ent = (DataObject) entities.get(i);
// Get the entity Identifier
DataObject id = ent.getDataObject(SchemaConstants.DO_IDENTIFIER);
if (id != null) {
String uniqueName = id.getString(SchemaConstants.PROP_UNIQUE_NAME);
System.out.println("UniqueName is -> " +uniqueName);
}
else {
System.out.println("Missing Identifier");
}
}
}
}
org.eclipse.emf.ecore.EPackage.Registry.INSTANCE=com.ibm.ws.wim.util.VMMEMFGlobalDelegatorRegistry
このシステム・プロパティーを設定しないと、デフォルト EMF 実装が有効になります。この実装では、マルチセキュリティー・ドメイン環境がサポートされておらず、EMF スキーマが破損しスキーマ違反エラーが発生する可能性があります。さまざまな Virtual member manager 操作のコード・サンプルが、BaseApp クラスで定義されたメソッドを使用します。API 呼び出しを行う方法の説明については、コード・サンプルを参照してください。
自分のアプリケーション・コードで Virtual member manager API を呼び出すには、以下の役割のいずれかに割り当てられている必要があります。
WebSphere Application Server 管理者ロール
統合リポジトリー管理権限を使用して割り当てられた Virtual member manager 役割
Virtual member manager の事前定義された役割について詳しくは、セキュリティーの提供の『統合リポジトリー管理権限割り当てのための役割へのユーザーおよびグループのマッピング』のセクションを参照してください。
ユーザーまたはグループに事前定義の Virtual member manager 役割を割り当てる方法については、WebSphere Application Server インフォメーション・センターの「AdminTask オブジェクトの IdMgrConfig コマンド・グループ」トピックの mapIdMgrUserToRole、mapIdMgrGroupToRole、removeIdMgrUsersFromRole、removeIdMgrGroupsFromRole、listIdMgrUsersForRoles、および listIdMgrGroupsForRoles コマンドの説明を参照してください。
エンドツーエンドのシナリオの例については、統合リポジトリー管理権限を使用するためのサンプル・コードのトピックを参照してください。
コードをコンパイルする場合、クラスパス設定を調べて、正しい Java アーカイブ (JAR) ファイルが含まれていることを確認してください。
アプリケーション・コードが、アプリケーションまたはサーブレットとして WebSphere Application Server 内部で実行している場合、Virtual member manager にアクセスするための Subject およびその他のパラメーターが暗黙的に使用されます。これらのパラメーターは、アプリケーションがデプロイされているサーバーまたはプロセスのものと同じです。
アプリケーションが WebSphere Application Server の外部で (例えば WebSphere Application Server クライアントから) 実行されている場合は、コンパイルされたコードを実行するときに以下の JVM 引数を使用してください。以下の引数でイタリックで示されている変数 は、必要な実際の値に置き換えてください。
-Djava.security.auth.login.config=<WAS_HOME>/properties/wsjaas_client.conf
-Dcom.ibm.CORBA.ConfigURL=<WAS_HOME_URL>/properties/sas.client.props
-Dcom.ibm.SSL.ConfigURL=<WAS_HOME_URL>/properties/ssl.client.props
以下の引数は、CORBA プロパティー・ファイルで指定されたクレデンシャルをオーバーライドする必要がある場合のみ使用してください。
-Dcom.ibm.CORBA.loginSource=properties
-Dcom.ibm.CORBA.loginUserid=AdminUserId
-Dcom.ibm.CORBA.loginPassword=Admin Password
-Djava.security.auth.login.config=C:/Progra~1/IBM/WebSphere/AppClient/properties/wsjaas_client.conf
-Dcom.ibm.CORBA.ConfigURL=file:/Progra~1/IBM/WebSphere/AppClient/properties/sas.client.props
-Dcom.ibm.SSL.ConfigURL=file:/Progra~1/IBM/WebSphere/AppClient/properties/ssl.client.props
-Dcom.ibm.CORBA.loginSource=properties
-Dcom.ibm.CORBA.loginUserid=admin
-Dcom.ibm.CORBA.loginPassword=admin