http://deepakdubeyontech.blogspot.com/2014/05/oim-11g-r2-ps2-notify-user-id-to-user.html
In this post, step-by-step instructions are given on how to create a custom component so that it can be registered to OIM 11gR2 PS2 or PS3.
Start JDeveloper
Select Java EE Edition and click OK
Click New Application
Take the defaults and click Next
Give it a name, say Client2 and click Next
Give your default package a name such as com.test.event.oim.user.NotifyUserIdToUser and click Finish
Name your class e.g. NotifyUserIdToUser and click OK
Your screen should look like this:
Copy and paste this code into your new class:
package com.test.event.oim.user;
import static oracle.iam.identity.usermgmt.api.UserManagerConstants.AttributeName.MANAGER_KEY;
import static oracle.iam.identity.usermgmt.api.UserManagerConstants.AttributeName.USER_LOGIN;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import oracle.iam.identity.exception.NoSuchUserException;
import oracle.iam.identity.exception.UserLookupException;
import oracle.iam.identity.usermgmt.api.UserManager;
import oracle.iam.identity.usermgmt.vo.User;
import oracle.iam.notification.api.NotificationService;
import oracle.iam.notification.vo.NotificationEvent;
import oracle.iam.platform.Platform;
import oracle.iam.platform.authz.exception.AccessDeniedException;
import oracle.iam.platform.kernel.spi.PostProcessHandler;
import oracle.iam.platform.kernel.vo.AbstractGenericOrchestration;
import oracle.iam.platform.kernel.vo.BulkEventResult;
import oracle.iam.platform.kernel.vo.BulkOrchestration;
import oracle.iam.platform.kernel.vo.EventResult;
import oracle.iam.platform.kernel.vo.Orchestration;
import java.util.logging.Logger;
public class NotifyUserIdToUser implements PostProcessHandler {
private static final Logger log = Logger.getLogger( NotifyUserIdToUser.class.getName() );
public EventResult execute(long processId, long eventId,
Orchestration orchestration) {
return new EventResult();
}
private NotificationEvent createNotificationEvent(String poTemplateName,
String userKey) {
NotificationEvent event = null;
try {
event = new NotificationEvent();
String[] receiverUserIds = getRecipientUserIds(userKey);
event.setUserIds(receiverUserIds);
event.setTemplateName(poTemplateName);
event.setSender(null);
HashMap<String, Object> templateParams = new HashMap<String, Object>();
templateParams.put("usr_key", userKey);
event.setParams(templateParams);
log.info("Template Name " + poTemplateName);
} catch (Exception e) {
e.printStackTrace();
System.out.println("e-------->" + e.getMessage());
}
return event;
}
@Override
public void initialize(HashMap<String, String> arg0) {
}
@Override
public boolean cancel(long arg0, long arg1,
AbstractGenericOrchestration arg2) {
return false;
}
@Override
public void compensate(long arg0, long arg1,
AbstractGenericOrchestration arg2) {
}
@Override
public BulkEventResult execute(long l, long l1, BulkOrchestration bulkOrch) {
try {
System.out.println("Entering BulkEventResult of NotifyUserIDToUser");
System.out.println("l ->" + l);
System.out.println("l1 ->" + l1);
String oprType = bulkOrch.getOperation();
System.out.println("oprType ->" + oprType);
HashMap<String, Serializable>[] bulkParams = bulkOrch
.getBulkParameters();
for (HashMap<String, Serializable> bulkParam : bulkParams) {
System.out.println("bulkParam ->" + bulkParam);
Set<String> bulkKeySet = bulkParam.keySet();
System.out.println("bulkKeySet ->" + bulkKeySet);
String usrLogin = null;
String usrKey = null;
for (String key : bulkKeySet) {
System.out.println("key ->" + key);
Serializable serializable = bulkParam.get(key);
System.out.println("serializable ->" + serializable);
if (key.equalsIgnoreCase("User Login")) {
usrLogin = serializable.toString();
System.out.println("usrLogin ->" + usrLogin);
UserManager usrMgr = Platform
.getService(UserManager.class);
User user = usrMgr.getDetails(usrLogin, null, true);
usrKey = user.getEntityId(); // getAttribute("usr_key").toString();
String uid = user.getId();
System.out.println("uid--->" + uid);
System.out.println("usrKey ->" + usrKey);
String templateName = "Notify UserId to User";
NotificationService notService = Platform
.getService(NotificationService.class);
NotificationEvent eventToSend = this
.createNotificationEvent(templateName, usrKey);
notService.notify(eventToSend);
}
}
}
} catch (Exception e) {
System.out.println("exception e in BulkExecuteEvent ->"
+ e.getMessage());
e.printStackTrace();
}
System.out.println("Exiting BulkEventResult of NotifyUserIDToUser");
return new BulkEventResult();
}
private String[] getRecipientUserIds(String userKey)
throws NoSuchUserException, UserLookupException,
AccessDeniedException {
UserManager usrMgr = Platform.getService(UserManager.class);
User user = null;
String userId = null;
Set<String> userRetAttrs = new HashSet<String>();
userRetAttrs.add(MANAGER_KEY.getId());
userRetAttrs.add(USER_LOGIN.getId());
User manager = null;
String managerId = null;
String managerKey = null;
Set<String> managerRetAttrs = new HashSet<String>();
managerRetAttrs.add(USER_LOGIN.getId());
user = usrMgr.getDetails(userKey, userRetAttrs, false);
userId = user.getAttribute(USER_LOGIN.getId()).toString();
List<String> userIds = new ArrayList<String>();
userIds.add(userId);
if (user.getAttribute(MANAGER_KEY.getId()) != null) {
managerKey = user.getAttribute(MANAGER_KEY.getId()).toString();
manager = usrMgr.getDetails(managerKey, managerRetAttrs, false);
managerId = manager.getAttribute(USER_LOGIN.getId()).toString();
userIds.add(managerId);
}
String[] recipientIDs = userIds.toArray(new String[0]);
return recipientIDs;
}
}
Your JDeveloper screen should look like this:
The compiler log pane will display errors as shown below:
To fix these, we need to modify the class path so that the relevant libraries and jar files can be included. To do this, in the Application Navigator, right click on Client and from the pop-up menu, select Project Properties:
From the Project Properties menu, select Libraries and Classpath:
Click on the Add JAR/Directory:
Most of the required jars will be in your $IDM_HOME/server which in this case is $IDM_HOME=/app/fmw/Oracle_IDM1/server. In the Add Archive or Directory pop up, enter /app/fmw/Oracle_IDM1/server/client/oimclient.jar and click Select. See below:
The following will be displayed:
Repeat the above for the following jar files:
$IDM_HOME/server/platform/iam-platform-kernel.jar
$IDM_HOME/server/platform/iam-platform-context.jar
Your Project Properties -> Libraries and Classpath should look like this:
Click Build -> Rebuild Client2.jpr (or whatever your project is called). You should get a clean build with no errors:
Source and class files will be located here:
/home/oracle/Application2/Client2/classes
/home/oracle/Application2/Client2/src
Next, we are ready to create the jar file and use Ant to register the plugin to OIM.
Set your ant and OIM environment variable and place your ant variable in the path:
# e.g. IDM_HOME=/app/fmw/Oracle_IDM1
OIM_ORACLE_HOME=$IDM_HOME
ANT_HOME=$MW_HOME/modules/org.apache.ant_17.1
export PATH=$PATH:$ANT_HOME/bin
export ORACLE_OIM_HOME
Create a plugins directory, say /home/oracle/oim_plugins
cd /home/oracle/oim_plugins
mkdir -p stage/custom/lib
Copy class files from /home/oracle/Application2/Client2/classes to /home/oracle/oim_plugins/stage/lib as follows:
cd /home/oracle/oim_plugins/stage/custom/lib
cp -rfp /home/oracle/Application2/Client2/classes .
Create a plugin.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<oimplugins>
<plugins pluginpoint="oracle.iam.
<plugin pluginclass=
"com.test.event.oim.user.
version="1.0"
name="NotifyUserIDToUser">
</plugin>
</plugins>
</oimplugins>
Next, create a zip archive:
zip -r NotifyUser.zip lib plugin.xml
You are now ready for registering your custom component into OIM.
cd $IDM_HOME/server/plugin_utility
Register the plugin:
ant -f pluginregistration.xml register
Buildfile: pluginregistration.xml
register:
[echo]
[echo] ******************************
[echo] REGISTRATION TOOL TO REGISTER
[echo] ******************************
[echo] This tool can be used to register or unregister plugins to OIM.
[echo]
...
...
...
[input] Enter the oim user id:
xelsysadm
[input]Enter the oim user password:
[input] Enter the server url [WLS : t3://<host>:<port> WAS : corbaloc:iiop:<host>:<port> )]:
t3://localhost:14000
[input] Enter name (complete file name with path) of the plugin file:
/home/oracle/oim_plugins_ins/
-register-to-was-server:
-register-to-wls-server:
...
...
...
BUILD SUCCESSFUL
Total time: 1 minute 37 seconds
Check for errors in the output. If there are no error, your plugin should now be registered and ready for use.