Tuesday 19 December 2017

OIM API - Code snippet to get IT Resource Key by Application Instance Name.

public String getItResourceKey(String applicationInstanceName) {
    String methodName = "getItResourceKey()";
    System.out.println(methodName + " :: Enter");
    String itrKey = null;
    ApplicationInstance appInst = null;
   
    //get application instance service
    ApplicationInstanceService appService = Platform.getService(ApplicationInstanceService.class);
   
    if(!applicationInstanceName.trim().isEmpty() && applicationInstanceName.trim() != null) {
        System.out.println(methodName + " :: Fetching IT Resource Key for application [" + applicationInstanceName + "]");
        try {
            appInst = appService.findApplicationInstanceByName(applicationInstanceName);
            itrKey = String.valueOf(appInst.getItResourceKey());

            System.out.println("itrKey :: " + itrKey);
        } catch (Exception e) {
            System.out.println(methodName + " :: Exception occured :" + e);
        }
    } else {
        System.out.println(methodName + " :: Appliction Instance Name is null or empty");
    }
    System.out.println(methodName + " :: Exit");
    return itrKey;
}

OIM API - Stand Alone Code to Provision Account to User.


To execute below code you have to add following jars in classpath:


  • commons-logging.jar
  • eclipselink.jar
  • jrf-api.jar
  • oimclient.jar
  • spring.jar
  • wlfullclient.jar

Stand Alone Code:


import java.util.HashSet;
import java.util.Hashtable;
import java.util.List;
import java.util.Set;
import javax.security.auth.login.LoginException;
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.entitymgr.vo.SearchCriteria;
import oracle.iam.provisioning.api.ApplicationInstanceService;
import oracle.iam.provisioning.api.ProvisioningService;
import oracle.iam.provisioning.vo.Account;
import oracle.iam.provisioning.vo.AccountData;
import oracle.iam.provisioning.vo.ApplicationInstance;
import oracle.iam.provisioning.vo.FormField;
import oracle.iam.provisioning.vo.FormInfo;

public class ProvisionAccountToUser {
        OIMClient client = null;
         
        //identity self service details
        String username = "xelsysadm";
        String password = "<password>"; //xelsysadm password
        String t3url = "t3://<hostname>:<port>"; //OIM HostName and Port
        String authwl_location = "<location of authwl.conf file in your local machine>";
     
        public void getOIMConnection(){
            System.out.println("getOIMConnection() : Start");
            //set system properties
            System.setProperty("java.security.auth.login.config", authwl_location);
            System.setProperty("OIM.AppServerType", "wls");
            System.setProperty("APPSERVER_TYPE", "wls");

            Hashtable oimenv = new Hashtable();
            oimenv.put(OIMClient.JAVA_NAMING_FACTORY_INITIAL, "weblogic.jndi.WLInitialContextFactory");
            oimenv.put(OIMClient.JAVA_NAMING_PROVIDER_URL,t3url);
            client = new OIMClient(oimenv);
            try {
                client.login(username, password.toCharArray());
                System.out.println("Connected Successfully...");
            } catch (LoginException e) {
                e.printStackTrace();
            }
            System.out.println("getOIMConnection() : End");
        }
      
        public void provisionAccount(String appInsName, String userId) throws Exception{
            ProvisioningService service= client.getService(ProvisioningService.class);
            ApplicationInstance appInstance = null;
            String usrKey = "";
            try {
                  //get application instance object by application instance name
                  appInstance = getApplicationInstanceByName(appInsName);
              
                  //get user key by user login
                  usrKey = getUserKey(userId);
                
                  //prepare process form
                  FormInfo formInfo = appInstance.getAccountForm();
                  FormField f1 = new FormField();
                  f1.setName("Account Name");
                  f1.setDefaultValue(userId);
                  formInfo.addFormField(f1);
      
                  String formKey = String.valueOf(formInfo.getFormKey());
      
                  AccountData accountData = new AccountData(formKey, null, null);
                  Account account = new Account(appInstance, accountData);
              
                  //set Account type
                  account.setAccountType(Account.ACCOUNT_TYPE.Primary);
                  service.provision(usrKey, account);
                
                  System.out.println(appInsName + " Provisioned to " + userId);
                            
                }catch(Exception e) {
                    e.printStackTrace();
                }
        }

