OIM API To Create Role With Category


package com.role;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import oracle.iam.identity.rolemgmt.api.RoleCategoryManager;
import oracle.iam.identity.rolemgmt.api.RoleManager;
import oracle.iam.identity.rolemgmt.api.RoleManagerConstants;
import oracle.iam.identity.rolemgmt.vo.Role;
import oracle.iam.identity.rolemgmt.vo.RoleCategory;
import oracle.iam.identity.rolemgmt.vo.RoleManagerResult;
import oracle.iam.platform.entitymgr.vo.SearchCriteria;

import com.connection.Platform;

public class CreateRoleWithCategory {

 public static void main(String[] args) throws Exception {  
  String roleName = "role1"; 
  String categoryName = "OIM Roles";
  
  RoleManager roleMgr = Platform.getService(RoleManager.class);
  RoleCategoryManager roleCategoryMgr = Platform.getService(RoleCategoryManager.class);
  
  // find role category information
  SearchCriteria criteria = new SearchCriteria(RoleManagerConstants.ROLE_CATEGORY_NAME, categoryName,
    SearchCriteria.Operator.EQUAL);
  Set retSet = new HashSet();
  retSet.add(RoleManagerConstants.ROLE_CATEGORY_NAME);
  retSet.add(RoleManagerConstants.ROLE_CATEGORY_DESCRIPTION);

  List<RoleCategory> categories = roleCategoryMgr.search(criteria, retSet, null);
  RoleCategory roleCat = categories.get(0);
  
  RoleManagerResult roleResult = null;
  HashMap<String, Object> createAttributes = new HashMap<String, Object>();
  
  createAttributes.put(RoleManagerConstants.ROLE_NAME, roleName);
  createAttributes.put(RoleManagerConstants.ROLE_DISPLAY_NAME, roleName);
  createAttributes.put(RoleManagerConstants.ROLE_DESCRIPTION, roleName + " Description");
  createAttributes.put(RoleManagerConstants.ROLE_CATEGORY_KEY, Long.parseLong(roleCat.getEntityId()));
  
  Role role = new Role(createAttributes);

  roleResult = roleMgr.create(role);
  String entityId = roleResult.getEntityId();
  System.out.println("Created role with key = " + entityId);  
 }


}

No comments:

Post a Comment

About OIM

Oracle Identity Management enables organizations to effectively manage the end - to - end life - cycle of user ide...

Popular Posts