Description: Shows how to remove a custom plugin such as an event handler or scheduled task from Oracle Identity Manager via API.
package com.blogspot.oraclestack.utilities;
import java.util.Hashtable;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.security.auth.login.LoginException;
import oracle.iam.platform.OIMClient;
import oracle.iam.platform.pluginframework.PluginException;
import oracle.iam.platformservice.api.PlatformService;
import oracle.iam.platformservice.api.PlatformUtilsService;
import oracle.iam.platformservice.exception.InvalidCacheCategoryException;
import oracle.iam.platformservice.exception.PlatformServiceAccessDeniedException;
/**
* Removes a single plugin. This does not remove an entire zip plugin.
* Query the OIM.PLUGINS table to get ID and VERSION.
*/
public class UnRegisterPlugin
{
// Substitute these values accordingly
public static final String OIM_HOSTNAME = "localhost";
public static final String OIM_PORT = "14000";
public static final String OIM_PROVIDER_URL ="t3://" + OIM_HOSTNAME + ":" + OIM_PORT;
public static final String OIM_USERNAME = "xelsysadm";
public static final String OIM_PASSWORD = "Password1";
public static final String OIM_CLIENT_HOME ="/home/oracle/jdeveloper/mywork/OracleIdentityManager/Resources/oimclient";
public static final String AUTHWL_PATH =OIM_CLIENT_HOME + "/conf/authwl.conf";
public static final String PLUGIN_ID = "com.blogspot.oraclestack.eventhandlers.SetMiddleNamePreprocessEH";
public static final String PLUGIN_VERSION = "1.0";
public static void main(String[] args)
{
OIMClient oimClient = null;
try
{
//Set system properties required for OIMClient
System.setProperty("java.security.auth.login.config", AUTHWL_PATH);
System.setProperty("APPSERVER_TYPE", "wls");
// Create an instance of OIMClient with OIM environment information
Hashtable env = new Hashtable();
env.put(OIMClient.JAVA_NAMING_FACTORY_INITIAL,"weblogic.jndi.WLInitialContextFactory");
env.put(OIMClient.JAVA_NAMING_PROVIDER_URL, OIM_PROVIDER_URL);
oimClient = new OIMClient(env);
// Login to OIM with the approriate credentials
oimClient.login(OIM_USERNAME, OIM_PASSWORD.toCharArray());
// Remove single plugin
PlatformService service = oimClient.getService(PlatformService.class);
service.unRegisterPlugin(PLUGIN_ID, PLUGIN_VERSION);
// Purge Cache
PlatformUtilsService platUtilOps = oimClient.getService(PlatformUtilsService.class);
platUtilOps.purgeCache("ALL");
}
catch (PlatformServiceAccessDeniedException ex) {Logger.getLogger(RegisterPlugin.class.getName()).log(Level.SEVERE, null, ex);}
catch (PluginException ex) {Logger.getLogger(RegisterPlugin.class.getName()).log(Level.SEVERE, null, ex);}
catch (LoginException ex) {Logger.getLogger(RegisterPlugin.class.getName()).log(Level.SEVERE, null, ex);}
catch (InvalidCacheCategoryException e) {Logger.getLogger(RegisterPlugin.class.getName()).log(Level.SEVERE, null, e);}
finally
{
// Logout user from OIMClient
if (oimClient != null) { oimClient.logout(); }
}
}
}
No comments:
Post a Comment