Pages

Wednesday, April 16, 2014

Register and UnRegister OIM Plugin in OIM Server


The PlatformService interface API being used to register and  un-register the OIM plugin pro-grammatically in OIM repository as follows:



Pre-Requisite:

Initial Setup.

Please follow the link and setup the OIM client environment to use to create the OIM Objects.


Client Code Setup
Developing the EventHandler Class 

PlatformService  API Usage:

1. Registering the Plugin.

2. Unrgister the Plugin.

Tasks Needs to be Performed:

1.    Create the OIMClient Handle


OIMClient client= new OIMClient();
client.login(username,password.toCharArray());

2.    Get PlatformService and PlatformUtilsService service object

PlatformService platformService = client.getService(PlatformService.class);
PlatformUtilsService platformUtilsService = client.getService(PlatformUtilsService.class);

3.  Create the  plugin.xml file

<oimplugins>
<plugins pluginpoint="oracle.iam.platform.kernel.spi.EventHandler">
<plugin pluginclass="test.eventhandlers.NamePreProcessEventHandlers" version="1.0" name="
NamePreProcessEventHandlers"/>
</plugins>
</oimplugins>

Replace pluginclass with your plugin class name.
           

4.  Create the Plugin Zip File. 

mkdir NamePreProcessEventHandlers
mkdir NamePreProcessEventHandlers/lib

copy plugin.xml file to NamePreProcessEventHandlers directory
copy NamePreProcessEventHandlers.jar file to NamePreProcessEventHandlers/lib directory
Create the NamePreProcessEventHandlers.zip file as follows
zip NamePreProcessEventHandlers.zip NamePreProcessEventHandlers/*

5.  Register the Plugin. 

                String operation=" - RegisterPlugin - ";
                // replace the plugin zip file according to your file path
                 String pluginFile="/tmp/NamePreProcessEventHandlers.zip"
File file= new File(pluginFile);
if(file.exists())
{
int size= (int)file.length();
byte data[]= new byte[size];
InputStream ins=null;
try
{
ins= new FileInputStream(file);
int bytesread= ins.read(data, 0,size);
while(bytesread < size)
{
bytesread += ins.read(data, bytesread, (bytesread-size));
}
platformService.registerPlugin(data);
}
catch(Exception e)
{
System.out.println(operation+e);
throw new RuntimeException(e);
}
finally
{
if(ins != null)
{
try {
ins.close();
} catch (IOException e)
{
System.out.println(operation+e);
throw new RuntimeException(e);
}
}
}


}
else
{
throw new RuntimeException("The Plugin File "+pluginFile + " Not Found");
}


6.  UnRegister Plugin.


operation=" - unRegisterPlugin - ";
                 String pluginClass="test.eventhandlers.NamePreProcessEventHandlers";
                  // replace plugin class with your pluin class name
try
{
platformService.unRegisterPlugin(pluginClass);
} catch (PlatformServiceAccessDeniedException e) {
System.out.println(operation+e);
throw new RuntimeException(e);
} catch (PluginException e) {
System.out.println(operation+e);
throw new RuntimeException(e);
}

7. Purge Cache.

String operation=" - purgeCache - ";
                String category="All";
try
{
platformUtilsService.purgeCache(category);
logger.info(operation+"Purge Cache "+category+" Completed Successfully");
} catch (InvalidCacheCategoryException e)
{
System.out.println(operation+e);
throw new RuntimeException(e);
}

8. Restart the OIM Server

No comments:

Post a Comment