- 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
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;
}
}
Hi Som,
ReplyDeleteThank you so much for this code.
This information really helped me a lot. It was very informative.
ReplyDeleteIdentity & Access Management Solution