首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Java导出/导入SAP UME角色

问使用Java导出/导入SAP UME角色
EN

Stack Overflow用户
提问于 2019-05-16 17:33:45
回答 1查看 629关注 0票数 1

在NetWeaver门户中,可以导入/导出角色。我想创建一个具有相同行为的自定义工具。如何使用JAVA代码来实现这一点?我在UME API中找不到任何类或接口来做这件事。

注意:定制工具还具有许多其他功能,并充当所有JAVA系统的集中式门户。

EN

回答 1

Stack Overflow用户

发布于 2019-06-03 19:40:32

利用SAP Composition Environment集,特别是Security API

com.sap.security.api命名空间包含IUserAccountFactory工厂,它具有返回IUserAccount对象(对象数组)的getUserAccount(s)方法。它有getRoles方法,完全满足您的需求。

配合addToRole方法,您可以实现角色的导出/导入。

您可以尝试使用此示例序列化特定用户的角色:

代码语言:javascript
复制
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());
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56165372

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档