Export/Import of SAP UME roles using Java

1k Views Asked by At

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

There are 1 best solutions below

3
Suncatcher On

Utilize SAP Composition Environment set of APIs, particularly Security API

The com.sap.security.api namespace contains IUserAccountFactory factory has getUserAccount(s) method which returns IUserAccount object (array of objects). It has getRoles method which perfectly meets your needs.

Together with addToRole method you can implement export/import of roles.

You can try to serialize roles of specific user with this sample:

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());
}