Thursday, 5 April 2018

OIM API - How to Create Role in OIM?

public void createRole(){
    final String logp = CN + " :: createRole() - ";
    logger.info(logp + "START");
   
    String roleName = "TestRole";
    String roleDisplayName = "TestRole";
    String roleDescription = "TestRole";

    RoleManager rolemanager;
    RoleManagerResult result;

    try{
         //getting role manager service
         rolemanager = Platform.getService(RoleManager.class);
        
         //Adding parameters for role creation
         HashMap<String, Object> mapAttrs = new HashMap<String, Object>();
       
         mapAttrs.put(RoleManagerConstants.ROLE_NAME, roleName);
         mapAttrs.put(RoleManagerConstants.ROLE_DISPLAY_NAME, roleDisplayName);
         mapAttrs.put(RoleManagerConstants.ROLE_DESCRIPTION, roleDescription);
        
         Role role = new Role(mapAttrs);
         result = rolemanager.create(role);
        
         logger.info(logp + "Role creation ends, Result is - " + result.getStatus());
       
    }catch(Exception e){
        logger.error(logp + "Exception occured while creating role - " + e, e);
    }

    logger.info(logp + "END");


OR

public void createRole(){
    final String logp = CN + " :: createRole() - ";
    logger.info(logp + "START");
   
    String roleName = "TestRole";
    String roleDisplayName = "TestRole";
    String roleDescription = "TestRole";

    RoleManager rolemanager;
    RoleManagerResult result;

    try{
         //getting role manager service
         rolemanager = Platform.getService(RoleManager.class);
       
         Role role = new Role(roleName);
         role.setName(roleName);
         role.setDisplayName(roleDisplayName);
         role.setDescription(roleDescription);
       
         result = rolemanager.create(role);

         logger.info(logp + "Role creation ends, Result is - " + result.getStatus());

    }catch(Exception e){
        logger.error(logp + "Exception occured while creating role - " + e, e);
    }
   
    logger.info(logp + "END");
}

 
Happy Learning!!!

No comments:

Post a Comment