OIM API To Create User,Role and Grant Role with Date


  1. package com.oimacademy.role;
  2. import java.text.ParseException;
  3. import java.text.SimpleDateFormat;
  4. import java.util.Calendar;
  5. import java.util.Date;
  6. import java.util.GregorianCalendar;
  7. import java.util.HashMap;
  8. import com.oimacademy.orgs.CreateOrganizations;
  9. import com.oimacademy.users.CreateUsers;
  10. import oracle.iam.identity.exception.ValidationFailedException;
  11. import oracle.iam.identity.rolemgmt.api.RoleManager;
  12. import oracle.iam.identity.rolemgmt.api.RoleManagerConstants;
  13. import oracle.iam.platform.Platform;
  14. public class GrantRoleWithDate {
  15.  public static void main(String[] args) throws NumberFormatException, Exception {
  16.   //local variables
  17.         Date currentDate = new Date();
  18.         String str_Date = "";
  19.         SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");
  20.         Calendar cal = new GregorianCalendar();
  21.         str_Date = formatter.format(cal.getTime());
  22.         Date endDate = (Date) formatter.parse(str_Date);
  23.         System.out.println("EndDate::::::" + endDate);
  24.         //Create requester and role.
  25.         String userKey=CreateUsers.createUsers(Long.parseLong(CreateOrganizations.createorg()));
  26.         String roleKey = CreateRoles.createRole();
  27.         try
  28.         {
  29.           //Login as requester and initiate role request;
  30.             HashMap<String, Object> roleDataMap = new HashMap<String,Object>();
  31.             RoleManager roleManagerService_1=Platform.getService(RoleManager.class);
  32.             roleDataMap.put(RoleManagerConstants.TEMPORAL_END_DATE, endDate);
  33.             String requestID =  roleManagerService_1.grantRoleRequest( "RoleKey", roleKey, "usr_key", userKey, roleDataMap);
  34.             System.out.println( "Requst ID should not be Generated ");
  35.         }
  36.         catch(ValidationFailedException e)
  37.         {
  38.             System.out.println( "End Date cannot be set to prior to the Current Date:::" + e.getErrorMessage());
  39.         }
  40.  }
  41. }

No comments:

Post a Comment