        public String getUserKey(String userLogin) throws Exception{
            String userKey = "" ;
            Set<String> retAttrs = new HashSet<String>();
            retAttrs.add(UserManagerConstants.AttributeName.USER_KEY.getId());

            SearchCriteria criteria1 = new SearchCriteria(UserManagerConstants.AttributeName.USER_LOGIN.getId(), userLogin, SearchCriteria.Operator.EQUAL);
            UserManager userService = client.getService(UserManager.class);
            List<User> users = userService.search(criteria1, retAttrs, null);

            if (!users.isEmpty()) {
                for (User user : users) {
                        userKey = user.getEntityId();
                    }
            }
            return userKey;
        }
      
        public ApplicationInstance getApplicationInstanceByName(String applicationInstanceName) throws Exception {
            ApplicationInstanceService service= client.getService(ApplicationInstanceService.class);
            ApplicationInstance appInstance = service.findApplicationInstanceByName(applicationInstanceName);
            return appInstance;
          }
        
        public static void main(String[] args) throws Exception {
            ProvisionAccountToUser provisionAccountToUser = new ProvisionAccountToUser();
            provisionAccountToUser.getOIMConnection();
          
            //e.g: provisionAccountToUser.provisionAccount("ServiceNow","Test1");
            provisionAccountToUser.provisionAccount("<Application Instance Name>","<User Login>");
        }
}


Happy Learning!!!

OIM API - Code snippet to get Application Instance from OIM for the given Application Instance Name.


Using Search Criteria:

public ApplicationInstance getApplicationInstance(String appIntName){
        final String logp = CN + "::
getApplicationInstance - ";
        LOGGER.debug(logp + "START");

        if(null == appIntName || appIntName.trim().length() == 0){
                LOGGER.error(logp + "Application Instance name is null or empty");
                return null;
        }
        appIntName = appIntName.trim();

        ApplicationInstance appInst = null;
        try{
            SearchCriteria criteria = new SearchCriteria(ApplicationInstance.APPINST_NAME, appIntName, SearchCriteria.Operator.EQUAL);
           
            //get application instance service
            ApplicationInstanceService appInstService = Platform.getService(ApplicationInstanceService.class);
            List<ApplicationInstance> appInstList = appInstService.findApplicationInstance(criteria, null);

            if(appInstList.size() == 0 || appInstList.size() > 1) {
                LOGGER.error(logp + "Improper number of ApplicationInstance found in OIM for Application Instance name " + appIntName + " - " + appInstList.size());
            }else{
                appInst = appInstList.get(0);


                LOGGER.info(logp + "Successfully obtained ApplicationInstance - " + appInst);
                LOGGER.info(logp + "Application Instance Key :: " + appInst.getApplicationInstanceKey());
                LOGGER.info(logp + "Display Name :: " + appInst.getDisplayName());
                LOGGER.info(logp + "Application Instance Name :: " + appInst.getApplicationInstanceName());
            }
        }catch(Exception e) {
                LOGGER.error(logp + "Exception while fetching ApplicationInstance for Application Instance name " + appIntName + " - " + e, e);
        }

        LOGGER.debug(logp + "END");
        return appInst;
 }


Without Search Criteria:

public ApplicationInstance getApplicationInstance(String applicationInstanceName) throws Exception{
        //get application instance service
        ApplicationInstanceService service= Platform.getService(ApplicationInstanceService.class);
      
        ApplicationInstance appInstance = service.findApplicationInstanceByName(applicationInstanceName);
       
        System.out.println("Display Name :: " + appInstance.getDisplayName());


        System.out.println("Application Instance Name :: " + appInstance.getApplicationInstanceName());


        System.out.println("Application Instance Key :: " + appInstance.getApplicationInstanceKey());
        return appInstance;
 }


Happy Learning!!!

