OIM API To Create Users in Multi Threaded Code


package com.users;

import java.util.HashMap;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

import com.connection.Platform;

import oracle.iam.identity.exception.UserAlreadyExistsException;
import oracle.iam.identity.exception.UserCreateException;
import oracle.iam.identity.exception.ValidationFailedException;
import oracle.iam.identity.usermgmt.api.UserManager;
import oracle.iam.identity.usermgmt.vo.User;
import oracle.iam.identity.usermgmt.vo.UserManagerResult;
import oracle.iam.identity.utils.Constants;
import oracle.iam.platform.authz.exception.AccessDeniedException;

public class CreateUsersMultiThread {
public static void main(String args[]){
 BlockingQueue<Runnable> bQueue = new LinkedBlockingQueue<>();
 ThreadPoolExecutor executor = new ThreadPoolExecutor(10, 10, 0, TimeUnit.SECONDS, bQueue);
 
 for(int i=0;i<100;i++){
  final String userLogin ="TUSER"+i;
  Runnable r = new CreateUsers(userLogin);
  executor.execute(r);
 }
 executor.shutdown();
}


static class CreateUsers implements Runnable{
 private String userLogin="";
 
 public CreateUsers(String userLogin){
 this.userLogin=userLogin;
 
 }
 public void run(){
  UserManager userManager = Platform.getService(UserManager.class);
  HashMap<String, Object> createAttributes=null;  
  createAttributes = new HashMap<String, Object>();
  
  // create users
   //int i =16;//getRandomNumber();
   createAttributes.put(Constants.USERID, userLogin);
   createAttributes.put(Constants.FIRSTNAME, "First_" + userLogin);
   createAttributes.put(Constants.LASTNAME, "Last_" + userLogin);    
   //createAttributes.put(Constants.ORGKEY,  Long.parseLong(createOrganizations.createorg()));
   createAttributes.put(Constants.ORGKEY, 1L);
   createAttributes.put(Constants.PASSWORD, "Welcome1");
   createAttributes.put(Constants.EMAIL, "EMAIL_" + userLogin+ "@oracle.com");
   createAttributes.put(Constants.EMPTYPE, "Full-Time");
   createAttributes.put(Constants.USERTYPE,"End-User Administrator");
   //createAttributes.put(Constants.AUTOMATICALLY_DELETED_ON,new Date(2014,6,11));
   System.out.println("  ID -> "+userLogin);
   UserManagerResult result;
   try {
    result = userManager.create(new User(null,createAttributes));   
    System.out.println("getEntityId  user."+result.getEntityId());
    System.out.println("Status  user."+result.getStatus());
   } catch (ValidationFailedException | UserAlreadyExistsException | UserCreateException
     | AccessDeniedException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
   }
   
   //System.out.println("getSucceededResults  user."+result.getSucceededResults());
   //ResetPasswordAsXelysyadmin.resetPassword(result.getEntityId());
  }
 }
 
}

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