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:
package com.oimacademy.users;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());
}
}
}
No comments:
Post a Comment