Tuesday 2 June 2015

Client Code for Disabling/Enabling/revoking Application Instances in OIM

OIM Client code fro Disabling/Enabling/Revoking the particular resource for OIM11gR2
=====================================================================================
Below query will fetch the mil_key based on requirement (Disable/Enable/Revoke) which can be used in Java code.

------------------------------------------------------------------------
 mil_key Query for Disabling the AD resource-

 select mil_key , mil_name from mil where tos_key in
(select tos_key from tos where pkg_key in (select pkg_key from pkg where pkg_name ='AD User'))  and mil_name ='Disable User';
------------------------------------------------------------------------
 mil_key Query for Enabling the AD resource-

 select mil_key , mil_name from mil where tos_key in
(select tos_key from tos where pkg_key in (select pkg_key from pkg where pkg_name ='AD User'))  and mil_name ='Enable User';
------------------------------------------------------------------------
 mil_key Query for Revoking the AD resource-

 select mil_key , mil_name from mil where tos_key in
(select tos_key from tos where pkg_key in (select pkg_key from pkg where pkg_name ='AD User'))  and mil_name ='Delete User';
------------------------------------------------------------------------
Table Information-

pkg table- Consists of names and system keys of service processes, which consist of a group of services from the TOS table. Defines a Process in Xellerate.
tos table- Holds information about a process
mil- Holds information about tasks of a process
-------------------------------------------------------------------------
Input file name would be Input1.csv. Input file would be like below-

userLogin1,orcKey1
userLogin2,orcKey2
-------------------------------------------------------------------------
Java Code for
===================================================
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import javax.security.auth.login.LoginException;
import Thor.API.Exceptions.tcAPIException;
import Thor.API.Exceptions.tcTaskNotFoundException;
import Thor.API.Operations.tcProvisioningOperationsIntf;
import oracle.iam.platform.OIMClient;


public class DisableApplication {
public static OIMClient oimClient;
//Pass the mil key fetched from above query as per the requirement
public static String MIL_KEY = "187";
public void OIMConnection(){

String oimInitialContextFactory = "weblogic.jndi.WLInitialContextFactory";
java.util.Hashtable<String, String> env = new java.util.Hashtable<String, String>();
env.put(oracle.iam.platform.OIMClient.JAVA_NAMING_FACTORY_INITIAL,oimInitialContextFactory);
//Provide the OIM t3 URL below
env.put(oracle.iam.platform.OIMClient.JAVA_NAMING_PROVIDER_URL, "t3://localhost:14000");
//provide the authwl.conf file path from your local system. Copy the authwl.conf from designconsole\config to your local system
System.setProperty("java.security.auth.login.config", "C:\\Software\\designconsole\\designconsole\\config\\authwl.conf");
System.setProperty("OIM.AppServerType", "wls");        
   System.setProperty("APPSERVER_TYPE", "wls");
   oimClient = new OIMClient(env);
   try {
//Pass the OIM Admin Username and password
oimClient.login("xelsysadm","Password".toCharArray());
System.out.println("Connected Successfully");
} catch (LoginException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

public void ReadDataFromFile() throws IOException{
String delimeter=",";
String userLogin;
String orcKey;
HashMap userList=new HashMap();
BufferedReader reader=new BufferedReader(new InputStreamReader(new FileInputStream("C:/CB/input1.csv")));
System.out.println("Data Read success");
for(String userDataLine=reader.readLine(); userDataLine!=null; userDataLine=reader.readLine()){
String[] tokens=userDataLine.split(delimeter, 100000);
userLogin = tokens[0];
orcKey = tokens[1];
userList.put(orcKey,userLogin);
System.out.println("UserList is::::"+userList);
}
AddRevokeTask(userList);
//System.out.println("Adding Task");
}
public void AddRevokeTask(HashMap userListMap){
System.out.println("::::Inside Add Revoke Task Method::::");
String userLogin="";
String orcKey="";
tcProvisioningOperationsIntf provOper=oimClient.getService(tcProvisioningOperationsIntf.class);
Iterator itr=userListMap.entrySet().iterator();
int count=0;
while(itr.hasNext())
{
count++;
Map.Entry e=(Map.Entry) itr.next();
orcKey=(String) e.getKey();
//orcKey is process Instance Key
System.out.println("orcKey is::::"+orcKey);
userLogin=(String) e.getValue();
System.out.println("userLogin is::::"+userLogin);
try {
provOper.addProcessTaskInstance(Long.parseLong(MIL_KEY), Long.parseLong(orcKey));

System.out.println("Task has been added successfully");
} catch (NumberFormatException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (tcAPIException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (tcTaskNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}

}
public static void main(String[] args) throws IOException{
DisableApplication da=new DisableApplication();
da.OIMConnection();
da.ReadDataFromFile();

}
}

No comments:

Post a Comment