For Client Code below JAR need to be added in Eclipse or JDeveloper.
1) commons-logging.jar
2) jrf-api.jar
3) oimclient.jar
4) spring.jar
5) wlfullclient.jar
Create User Code-
===========================================
import java.util.HashMap;
import java.util.Map;
import javax.security.auth.login.LoginException;
import Thor.API.tcResultSet;
import Thor.API.Operations.tcUserOperationsIntf;
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.platform.OIMClient;
import oracle.iam.platform.authz.exception.AccessDeniedException;
public class UserOperation {
public static OIMClient oimClient;
//Function to Connection to OIM
public void OIMConnection(){
System.out.println("Trying to established oim client");
System.out.println("inside OIM Connection");
String oimInitialContextFactory = "weblogic.jndi.WLInitialContextFactory";
// set up the environment for making the OIM API invocation
java.util.Hashtable<String, String> env = new java.util.Hashtable<String, String>();
env.put(oracle.iam.platform.OIMClient.JAVA_NAMING_FACTORY_INITIAL,oimInitialContextFactory);
env.put(oracle.iam.platform.OIMClient.JAVA_NAMING_PROVIDER_URL, "t3://localhost:14000");
System.out.println("inside OIM Connection11");
System.setProperty("java.security.auth.login.config", "C:\\Software\\designconsole\\designconsole\\config\\authwl.conf"); //Update path of authwl.conf file according to your environment
System.out.println("inside OIM Connection22");
System.setProperty("OIM.AppServerType", "wls");
System.setProperty("APPSERVER_TYPE", "wls");
System.out.println("inside OIM Connection33");
oimClient = new OIMClient(env);
System.out.println("inside OIM Connection44");
try {
oimClient.login("xelsysadm","Welcome123".toCharArray());
} catch (LoginException e) {
e.printStackTrace();
}
System.out.print("Successfully Connected to OIM ");
}
public void createUser(){
System.out.println("Inside Create User Method");
UserManager usermgr = oimClient.getService(UserManager.class);
HashMap<String, Object> userAttributeValueMap = new HashMap<String, Object>();
UserManagerResult userResult = null;
String userKey = null;
userAttributeValueMap.put("act_key", new Long(22));
userAttributeValueMap.put("First Name", "CBS");
userAttributeValueMap.put("Last Name", "Test4");
userAttributeValueMap.put("Email", "cbs@gmail.com");
userAttributeValueMap.put("usr_password", "Welcome@123");
userAttributeValueMap.put("Role", "EMP");
userAttributeValueMap.put("Xellerate Type", "End-User");
userAttributeValueMap.put("usr_manager_key", new Long(13543));
userAttributeValueMap.put("Mobile", "2223334445");
User user = new User("Test", userAttributeValueMap);
try {
userResult=usermgr.create(user);
} catch (ValidationFailedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (UserAlreadyExistsException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (UserCreateException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (AccessDeniedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
userKey = userResult.getEntityId();
System.out.println("\nUser got created...."+userKey);
//Searching the User Login through User Key
tcUserOperationsIntf service = oimClient.getService(tcUserOperationsIntf.class);
Map<String, String> criteria = new HashMap<String, String>();
criteria.put("Users.Key",userKey);
try {
System.out.println("====================SEARCHING BY ONLY ONE CRITERIA-==============");
tcResultSet userresultSet = service.findAllUsers(criteria);
for(int i=0;i<userresultSet.getRowCount();i++)
{
userresultSet.goToRow(i);
System.out.println(userresultSet.getStringValue("Users.User ID"));
}
System.out.println("==================================================================================");
} catch (AccessDeniedException e) {
e.printStackTrace();
}
catch (Exception e) {
System.out.print("Login Exception" + e);
}
}
public static void main(String[] arg) {
UserOperation usinfo=new UserOperation();
usinfo.OIMConnection(); //calling method for connecting to OIM
usinfo.createUser(); //Calling method to create the user in OIM
}
}