import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.HashSet; import java.util.Hashtable; import java.util.List; import javax.security.auth.login.LoginException; import oracle.iam.api.OIMService; import oracle.iam.exception.OIMServiceException; import oracle.iam.identity.exception.NoSuchUserException; import oracle.iam.identity.exception.UserLookupException; import oracle.iam.identity.usermgmt.api.UserManager; import oracle.iam.identity.usermgmt.api.UserManagerConstants; import oracle.iam.identity.usermgmt.vo.User; import oracle.iam.platform.OIMClient; import oracle.iam.platform.Platform; import oracle.iam.platform.utils.vo.OIMType; import oracle.iam.request.vo.Beneficiary; import oracle.iam.request.vo.RequestBeneficiaryEntity; import oracle.iam.request.vo.RequestBeneficiaryEntityAttribute; import oracle.iam.request.vo.RequestConstants; import oracle.iam.request.vo.RequestData; public class ProvisionRole { public static void main(String[] args) throws Exception { init(); requestToProvisionRole("GTCUSER8", "TestRole1", "6"); // getUserKeyByUserLogin("ABHILARE"); } private static OIMClient oimClient; public static void init() throws LoginException { String oimURL = "t3://localhost:14000"; String authwlFilePath = "D:\\PS2Designconsole\\designconsole\\config\\authwl.conf"; String oimUserName = "GTCUSER8"; String oimPassword = "Welcome1"; Hashtable<String, String> env = new Hashtable<String, String>(); env.put(OIMClient.JAVA_NAMING_FACTORY_INITIAL, "weblogic.jndi.WLInitialContextFactory"); env.put(OIMClient.JAVA_NAMING_PROVIDER_URL, oimURL); System.setProperty("java.security.auth.login.config", authwlFilePath); System.setProperty("APPSERVER_TYPE", "wls"); System.setProperty("OIM.AppServerType", "wls"); oimClient = new OIMClient(env); oimClient.login(oimUserName, oimPassword.toCharArray()); System.out.println("Connection Successful..!!"); } public static oracle.iam.vo.OperationResult requestToProvisionRole(String userLogin, String entitlementName, String entKey) throws NoSuchUserException, UserLookupException, OIMServiceException, ParseException { System.out.println("requestToProvisionRole"); String usrKey = getUserKeyByUserLogin(userLogin); RequestBeneficiaryEntity reqBenefEntity = new RequestBeneficiaryEntity(); reqBenefEntity.setRequestEntityType(OIMType.Role); reqBenefEntity.setEntityKey(entKey); reqBenefEntity.setOperation(RequestConstants.MODEL_ASSIGN_ROLES_OPERATION); reqBenefEntity.setEntitySubType("work"); List<RequestBeneficiaryEntityAttribute> entityAttributes = new ArrayList<>(); java.sql.Date stDate; java.util.Date parseDate; SimpleDateFormat sdf = new SimpleDateFormat("yyy-MM-dd'T'HH:mmZ"); sdf.setLenient(false); parseDate = sdf.parse("2018-09-14T03:00+0530"); stDate = new java.sql.Date(parseDate.getTime()); java.sql.Date edDate; parseDate = sdf.parse("2018-09-23T05:20+0530"); edDate = new java.sql.Date(parseDate.getTime()); RequestBeneficiaryEntityAttribute startDate = new RequestBeneficiaryEntityAttribute("startDate", stDate, RequestBeneficiaryEntityAttribute.TYPE.Date); RequestBeneficiaryEntityAttribute endDate = new RequestBeneficiaryEntityAttribute("endDate", edDate, RequestBeneficiaryEntityAttribute.TYPE.Date); entityAttributes.add(startDate); entityAttributes.add(endDate); reqBenefEntity.setEntityData(entityAttributes); List<RequestBeneficiaryEntity> entities = new ArrayList<RequestBeneficiaryEntity>(); entities.add(reqBenefEntity); Beneficiary beneficiary = new Beneficiary(); beneficiary.setBeneficiaryKey(usrKey); beneficiary.setBeneficiaryType(Beneficiary.USER_BENEFICIARY); beneficiary.setTargetEntities(entities); List<Beneficiary> beneficiaries = new ArrayList<Beneficiary>(); beneficiaries.add(beneficiary); RequestData reqData = new RequestData(); reqData.setBeneficiaries(beneficiaries); OIMService oimService = oimClient.getService(OIMService.class); oracle.iam.vo.OperationResult result = oimService.doOperation(reqData, OIMService.Intent.REQUEST); String reqKey = result.getRequestID(); System.out.println("Status : " + result.getOperationStatus()); System.out.println("Request ID: " + result.getRequestID()); // System.out.println("Entity ID : " + result.getEntityId()); return result; } private static String getUserKeyByUserLogin(String userLogin) throws NoSuchUserException, UserLookupException { boolean userLoginUsed = true; HashSet<String> attrsToFetch = new HashSet<String>(); attrsToFetch.add(UserManagerConstants.AttributeName.USER_KEY.getId()); attrsToFetch.add(UserManagerConstants.AttributeName.USER_LOGIN.getId()); UserManager usrMgrOps = oimClient.getService(UserManager.class); User user = usrMgrOps.getDetails(userLogin, attrsToFetch, userLoginUsed); System.out.println(user.getEntityId()); return user.getEntityId(); } }
Oracle Identity Manager (OIM R2PS2/PS3/12C) is a highly flexible and scalable enterprise identity administration system that provides operational and business efficiency by providing centralized administration & complete automation of identity and user provisioning events across enterprise as well as extranet applications.
OIM API Provision Role Based on Start and End Date using Request Engine
Subscribe to:
Posts (Atom)
About OIM
Oracle Identity Management enables organizations to effectively manage the end - to - end life - cycle of user ide...
Popular Posts
-
OIM API's Sample Code : Videos: Massive Gaze Videos Connection Related API's : OIM DB Connection/ Data Source connection ...
-
Videos: Massive Gaze Videos 1. Basic OIM Information 2. MDS Export/Import 3. Steps For R2PS2 / R2PS3 Custom Pre-processor Ev...
-
Videos: Massive Gaze Videos 1. Query to get OIM Provsioned/provisioning Account details 2. Query to get usr keys For Rejected / ...
No comments:
Post a Comment