OIM API - Code Snippet to Create Application Instance.

public void createApplicationInstance() throws Exception{
    ApplicationInstanceService appService = Platform.getService(ApplicationInstanceService.class);
  
    String applicationInstanceName = "TestDisconnectedApp";
   
    ApplicationInstance newAppInstance = new ApplicationInstance();
    //Set Application Instance Name
    newAppInstance.setApplicationInstanceName(applicationInstanceName);
    //Set Application Instance type(Set it as per requirement)
    newAppInstance.setType(ApplicationInstance.TYPE.Disconnected);
    //Set Application Instance Display Name
    newAppInstance.setDisplayName(applicationInstanceName);
    appService.addApplicationInstance(newAppInstance);
    System.out.println("Application Created Successfully :: " + applicationInstanceName);
}


Happy Learning!!!

OIM API - Stand Alone Code to Register/Unregister Plugin.


To execute below code you have to add following jars in classpath:


  • commons-logging.jar
  • eclipselink.jar
  • jrf-api.jar
  • oimclient.jar
  • spring.jar
  • wlfullclient.jar


Stand Alone Code:

 

import java.io.File;
import java.io.FileInputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.Hashtable;
import javax.security.auth.login.LoginException;
import oracle.iam.identity.exception.NoSuchUserException;
import oracle.iam.identity.exception.SearchKeyNotUniqueException;
import oracle.iam.identity.exception.UserManagerException;
import oracle.iam.identity.usermgmt.api.UserManager;
import oracle.iam.identity.usermgmt.api.UserManagerConstants;
import oracle.iam.platform.OIMClient;
import oracle.iam.platform.authz.exception.AccessDeniedException;
import oracle.iam.platform.pluginframework.PluginException;
import oracle.iam.platformservice.api.PlatformService;
import oracle.iam.platformservice.exception.PlatformServiceAccessDeniedException;
import com.bea.common.security.xacml.IOException;


public class PluginUtility {
    static OIMClient oimClient = null;
       
    //identity self service details
    String username = "xelsysadm";
    String password = "<password>"; //xelsysadm password
    String t3url = "t3://<hostname>:<port>"; //OIM HostName and Port
    String authwl_location = "<location of authwl.conf file in your local machine>";
   
    public void getOIMConnection() {
        System.out.println("getOIMConnection() : Start");
        //set system properties
        System.setProperty("java.security.auth.login.config", authwl_location);
        System.setProperty("OIM.AppServerType", "wls");
        System.setProperty("APPSERVER_TYPE", "wls");

        Hashtable oimenv = new Hashtable();
        oimenv.put(OIMClient.JAVA_NAMING_FACTORY_INITIAL, "weblogic.jndi.WLInitialContextFactory");
        oimenv.put(OIMClient.JAVA_NAMING_PROVIDER_URL,t3url);
        oimClient = new OIMClient(oimenv);
        try {
            oimClient.login(username, password.toCharArray());
            System.out.println("Connected");
        } catch (LoginException e) {
            e.printStackTrace();
        }
        System.out.println("getOIMConnection() : End");
    }

    public void registerPlugin() throws Exception{
        System.out.println("registerPlugin() : Start");
        System.setProperty("java.security.policy","<location of xl.policy file in your local machine>"); //eg. D:\\designconsole\\config\\xl.policy"

        PlatformService service = oimClient.getService(PlatformService.class);
        System.out.println("Platforn service initialised..: "+service.toString());
      
        File zipFile = new File("<plugin file path>"); //e.g: D:\\plugin.zip
        System.out.println("File read from the system...");
        FileInputStream fis = new FileInputStream(zipFile);
        System.out.println("Input stream created...");
      
        int size = (int) zipFile.length();
        byte[] b = new byte[size];
        int bytesRead = fis.read(b, 0, size);
      
        while (bytesRead < size) {
            bytesRead += fis.read(b, bytesRead, size - bytesRead);
        }
        fis.close();
      
        System.out.println("Register plugin...");
        service.registerPlugin(b);      
   
        System.out.println("Plugin Registered Successfully");
        System.out.println("registerPlugin() : End");
    }
   
