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!!!