Wednesday, January 23, 2013

Populating request attributes in OIM 11g R2 Part I - Prepopulate Plug-in

This is the first of a two posts series about pre-populating requests in OIM 11 R2. This post is also part of the OIM 11g Academy Series.

With the introduction of the Catalog, request creation process changed from a wizard to a shopping cart experience style. But request pre-populating is still a common requirement for OIM customers.

There are two different approaches to pre-populate a request:
  1. Pre-populate plug-ins
  2. UI customization


This post is about pre-populate plug-ins, and a second one will be posted for the UI customization.

Pre-populate plug-ins can be used when the same logic needs to be executed for both UI and API request creation, and they can also be used when a UI interaction is not required.

The customization approach is always to have one plug-in for each attribute that must be pre-populated in the request. Another important thing to notice is that the same plug-in can be used across different resources and even different attributes.

The plug-in code must implement the oracle.iam.request.plugins.PrePopulationAdapter interface. Below the example code for this post:

package com.oracle.demo.iam.prepop.plugin;

import java.io.Serializable;

import java.util.HashSet;
import java.util.List;

import oracle.iam.identity.usermgmt.api.UserManager;
import oracle.iam.identity.usermgmt.api.UserManagerConstants.AttributeName;
import oracle.iam.identity.usermgmt.vo.User;
import oracle.iam.platform.Platform;
import oracle.iam.request.vo.Beneficiary;
import oracle.iam.request.vo.RequestData;

public class UserLoginPrePop implements oracle.iam.request.plugins.PrePopulationAdapter {

    public UserLoginPrePop() {
        super();
    }

    public Serializable prepopulate(RequestData requestData) {

        String prePopUserId = null;

        List<Beneficiary> benList = requestData.getBeneficiaries();
        
        if(benList.size()==1){
            
            UserManager  usersvc = Platform.getService(UserManager.class);
            
            for(Beneficiary benf: benList){
                                        
                HashSet<string> searchAttrs = new java.util.HashSet<String>();
                searchAttrs.add(AttributeName.USER_LOGIN.getId());
            
                try {
                    User userBenef = usersvc.getDetails(benf.getBeneficiaryKey(),searchAttrs, false);
                    if (userBenef!= null) {
                        prePopUserId = userBenef.getLogin();        
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
        return prePopUserId;
    }
}


A pre-populate plug-in is like any other OIM plug-in: the plug-in class must be compiled and deployed to a Jar file. The Jar file must be added to a ZIP file under the path '/lib'. The ZIP file must contain in the root path a XML file declaring the plug-in. The XML used in this example is shown below:

<?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.oracle.demo.iam.prepop.plugin.UserLoginPrePop" version="1.0" name="UserLoginPrePop">
  <metadata name="PrePopulationAdapater">
   <value>OracleDBUMForm::Username|OIDUserForm::User ID</value>
  </metadata>
 </plugin>
</plugins>
</oimplugins>


There are a few import things to pay attention to in the XML above:
  • The 'xmlns' tag attribute must be present in the XML otherwise the plug-in is not invoked by OIM
  • The pluginpoin element must be 'oracle.iam.request.plugins.PrePopulationAdapter'
  • The 'metadata' tag and its child node 'value'. 'value' must contain the pairs of 'FormName::AttributeName'. Each pair indicates a form attribute that will be populated by the pre-populate plug-in. In this case, such attributes are 'Username' in the 'OracleDBUMForm' form and 'User ID' in the 'OIDUserForm' form. The form names are the ones configured when the ApplicationInstances and their forms were created (and not the 'process form' created when the connector is imported into OIM). 
The pre-populate plug-in can be deployed to either $OIM_HOME/server/plugins or it can be registered using the plug-in registration script. In production environments, it is always recommended to deploy using the command line as this approach uploads the plug-in Zip file to the database.

This blog post was created based on examples provided by my colleague Manoj Yadav.

7 comments:

  1. This worked like Charm. Thanks for sharing

    ReplyDelete
  2. Hi Daniel,

    Thanks for your post. I was curious to know how bulk requests work in OIM. Say i selected a catalog item and two target users. At that time the app instance form is getting dis-appeared in my request. Did i miss anything while creating the form? Also will pre-pop plugin work for bulk request? Thanks in advance

    ReplyDelete
    Replies
    1. Prasad,

      Yes, the pre-pop plugin will be invoked, but if you deploy the one from this example, it will fill in based on the first beneficiary data.

      In some cases, like bulk upload, it doesn't make much sense to have pre-pos.

      Hope this helps

      Delete
    2. Thanks Daniel. I had another doubt regarding UI customization. I found in OIM developer's guide that i should provide permission for a taskflow in jazn-data.xml. But i saw multiple jazn-data.xml files in my OIM_HOME folder. Can you let me know the exact location of the jazn-data.xml file in which new taskflow permissions needs to be added.

      Delete
    3. I do not have an answer at this moment.

      Delete
  3. Hai Daniel,

    I am bit confused about the imported classes. How I gonna compile this class and where I can find all classes which you have imported here. I am getting compilation error.

    Thanks ,
    Ritesh.

    ReplyDelete
    Replies
    1. Follow the documentation:

      http://docs.oracle.com/cd/E27559_01/dev.1112/e27150/apis.htm#OMDEV2836

      Delete

Note: Only a member of this blog may post a comment.