    public void unregisterPlugin() throws Exception{
        System.out.println("unregisterPlugin() : Start");
        System.setProperty("java.security.policy","<location of xl.policy file in your local machine>"); //eg. D:\\designconsole\\config\\xl.policy"

        PlatformService service = oimClient.getService(PlatformService.class);
        System.out.println("Platforn service initialised..: "+service.toString());
        System.out.println("Unregister plugin...");
      
        //e.g: service.unRegisterPlugin("com.plugin.example.OIMNotification", "1.0");  
        service.unRegisterPlugin("<full qualified class name>", "<version>");      

        System.out.println("Plugin Unregistered Successfully");
        System.out.println("unregisterPlugin() : End");
    }
   
    public static void main(String[] args) {
        try {
            PluginUtility pluginUtility = new PluginUtility();
          
            //get OIM handle
            pluginUtility.getOIMConnection();
          
            //register plugin
            pluginUtility.registerPlugin();
          
            //unregister plugin
            //pluginUtility.unregisterPlugin();
      
        } catch (Exception e) {
            e.printStackTrace();
        }                   
    }

 Happy Learning!!!

Saturday 16 September 2017

OIM API - How to Update Process Form Data using tcFormInstanceOperationsIntf API?


To execute below code you have to add following jars in classpath:


  • commons-logging.jar
  • eclipselink.jar
  • jrf-api.jar
  • oimclient.jar
  • spring.jar
  • wlfullclient.jar

Stand Alone Code:


public class ProcessFormDataOps{
       static OIMClient oimClient = null;
        
        //identity self service details
        String username = "xelsysadm";
        String password = "<password>"; //xelsysadm password
        String t3url = "t3://<hostname>:<port>"; //OIM HostName and Port
        String authwl_location = "<location of authwl.conf file in your local machine>"; //eg. D:\\authwl.conf
        
        public void getOIMConnection() {
            System.out.println("getOIMConnection() : Start");
            //set system properties
            System.setProperty("java.security.auth.login.config", authwl_location);
            System.setProperty("OIM.AppServerType", "wls");
            System.setProperty("APPSERVER_TYPE", "wls");
    
            Hashtable oimenv = new Hashtable();
            oimenv.put(OIMClient.JAVA_NAMING_FACTORY_INITIAL, "weblogic.jndi.WLInitialContextFactory");
            oimenv.put(OIMClient.JAVA_NAMING_PROVIDER_URL,t3url); 
            oimClient = new OIMClient(oimenv);
            try {
                oimClient.login(username, password.toCharArray());
                System.out.println("Connected");
            } catch (LoginException e) {
                e.printStackTrace();
            }
            System.out.println("getOIMConnection() : End");
        }

      public void updateProcessFormData(long pkey, Map updateProFrmDataMap){
          tcFormInstanceOperationsIntf formInstanceIntf = oimClient.getService(tcFormInstanceOperationsIntf.class);
          try {
        System.out.println("Update Process From Data Map :: " + updateProFrmDataMap);
            formInstanceIntf.setProcessFormData(pkey, updateProFrmDataMap);
            System.out.println("Process form data updated successfully");
          } catch(Exception e){
        e.printStackTrace();
          }
       }
    
    public static void main(String[] args) {
        ProcessFormDataOps processFormDataOps = new ProcessFormDataOps();
        processFormDataOps.connect();
        
        //Process Instance Key
        long proInsKey = 140683; 
        
        //Add all attributes which need to be updated
        Map updateProFrmDataMap = new HashMap();

        //updateProFrmDataMap.put("<Column_Name>", "<Attribute_Value>");
        updateProFrmDataMap.put("UD_ADUSER_FIRSTNAME", "Anand");
        updateProFrmDataMap.put("UD_ADUSER_LASTNAME", "Badal");
        processFormDataOps.updateProcessFormData(proInsKey, updateProFrmDataMap);
    }
}


Happy Learning!!!

OIM API - Stand Alone Code to Read Process Form Data.

  To execute below code you have to add following jars in classpath:

