Export / Import UME roles using JAVA Code in AS JAVA SAP system

时间:2019-05-16 09:33:45

标签: java sapui5 sap

In NetWeaver Portal it is possible to Import / Export roles. I want to create a custom tool which have the same behavior. How I can achieve this using JAVA code? I couldn't find any Classes or Interfaces to do this in UME API.

Note: The custom tool have many other functionalities and act as a centralized portal for all the JAVA systems.

1 个答案:

答案 0 :(得分:0)

使用SAP Composition Environment组API,尤其是Security API

com.sap.security.api命名空间包含IUserAccountFactory工厂,该工厂具有getUserAccount(s)方法,该方法返回IUserAccount对象(对象数组)。它具有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());
}