此处提供的端到端步骤、命令和样本代码片段,是使非 WebSphere Application Server 管理员用户能够在多个安全域环境中访问 virtual member manager 应用程序编程接口 (API) 所必需的。
通过联合存储库管理权限,非 WebSphere Application Server 管理员用户也能管理用户和组以及访问管理域和应用程序域中的其他 virtual member manager API。请阅读 virtual member manager 文档中“提供安全性”主题下有关预定义角色及其许可权的内容。您可以使用以下 wsadmin 命令来实现此功能:mapIdMgrUserToRole、mapIdMgrGroupToRole、removeIdMgrUsersFromRole、removeIdMgrGroupsFromRole 和 listIdMgrUsersForRoles。 有关更多信息,请阅读 WebSphere Application Server 信息中心“用于 AdminTask 对象的 IdMgrConfig 命令组”主题中有关使用这些命令的内容
此样本方案中涵盖以下步骤:
确保您已阅读了“编程先决条件”主题中的信息并完成了其中描述的步骤。
您必须首先完成以下配置步骤,然后才能使用样本代码。启动 wsadmin 工具并执行以下命令。将变量替换为您要使用的实际值。
$AdminApp.install('app_server_root/installableApps/wimperdomain.ear',
'[-appname wimperdomain -BindJndiForEJBNonMessageBinding [[ wim.ejb
WIMService wimejb.jar,META-INF/ejb-jar.xml ejbd2/com/ibm/websphere/wim/ejb/WIMServiceHome]]
-MapModulesToServers [[ wim.ejb wimejb.jar,META-INF/ejb-jar.xml
WebSphere:cell=myCell,node=myNode,server=server1 ]]]' )
$AdminTask createUser {-uid vmmadmin –password tempPass -confirmPassword tempPass
–cn admincn –sn adminsn -securityDomainName domain1 }
$AdminTask mapIdMgrUserToRole {-userId vmmadmin -roleName IdMgrAdmin -securityDomainName domain1}
按照以下步骤所述,将以下端到端样本代码添加到您的应用程序代码。将变量替换为您要使用的实际值。
import commonj.sdo.DataObject;
public class SimpleTest extends BaseApp
{
public static void createAsAdmin()
{
try {
createUser("vmmadmin", "tempPass");
}
catch (Exception e) {
e.printStackTrace();
}
}
public static void createUser(String user, String password) throws Exception
{
DataObject result = (DataObject) runAsUser(user, password, new java.security.PrivilegedExceptionAction()
{
public Object run() throws Exception
{
//Note the service instance used is that of security domain obtained in step 1.
DataObject root = service.createRootDataObject();
DataObject user = root.createDataObject(DO_ENTITIES, WIM_NS_URI, DO_PERSON_ACCOUNT);
user.set("uid", "authzzuser");
user.set("cn", "authzzuser");
user.set("sn", "authzzuser");
user.set(PROP_PASSWORD, com.ibm.websphere.wim.util.PasswordUtil
.getByteArrayPassword("authzzuser"));
// Print Input datagraph
System.out.println("Input datagraph before creating user" + printDO(root));
DataObject retObject = service.create(root);
// Print the output datagraph
System.out.println("Output datagraph after creating user" + printDO(retObject));
return retObject;
}
});
}
public static void main(String[] args)
{
// Note that the EJB JNDI is same as one used in step 1.
service = locateService("ejbd2/com/ibm/websphere/wim/ejb/WIMServiceHome");
createAsAdmin();
}
}