  • commons-logging.jar
  • eclipselink.jar
  • jrf-api.jar
  • oimclient.jar
  • spring.jar
  • wlfullclient.jar

 

Stand Alone Code:


public class ProcessFormDataOps{
       static OIMClient oimClient = null;
        
        //identity self service details
        String username = "xelsysadm";
        String password = "<password>"; //xelsysadm password
        String t3url = "t3://<hostname>:<port>"; //OIM HostName and Port
        String authwl_location = "<location of authwl.conf file in your local machine>"; //eg. D:\\authwl.conf
        
        public void getOIMConnection() {
            System.out.println("getOIMConnection() : Start");
            //set system properties
            System.setProperty("java.security.auth.login.config", authwl_location);
            System.setProperty("OIM.AppServerType", "wls");
            System.setProperty("APPSERVER_TYPE", "wls");
    
            Hashtable oimenv = new Hashtable();
            oimenv.put(OIMClient.JAVA_NAMING_FACTORY_INITIAL, "weblogic.jndi.WLInitialContextFactory");
            oimenv.put(OIMClient.JAVA_NAMING_PROVIDER_URL,t3url); 
            oimClient = new OIMClient(oimenv);
            try {
                oimClient.login(username, password.toCharArray());
                System.out.println("Connected");
            } catch (LoginException e) {
                e.printStackTrace();
            }
            System.out.println("getOIMConnection() : End");
        }

public void getProcessFormData(long processInstanceKey){
   System.out.println("getProcessFormData() : Start");
tcFormInstanceOperationsIntf formInstanceIntf = oimClient.getService(tcFormInstanceOperationsIntf.class);
try {
tcResultSet trs = formInstanceIntf.getProcessFormData(processInstanceKey);
int count = trs.getRowCount();
for (int i = 0; i < count; i++) {
trs.goToRow(i);
String columnNames[] = trs.getColumnNames();
for (String fieldName : columnNames) {
System.out.println(fieldName + " :: " + trs.getStringValue(fieldName));
}
}
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("getProcessFormData() : End");
}
public static void main(String[] args) {
ProcessFormDataOps processFormDataOps = new ProcessFormDataOps();
processFormDataOps.connect();
long proInsKey = 140683; //Process Instance Key
processFormDataOps.getProcessFormData(proInsKey);
}
}


Happy Learning!!!

Sunday 10 September 2017

OIM - SQL query to get all proxy assigned for users.

SELECT DISTINCT USR.USR_LOGIN "User_Login", 
PU.USR_LOGIN "Proxy_User_Login",
TO_CHAR(P.PXD_START_DATE,'DD-MON-YYYY') "Proxy_Start_Date",
TO_CHAR(P.PXD_END_DATE,'DD-MON-YYYY') "Proxy_End_Date"
FROM PXD P, USR, USR PU
WHERE P.PXD_ORIG_USR_KEY = USR.USR_KEY
AND P.PXD_PROXY_KEY = PU.USR_KEY
AND P.PXD_END_DATE > SYSDATE;

OIM - How to Migrate User's Proxy from one environment to other environment in OIM?

First export proxy details from source OIM :-


Execute below SQL query to get all proxy assigned for users:


SELECT DISTINCT USR.USR_LOGIN "User_Login", 
PU.USR_LOGIN "Proxy_User_Login",
TO_CHAR(P.PXD_START_DATE,'DD-MON-YYYY') "Proxy_Start_Date",
TO_CHAR(P.PXD_END_DATE,'DD-MON-YYYY') "Proxy_End_Date"
FROM PXD P, USR, USR PU
WHERE P.PXD_ORIG_USR_KEY = USR.USR_KEY
AND P.PXD_PROXY_KEY = PU.USR_KEY
AND P.PXD_END_DATE > SYSDATE;

Export Proxy details in CSV file:





Execute below code to add proxy for users on destination OIM :-


To execute below code you have to add following jars in classpath:

  • commons-logging.jar

  • eclipselink.jar

  • jrf-api.jar

  • oimclient.jar

  • spring.jar

