/*Jar needed - wlfullclient-10.3.6.0.jar, spring.jar, oimclient.jar, jrf-api-11.1.1.0.0.jar & commons-logging-1.2.jar
Steps to run below code
Update Host, Port & password, jar name & Jar path from OIM Machine in belwo code
Get the authwl.conf file from designconsole/config folder and then run below method
Refer link to setup design console in your local.
Refer link to login in OIM from API.
*/
package com.test;
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.vo.JarElement;
public class ManageJar {
static PlatformUtilsService platformUtilsServe = null;
/*
Enter the jar type
1.JavaTasks
2.ScheduleTask
3.ThirdParty
4.ICFBundle
*/
public static void main(String[] args) throws Exception {
OIMClient oimClient = login(".\\Input\\authwl.conf", "t3://host:port/", "xelsysadm", "password", false, "");
platformUtilsServe = oimClient.getService(PlatformUtilsService.class);
uploadJar("JavaTasks", "temp/Custom_Java.jar");
uploadJar("ScheduleTask", "temp/Custom_Sch.jar");
uploadJar("ThirdParty", "temp/Custom_ThirdParty.jar");
uploadJar("ICFBundle", "temp/Custom_ICFBundle.jar");
deleteJar("JavaTasks", "Custom_Java.jar");
purgeCache();
oimClient.logout();
}
public static void purgeCache() throws Exception
{
platformUtilsServe.purgeCache("ALL");
System.out.println("Successfully purged the cache.");
}
public static void uploadJar(String jarType, String jarPath) throws Exception
{
System.out.println( "Going to uploaded jar: "+jarPath);
JarElement jarElement = new JarElement();
jarElement.setType(jarType);
jarElement.setPath(jarPath);
Set<JarElement> jarElements = new HashSet<JarElement>();
jarElements.add(jarElement);
platformUtilsServe.uploadJars(jarElements);
System.out.println( "Successfully uploaded jar: "+jarPath);
}
public static void deleteJar(String jarType, String jarName) throws Exception
{
JarElement jarElement = new JarElement();
jarElement.setType(jarType);
jarElement.setName(jarName);
Set<JarElement> jarElements = new HashSet<JarElement>();
jarElements.add(jarElement);
platformUtilsServe.deleteJars(jarElements);
System.out.println( "Successfully deleted jar: "+ jarName);
}
public static void updateJar(String jarType, String jarPath) throws Exception
{
JarElement jarElement = new JarElement();
jarElement.setType(jarType);
jarElement.setPath(jarPath);
Set<JarElement> jarElements = new HashSet<JarElement>();
jarElements.add(jarElement);
platformUtilsServe.updateJars(jarElements);
System.out.println( "Successfully updated jar:" + jarPath);
}
public static void downloadJar(String jarType, String jarName, String destinationPath) throws Exception
{
JarElement jarElement = new JarElement();
jarElement.setType(jarType);
jarElement.setName(jarName);
jarElement.setPath(destinationPath);
Set<JarElement> jarElements = new HashSet<JarElement>();
jarElements.add(jarElement);
platformUtilsServe.downloadJars(jarElements);
System.out.println("Successfully downloaded jar: " + destinationPath);
}
public static OIMClient login(String authwlPath, String oimProviderURL,
String userId, String password, boolean isSSL, String trustKeystorePath){
System.setProperty("java.security.auth.login.config", authwlPath);
System.setProperty("APPSERVER_TYPE", "wls");
if(isSSL)
System.setProperty("weblogic.security.SSL.trustedCAKeyStore", trustKeystorePath);
Hashtable<String, String> env = new Hashtable<String, String>();
env.put(OIMClient.JAVA_NAMING_FACTORY_INITIAL, "weblogic.jndi.WLInitialContextFactory");
env.put(OIMClient.JAVA_NAMING_PROVIDER_URL, oimProviderURL);
OIMClient oimClient = new OIMClient(env);
try {
oimClient.login(userId, password.toCharArray());
System.out.println("Login Done!!!");
} catch (LoginException e) {
e.printStackTrace();
}
return oimClient;
}
}
Steps to run below code
Update Host, Port & password, jar name & Jar path from OIM Machine in belwo code
Get the authwl.conf file from designconsole/config folder and then run below method
Refer link to setup design console in your local.
Refer link to login in OIM from API.
*/
package com.test;
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.vo.JarElement;
public class ManageJar {
static PlatformUtilsService platformUtilsServe = null;
/*
Enter the jar type
1.JavaTasks
2.ScheduleTask
3.ThirdParty
4.ICFBundle
*/
public static void main(String[] args) throws Exception {
OIMClient oimClient = login(".\\Input\\authwl.conf", "t3://host:port/", "xelsysadm", "password", false, "");
platformUtilsServe = oimClient.getService(PlatformUtilsService.class);
uploadJar("JavaTasks", "temp/Custom_Java.jar");
uploadJar("ScheduleTask", "temp/Custom_Sch.jar");
uploadJar("ThirdParty", "temp/Custom_ThirdParty.jar");
uploadJar("ICFBundle", "temp/Custom_ICFBundle.jar");
deleteJar("JavaTasks", "Custom_Java.jar");
purgeCache();
oimClient.logout();
}
public static void purgeCache() throws Exception
{
platformUtilsServe.purgeCache("ALL");
System.out.println("Successfully purged the cache.");
}
public static void uploadJar(String jarType, String jarPath) throws Exception
{
System.out.println( "Going to uploaded jar: "+jarPath);
JarElement jarElement = new JarElement();
jarElement.setType(jarType);
jarElement.setPath(jarPath);
Set<JarElement> jarElements = new HashSet<JarElement>();
jarElements.add(jarElement);
platformUtilsServe.uploadJars(jarElements);
System.out.println( "Successfully uploaded jar: "+jarPath);
}
public static void deleteJar(String jarType, String jarName) throws Exception
{
JarElement jarElement = new JarElement();
jarElement.setType(jarType);
jarElement.setName(jarName);
Set<JarElement> jarElements = new HashSet<JarElement>();
jarElements.add(jarElement);
platformUtilsServe.deleteJars(jarElements);
System.out.println( "Successfully deleted jar: "+ jarName);
}
public static void updateJar(String jarType, String jarPath) throws Exception
{
JarElement jarElement = new JarElement();
jarElement.setType(jarType);
jarElement.setPath(jarPath);
Set<JarElement> jarElements = new HashSet<JarElement>();
jarElements.add(jarElement);
platformUtilsServe.updateJars(jarElements);
System.out.println( "Successfully updated jar:" + jarPath);
}
public static void downloadJar(String jarType, String jarName, String destinationPath) throws Exception
{
JarElement jarElement = new JarElement();
jarElement.setType(jarType);
jarElement.setName(jarName);
jarElement.setPath(destinationPath);
Set<JarElement> jarElements = new HashSet<JarElement>();
jarElements.add(jarElement);
platformUtilsServe.downloadJars(jarElements);
System.out.println("Successfully downloaded jar: " + destinationPath);
}
public static OIMClient login(String authwlPath, String oimProviderURL,
String userId, String password, boolean isSSL, String trustKeystorePath){
System.setProperty("java.security.auth.login.config", authwlPath);
System.setProperty("APPSERVER_TYPE", "wls");
if(isSSL)
System.setProperty("weblogic.security.SSL.trustedCAKeyStore", trustKeystorePath);
Hashtable<String, String> env = new Hashtable<String, String>();
env.put(OIMClient.JAVA_NAMING_FACTORY_INITIAL, "weblogic.jndi.WLInitialContextFactory");
env.put(OIMClient.JAVA_NAMING_PROVIDER_URL, oimProviderURL);
OIMClient oimClient = new OIMClient(env);
try {
oimClient.login(userId, password.toCharArray());
System.out.println("Login Done!!!");
} catch (LoginException e) {
e.printStackTrace();
}
return oimClient;
}
}
No comments:
Post a Comment