在NetWeaver门户中,可以导入/导出角色。我想创建一个具有相同行为的自定义工具。如何使用JAVA代码来实现这一点?我在UME API中找不到任何类或接口来做这件事。
注意:定制工具还具有许多其他功能,并充当所有JAVA系统的集中式门户。
发布于 2019-06-03 19:40:32
利用SAP Composition Environment集,特别是Security API
com.sap.security.api命名空间包含IUserAccountFactory工厂,它具有返回IUserAccount对象(对象数组)的getUserAccount(s)方法。它有getRoles方法,完全满足您的需求。
配合addToRole方法,您可以实现角色的导出/导入。
您可以尝试使用此示例序列化特定用户的角色:
import java.io.*;
import com.sap.security.api.IUser;
import com.sap.security.api.UMFactory;
// getting current user
try {
IUser user = UMFactory.getAuthenticator().getLoggedInUser();
if (user == null) { throw new SecurityException("User is invalid"); }
// getting user roles
Iterator<String> roles = loggedInUser.getRoles(true);
// serializing roles
while (roles.hasNext()) {
String roleId = roles.next();
IRole role = UMFactory.getRoleFactory().getRole(roleId);
FileOutputStream file = new FileOutputStream(filename);
ObjectOutputStream out = new ObjectOutputStream(file);
out.writeObject(role);
out.close();
file.close();
}
} catch (Exception e) {
logger.logError("[getAssignedRole] Error " + e.getMessage());
}https://stackoverflow.com/questions/56165372
复制相似问题