Monday 18 June 2018

Code to get IT Resource properties in OIM



  • It is necessary to get IT Resource properties in OIM to know connection parameters of target system in OIM; specially the password which is encrypted.
  • This method is useful for many requirements like developing a connector or a scheduler.
  • The below code can be used for the same with minor changes as per the environment.
  • Required to change the OIM host & port and its credentials and the path of authwl.conf to connect to OIM environment.
  • Required to change IT Resource name and its paremeters   
         e.g.here ITR name is DSEE Server and parameters are baseContexts,principal,credentials etc.
         


CODE


package com.code;

import java.sql.Connection;
import java.sql.DriverManager;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Map;
import javax.security.auth.login.LoginException;
import oracle.iam.platform.OIMClient;
import oracle.iam.platform.Platform;
import Thor.API.tcResultSet;
import Thor.API.Exceptions.tcAPIException;
import Thor.API.Exceptions.tcColumnNotFoundException;
import Thor.API.Exceptions.tcITResourceNotFoundException;
import Thor.API.Operations.tcITResourceInstanceOperationsIntf;
import Thor.API.Operations.tcLookupOperationsIntf;

public class GetITResourceProperties {
private static OIMClient oimClient;
static Map<String, String> mapITResource = new HashMap<String, String>();
public static void main(String[] args) {
GetITResourceProperties obj = new GetITResourceProperties();
try {
oimClient = obj.oimClient();
mapITResource = obj.getITResourcesProperties("DSEE Server");//Provide correct IT Resource Name
String url = (String) mapITResource.get("baseContexts");
String user = (String) mapITResource.get("principal");
String password = (String) mapITResource.get("credentials");
System.out.println("url : " + url);
System.out.println("user : " + user);
System.out.println("password : " + password);
} catch (LoginException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
public OIMClient oimClient() throws LoginException {
System.out.println("Creating client....");
String ctxFactory = "weblogic.jndi.WLInitialContextFactory";
String serverURL = "http://localhost:14000"; //Provide correct OIM Host & Port Name
System.setProperty("java.security.auth.login.config",
"E:\\Auth\\authwl.conf");            //Provide correct path of authwl.conf
System.setProperty("APPSERVER_TYPE", "wls");
String username = "xelsysadm";
char[] password = "Abcd1234".toCharArray();
Hashtable<String, String> env = new Hashtable<String, String>();
env.put(OIMClient.JAVA_NAMING_FACTORY_INITIAL, ctxFactory);
env.put(OIMClient.JAVA_NAMING_PROVIDER_URL, serverURL);

oimClient = new OIMClient(env);
System.out.println("Logging in");
oimClient.login(username, password);
System.out.println("Log in successful");
return oimClient;
}
private static Map<String, String> getITResourcesProperties(
String itResourceName) {
System.out.println("Inside getITResourcesProperties method");
tcITResourceInstanceOperationsIntf resourceFactory = null;
long vdResourceKey = 0L;
Map<String, String> result = new HashMap<String, String>();
try {
resourceFactory = (tcITResourceInstanceOperationsIntf) oimClient
.getService(tcITResourceInstanceOperationsIntf.class);
Map<String, String> filter = new HashMap<String, String>();
filter.put("IT Resource.Name", itResourceName);
tcResultSet resources = resourceFactory.findITResourceInstances(filter);
vdResourceKey = resources.getLongValue("IT Resource.Key");
System.out.println("IT Resource key : " + vdResourceKey);
tcResultSet params = resourceFactory.getITResourceInstanceParameters(vdResourceKey);
for (int j = 0, objectRowCount = params.getRowCount(); j < objectRowCount; j++) {
params.goToRow(j);
result.put(params.getStringValue("IT Resources Type Parameter.Name"),
params.getStringValue("IT Resource.Parameter.Value"));
}
} catch (tcAPIException e) {
e.printStackTrace();
} catch (tcColumnNotFoundException e) {
e.printStackTrace();
} catch (tcITResourceNotFoundException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
return result;
}

}

                  

                                                   *****Thanks for visiting*****


2 comments:

   Here we are going to discuss the steps required in detail, to extend a connector in OIM for provisioning to target system. Steps are s...