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

package com.massiveGaze.role;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.HashMap;

import com.massiveGaze.orgs.CreateOrganizations;
import com.massiveGaze.users.CreateUsers;

import oracle.iam.identity.exception.ValidationFailedException;
import oracle.iam.identity.rolemgmt.api.RoleManager;
import oracle.iam.identity.rolemgmt.api.RoleManagerConstants;
import oracle.iam.platform.Platform;



public class GrantRoleWithDate {

 public static void main(String[] args) throws NumberFormatException, Exception {
  //local variables
        Date currentDate = new Date();
        String str_Date = "";

        SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");
        Calendar cal = new GregorianCalendar();
        str_Date = formatter.format(cal.getTime());
        Date endDate = (Date) formatter.parse(str_Date);

        System.out.println("EndDate::::::" + endDate);

        //Create requester and role.
        String userKey=CreateUsers.createUsers(Long.parseLong(CreateOrganizations.createorg()));
        String roleKey = CreateRoles.createRole();
        try
        {
          //Login as requester and initiate role request;
            HashMap<String, Object> roleDataMap = new HashMap<String,
Object>();
            RoleManager roleManagerService_1=Platform.getService(RoleManager.class);
            roleDataMap.put(RoleManagerConstants.TEMPORAL_END_DATE, endDate);
            String requestID =  roleManagerService_1.grantRoleRequest( "RoleKey", roleKey, "usr_key", userKey, roleDataMap);
            System.out.println( "Requst ID should not be Generated ");
        }
        catch(ValidationFailedException e)
        {
            System.out.println( "End Date cannot be set to prior to the Current Date:::" + e.getErrorMessage());

        }

 }

}

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