  • wlfullclient.jar

 

Stand Alone Code:


import java.util.Date;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.Set;
import javax.security.auth.login.LoginException;
import oracle.iam.platform.OIMClient;
import oracle.iam.platformservice.api.PlatformUtilsService;
import oracle.iam.platformservice.exception.PlatformServiceException;
import oracle.iam.platformservice.vo.JarElement;

public class OIMProxyOperation{
        OIMClient oimClient = null;
        
        //identity self service details
        String username = "xelsysadm";
        String password = "<password>"; //xelsysadm password
        String t3url = "t3://<hostname>:<port>"; //Destination OIM HostName and Port
        String authwl_location = "<location of authwl.conf file in your local machine>"; //eg. D:\\authwl.conf
        
        public void getOIMConnection() {
            System.out.println("getOIMConnection() : Start");
            //set system properties
            System.setProperty("java.security.auth.login.config", authwl_location);
            System.setProperty("OIM.AppServerType", "wls");
            System.setProperty("APPSERVER_TYPE", "wls");
    
            Hashtable oimenv = new Hashtable();
            oimenv.put(OIMClient.JAVA_NAMING_FACTORY_INITIAL, "weblogic.jndi.WLInitialContextFactory");
            oimenv.put(OIMClient.JAVA_NAMING_PROVIDER_URL,t3url); 
            oimClient = new OIMClient(oimenv);
            try {
                oimClient.login(username, password.toCharArray());
                System.out.println("Connected");
            } catch (LoginException e) {
                e.printStackTrace();
            }
            System.out.println("getOIMConnection() : End");
        }

