OIM API to Assign Multiple RolesToUser


  1. package com.oimacademy.role;
  2. import java.util.HashSet;
  3. import java.util.List;
  4. import java.util.Set;
  5. import oracle.iam.identity.rolemgmt.api.RoleManager;
  6. import oracle.iam.identity.rolemgmt.vo.Role;
  7. import com.oimacademy.connection.Platform;
  8. public class AssignMutipleRolesToUser {
  9.  public static void main(String[] args) throws Exception {
  10.   String ROLE_NAME_PREFIX = "MyRole*";
  11.    RoleManager roleMgr = Platform.getService(RoleManager.class);
  12.   List<Role> roleList = new SearchRole().searchRoleConfigParams(ROLE_NAME_PREFIX);
  13.   Set userKeys = new HashSet();
  14.   userKeys.add("5005");
  15.   for(Role role: roleList){
  16.      roleMgr.grantRole(role.getEntityId(),userKeys); 
  17.      System.out.println("Granted role -> "+role.getEntityId()+ " To user -> "+userKeys);
  18.   }
  19.  }
  20. }

No comments:

Post a Comment