OIM API To Grant/Provision Role to User using Request API


package com.request;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

import oracle.iam.api.OIMService;
import oracle.iam.exception.OIMServiceException;
import oracle.iam.request.vo.Beneficiary;
import oracle.iam.request.vo.RequestBeneficiaryEntity;
import oracle.iam.request.vo.RequestConstants;
import oracle.iam.request.vo.RequestData;
import oracle.iam.vo.OperationResult;

import com.connection.Platform;

public class RequestRoleToUser {
 private final OIMService oimService  =Platform.getService(OIMService.class);
 
 
 public OperationResult requestRole() throws OIMServiceException{
  List<String> users = new ArrayList<String>();
  users.add("");
  String roleKey="";
   RequestData requestData = new RequestData();
         
         Calendar calendar = Calendar.getInstance();
         calendar.add(Calendar.DATE, 2);

         requestData.setJustification("This is a test");
         requestData.setExecutionDate(calendar.getTime());         
        
         List<Beneficiary> beneficiaries = new ArrayList<Beneficiary>();
         
         for (String userKey : users) {
             Beneficiary beneficiary = new Beneficiary();
             beneficiary.setBeneficiaryKey(userKey);
             beneficiary.setBeneficiaryType(Beneficiary.USER_BENEFICIARY);
             beneficiaries.add(beneficiary);
             beneficiary.setTargetEntities(getTargeEntities(roleKey));
         }
         
         requestData.setBeneficiaries(beneficiaries);
         OperationResult operationResult = oimService.doOperation(requestData, OIMService.Intent.REQUEST);        
         System.out.println("Request submitted with ID: " + operationResult.getRequestID());
         
         return operationResult;
 }
 
    private static List<RequestBeneficiaryEntity> getTargeEntities(String role) {
        RequestBeneficiaryEntity ent1 = new RequestBeneficiaryEntity();
        String entityType = "Role";
        String entitySubType = role;
        ent1.setEntityType(entityType);
        ent1.setEntitySubType(entitySubType);
        ent1.setEntityKey(role);
        ent1.setOperation(RequestConstants.MODEL_ASSIGN_ROLES_OPERATION);
        return new ArrayList<RequestBeneficiaryEntity>(java.util.Arrays.asList(ent1));
    }
 
}

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