    public void addProxy(String csvFile) {
        System.out.println("addProxy() : Start");
        UserManager userManager = oimClient.getService(UserManager.class);
        BufferedReader br = null;
        String line = "";
        String cvsSplitBy = ",";
        int i = 0;
        try {     
            //Code for csv reader
            br = new BufferedReader(new FileReader(csvFile));
            br.readLine();
            while ((line = br.readLine()) != null) {
                String[] str = line.split(cvsSplitBy);
                String userLogin = str[0];
                String proxyUserLogin = str[1];
                String startDate = str[2];
                String endDate = str[3];
                
                Date proxyStartDate = new SimpleDateFormat("dd-MMM-yyyy").parse(startDate);
                Date proxyEndDate = new SimpleDateFormat("dd-MMM-yyyy").parse(endDate);
                System.out.println("UserLogin :: " + userLogin + " " + "ProxyUserKey :: " + proxyUserLogin + " " + "Proxy Start Date :: " + proxyStartDate + " " + "Proxy End Date :: " + proxyEndDate);
                userManager.addProxyForUser(userLogin, proxyUserLogin, proxyStartDate, proxyEndDate, true);
                i++;
            }
            System.out.println("User updated count :" + i);
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println("addProxy() : End");
        }
        
    public static void main(String[] args) {
        try {
            OIMProxyOperation obj = new OIMProxyOperation();
            obj.getOIMConnection();
            String csvFile = "D:\\ProxyDetails.csv"; //location of csv file
            obj.addProxy(csvFile);
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
    }
}


Happy Learning!!!

OIM API - Stand alone code to Upload/Update/Delete Jar.

To execute below code you have to add following jars in classpath:

  • commons-logging.jar

  • eclipselink.jar

  • jrf-api.jar

  • oimclient.jar

  • spring.jar

  • wlfullclient.jar

 

Stand Alone Code:


import java.util.Date;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.Set;
import javax.security.auth.login.LoginException;
import oracle.iam.platform.OIMClient;
import oracle.iam.platformservice.api.PlatformUtilsService;
import oracle.iam.platformservice.exception.PlatformServiceException;
import oracle.iam.platformservice.vo.JarElement;

public class CustomJarUtilities {
       static OIMClient oimClient = null;
        
        //identity self service details
        String username = "xelsysadm";
        String password = "<password>"; //xelsysadm password
        String t3url = "t3://<hostname>:<port>"; //OIM HostName and Port
        String authwl_location = "<location of authwl.conf file in your local machine>"; //eg. D:\\authwl.conf
        
 public void getOIMConnection() {
            System.out.println("getOIMConnection() : Start");
            //set system properties
            System.setProperty("java.security.auth.login.config", authwl_location);
            System.setProperty("OIM.AppServerType", "wls");
            System.setProperty("APPSERVER_TYPE", "wls");
    
            Hashtable oimenv = new Hashtable();
            oimenv.put(OIMClient.JAVA_NAMING_FACTORY_INITIAL, "weblogic.jndi.WLInitialContextFactory");
            oimenv.put(OIMClient.JAVA_NAMING_PROVIDER_URL,t3url); 
            oimClient = new OIMClient(oimenv);
            try {
                oimClient.login(username, password.toCharArray());
                System.out.println("Connected");
            } catch (LoginException e) {
                e.printStackTrace();
            }
            System.out.println("getOIMConnection() : End");
        }

public void uploadJar(PlatformUtilsService service, String jarType, String jarPath){
            System.out.println("uploadJar() : Start");
            System.out.println("Jar Path : " + jarPath);
            System.out.println("Jar Type : " + jarType);
            Set<JarElement> jarElement = new HashSet<JarElement>();
            JarElement elem = new JarElement();
            elem.type = jarType;
            elem.path = jarPath;
            jarElement.add(elem);
            try {
                    service.uploadJars(jarElement);
            } catch (PlatformServiceException e) {
                    System.out.println("Upload Jar Operation Failed ...");
                    e.printStackTrace();
            }
            System.out.println("Jar Uploaded Successfully ...");
   System.out.println("uploadJar() : End");
}

public void updateJar(PlatformUtilsService service, String jarType, String jarPath){
            System.out.println("updateJar() : Start");
            System.out.println("Jar Path : " + jarPath);
            System.out.println("Jar Type : " + jarType);
            Set<JarElement> jarElement = new HashSet<JarElement>();
            JarElement elem = new JarElement();
            elem.type = jarType;
            elem.path = jarPath;
            jarElement.add(elem);
            try {
                    service.updateJars(jarElement);
            } catch (PlatformServiceException e) {
                    System.out.println("Update Jar Operation Failed ...");
                    e.printStackTrace();
            }
            System.out.println("Jar Updated Successfully ...");
   System.out.println("updateJar() : End");
}

 public void deleteJar(PlatformUtilsService service, String jarType, String jarPath){
            System.out.println("deleteJar() : Start");
            System.out.println("Jar Path : " + jarPath);
            System.out.println("Jar Type : " + jarType);
            Set<JarElement> jarElement = new HashSet<JarElement>();
            JarElement elem = new JarElement();
            elem.type = jarType;
            elem.path = jarPath;
            jarElement.add(elem);
            try {
                    service.deleteJars(jarElement);
            } catch (PlatformServiceException e) {
                    System.out.println("Delete Jar Operation Failed ...");
                    e.printStackTrace();
            }
            System.out.println("Jar Deleted Successfully ..."); 
            System.out.println("deleteJar() : End");
        }
        
public static void main(String[] args) {
             CustomJarUtilities customJarUtility = new CustomJarUtilities();
             customJarUtility.getOIMConnection();
             if(oimClient != null){
                PlatformUtilsService service = (PlatformUtilsService)oimClient.getService(PlatformUtilsService.class);
                
                //Possible Values : "JavaTasks" , "ICFBundle", "ScheduleTask", "ThirdParty";
                String jarType = "JavaTasks";
                
                //The Jars location should be on the OIM installed machine
                String jarPath = "/home/oracle/customJars/test.jar";
                
                /******** Upload Jar ********/
                customJarUtility.uploadJar(service, jarType, jarPath);
                
                /******** Update Jar ********/
                customJarUtility.updateJar(service, jarType, jarPath);
                 
                /******** Delete Jar ********/
                customJarUtility.deleteJar(service, jarType, jarPath);
                 
                oimClient.logout();
             }
             else{
                     System.out.println(new Date() +" oimClient is null");
             } 
}
}