Saturday 31 March 2018

OIM API - Update Role Details in OIM for the given Role Name.

 public void updateRole(String roleName){
        final String logp = CN + " :: updateRole - ";
        LOGGER.debug(logp + "START");

        //get role manager service
        RoleManager roleManager = Platform.getService(RoleManager.class);
       
        //get Role from OIM for the given Role Name
        Role role = getRole(roleName, roleManager);
       
        try{
            //Set Display Name
            role.setDisplayName("Role Display Name");

            //Set Description
            role.setDescription("Role Description");
                     
            //Update Role Details
            roleManager.modify(role);
           
            LOGGER.info(logp + "Successfully updated role details for - " + role);
           
        }catch(Exception e){
            LOGGER.error(logp + "Exception while updating Role in OIM - " + e, e);
        }

        LOGGER.debug(logp + "END");
 }



public Role getRole(String roleName, RoleManager roleManager){
        final String logp = CN + " :: getRole - ";
        LOGGER.debug(logp + "START");

        if (null == roleName || roleName.trim().length() == 0) {
                return null;
        }
        roleName = roleName.trim();

        Role role = null;
        try {
            SearchCriteria criteria = new SearchCriteria(RoleAttributeName.NAME.getId(), roleName, SearchCriteria.Operator.EQUAL);

            List<Role> roleList = roleManager.search(criteria, null, null);

            if(null == roleList || roleList.size() == 0){
                LOGGER.error(logp + "Role not found in OIM for role name - " + roleName);
            }else if(roleList.size() > 1){
                LOGGER.error(logp + "More than 1 role found in OIM for role name - " + roleName);
            } else {
                role = roleList.get(0);
                LOGGER.info(logp + "Successfully obtained role for role name " + roleName);
            }
        }catch(Exception e){
                LOGGER.error(logp + "Exception while fetching role  " + roleName + " - " + e, e);
        }

        LOGGER.debug(logp + "END");
        return role;
 }


Happy Learning!!!

No comments:

Post a Comment