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


  1. package com.oimacademy.request;
  2. import java.util.ArrayList;
  3. import java.util.Calendar;
  4. import java.util.List;
  5. import oracle.iam.api.OIMService;
  6. import oracle.iam.exception.OIMServiceException;
  7. import oracle.iam.request.vo.Beneficiary;
  8. import oracle.iam.request.vo.RequestBeneficiaryEntity;
  9. import oracle.iam.request.vo.RequestConstants;
  10. import oracle.iam.request.vo.RequestData;
  11. import oracle.iam.vo.OperationResult;
  12. import com.oimacademy.connection.Platform;
  13. public class RequestRoleToUser {
  14.  private final OIMService oimService  =Platform.getService(OIMService.class); 
  15.  public OperationResult requestRole() throws OIMServiceException{
  16.   List<String> users = new ArrayList<String>();
  17.   users.add("");
  18.   String roleKey="";
  19.    RequestData requestData = new RequestData();         
  20.          Calendar calendar = Calendar.getInstance();
  21.          calendar.add(Calendar.DATE, 2);
  22.          requestData.setJustification("This is a test");
  23.          requestData.setExecutionDate(calendar.getTime());        
  24.          List<Beneficiary> beneficiaries = new ArrayList<Beneficiary>();         
  25.          for (String userKey : users) {
  26.              Beneficiary beneficiary = new Beneficiary();
  27.              beneficiary.setBeneficiaryKey(userKey);
  28.              beneficiary.setBeneficiaryType(Beneficiary.USER_BENEFICIARY);
  29.              beneficiaries.add(beneficiary);
  30.              beneficiary.setTargetEntities(getTargeEntities(roleKey));
  31.          }         
  32.          requestData.setBeneficiaries(beneficiaries);
  33.          OperationResult operationResult = oimService.doOperation(requestData, OIMService.Intent.REQUEST);        
  34.          System.out.println("Request submitted with ID: " + operationResult.getRequestID());         
  35.          return operationResult;
  36.          } 
  37.     private static List<RequestBeneficiaryEntity> getTargeEntities(String role) {
  38.         RequestBeneficiaryEntity ent1 = new RequestBeneficiaryEntity();
  39.         String entityType = "Role";
  40.         String entitySubType = role;
  41.         ent1.setEntityType(entityType);
  42.         ent1.setEntitySubType(entitySubType);
  43.         ent1.setEntityKey(role);
  44.         ent1.setOperation(RequestConstants.MODEL_ASSIGN_ROLES_OPERATION);
  45.         return new ArrayList<RequestBeneficiaryEntity>(java.util.Arrays.asList(ent1));
  46.     } 
  47. }

No comments:

Post a Comment