There are many requirements when we want to populate User form, Resource form with some predefined values or depending on some business logic. OIM provides Prepopulate plugins which can be used to populate the values on these different forms.
Prepopulate plug-ins can be used when the same logic is to be executed for both UI and API request creation, and can also be used when a UI interaction is not required.
Here I have taken the use case of prepopulating Organization field depend on logged in user's Organization. For e.g I have user who belongs to organization Finance and whenever this user will try to Create the new user, create user form will open with Organization value prefilled as Finance.
1. To achieve this goal we have to write the java class which will implement the oracle.iam.request.plugins.PrePopulationAdapter interface. The following is an example code:
package com.plugin;
import java.io.Serializable;
import Thor.API.tcResultSet;
import Thor.API.Operations.tcUserOperationsIntf;
import oracle.iam.identity.usermgmt.api.UserManager;
import oracle.iam.identity.usermgmt.vo.User;
import oracle.iam.platform.Platform;
import oracle.iam.request.exception.RequestServiceException;
import oracle.iam.request.plugins.PrePopulationAdapter;
import oracle.iam.request.vo.RequestData;
public class PrePopulateOrganization implements PrePopulationAdapter {
String className = this.getClass().getName();
public Serializable prepopulate(RequestData requestData)
throws RequestServiceException {
String methodName = "/plugins prepopulate()";
String reqrOrgKey = null;
tcUserOperationsIntf userOppsIntf = null;
try {
userOppsIntf = (tcUserOperationsIntf) Platform
.getService(tcUserOperationsIntf.class);
tcResultSet result = userOppsIntf.getSelfProfile();
UserManager usrmgr = Platform.getService(UserManager.class);
result.goToRow(0);
String requesterID = result.getStringValue("Users.Key");
User usr = usrmgr.getDetails(requesterID, null, false);
reqrOrgKey = usr.getOrganizationKey();
} catch (Exception e) {
e.printStackTrace();
throw new RequestServiceException(e.getMessage());
} finally {
if (userOppsIntf != null) {
userOppsIntf.close();
}
}
return reqrOrgKey;
}
}
2. Compile the above code and create a jar file.
3. Then you need to create plugin.xml.
<?xml version="1.0" encoding="UTF-8"?>
<oimplugins xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<plugins pluginpoint="oracle.iam.request.plugins.PrePopulationAdapter">
<plugin pluginclass= "com.plugin.PrePopulateOrganization" version="1.0" name="PrePopulateOrganization">
<metadata name="PrePopulationAdapater">
<value>CreateUserDataSet::Organization</value>
</metadata>
</plugin>
</plugins>
</oimplugins>
The metadata tag contains a value child node. This value child node must contain the pairs of FormName::AttributeName. Pair indicates a form attribute that will be populated by the prepopulate plug-in. In this example, such attribute is Organization in the CreateUserDataSet form. Same way you can populate the values on Application instance resource form.
4. The JAR file created above must be added to a ZIP file in the lib directory. The ZIP file must contain in the root path a XML file declaring the plug-in. This plugin zip is similar as we create for Schedulers/Eventhandler etc..
5. Register the plugin zip in OIM and as a result whenever you will open the Create user page, Organization will be populated with logged in users Organization.