Saturday, September 12, 2015

Post Process Event Handler in OIM

Event handler are nothing but Piece of java code which perform certain task on particular event.In this lab we are going to see the post process event handler which will copy the value of organization to LDAP Organization Unit.Please see the steps for the same here.

Note: Here we are going to deploy the code using oim custom installer for Jdeveloper. For steps please see the link "http://www.iamidm.com/2013/02/oim-11g-r2-customization-extension.html". Also it is assume that you know the folder structure and how to deploy the code using jdeveloper. For creating folder structure please go to "http://www.iamidm.com/2015/09/folder-structure-after-installing-oim.html"

1) Create the java project in jdeveloper and add the following jar as shown in figure.











2) Copy and paste the below code

package com.oimclient;
import java.io.Serializable;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import java.util.logging.Level;

import java.util.logging.Logger;

import oracle.iam.identity.orgmgmt.api.OrganizationManager;
import oracle.iam.identity.orgmgmt.api.OrganizationManagerConstants;
import oracle.iam.identity.orgmgmt.vo.Organization;
import oracle.iam.platform.Platform;
import oracle.iam.platform.context.ContextAware;
import oracle.iam.platform.entitymgr.EntityManager;
import oracle.iam.platform.entitymgr.vo.SearchCriteria;
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;

/**@author sunil
 * This event handler is use to copy the value
 * of organization field in the LDAP Organization unit field.
 *
 *
 */

public class CreateLDAPouEventHandler implements PostProcessHandler {

;

public CreateLDAPouEventHandler() {

}
/**
    *
    * @param arg0
    * @return
    */

@Override
public void initialize(HashMap<String, String> arg0)
{

}
/**
    *
    * @param arg0
    * @param arg1
    * @param arg2
    * @return
    */
@Override
public boolean cancel(long arg0, long arg1,
AbstractGenericOrchestration arg2)
{
return false;
}

/**
    *
    * @param arg0
    * @param arg1
    * @param arg2
    * @return
    */
@Override
public void compensate(long arg0, long arg1,
AbstractGenericOrchestration arg2)
{

}


 /**
    *
    * @param processId
    * @param eventId
    * @param orchestration
    * @return
    */
@Override
public EventResult execute(long processId, long eventId,
Orchestration orchestration) {

HashMap<String, Serializable> parameters = orchestration
.getParameters();

String entityId = orchestration.getTarget().getEntityId();

String targetType = orchestration.getTarget().getType();

try {

long orgKey;

if (parameters.get("act_key") instanceof ContextAware) {
orgKey = (Long) ((ContextAware) parameters.get("act_key")).getObjectValue();
} else {
orgKey = (Long) parameters.get("act_key");
}
OrganizationManager orgService = Platform.getService(OrganizationManager.class);
Set orgCritAttrs = new HashSet();

SearchCriteria orcriteria = new SearchCriteria("act_key", orgKey,SearchCriteria.Operator.EQUAL);
orgCritAttrs.add(OrganizationManagerConstants.AttributeName.ORG_NAME.getId());

List<Organization> orgs = orgService.search(orcriteria,orgCritAttrs, null);
String organizationName = (String) orgs.get(0).getAttribute("Organization Name");
HashMap<String, Object> mapAttrs = new HashMap<String, Object>();
mapAttrs.put("LDAP Organization Unit", organizationName);

EntityManager entMgr = Platform.getService(EntityManager.class);
entMgr.modifyEntity(targetType, entityId, mapAttrs);

} catch (Exception e) {
e.printStackTrace();
}

return new EventResult();
}

/**
    *
    * @param parameters
    * @param key
    * @return
    */
private String getParameterValue(HashMap<String, Serializable> parameters,String key)
{

String value = (parameters.get(key) instanceof ContextAware) ? (String) ((ContextAware) parameters
.get(key)).getObjectValue() : (String) parameters.get(key);

return value;
}

/**
    *
    * @param arg0
    * @param arg1
    * @param arg2
    * @return
    */
@Override
public BulkEventResult execute(long arg0, long arg1, BulkOrchestration arg2)
{
return null;
}

}

3) Create the "plugin.xml" with content as shown below.
<?xml version="1.0" encoding="UTF-8"?>
<oimplugins xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.oracle.com/schema/oim/plugin plugin.xsd">
<plugins pluginpoint="oracle.iam.platform.kernel.spi.EventHandler">
<plugin pluginclass="com.oimclient.CreateLDAPouEventHandler" version="1.0" name="SamplePostprocessExtension">
</plugin>
</plugins>
</oimplugins>

4) Create "metadata.xml" with content as shown below
<?xml version="1.0" encoding="UTF-8"?>
<eventhandlers xmlns="http://www.oracle.com/schema/oim/platform/kernel" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.oracle.com/schema/oim/platform/kernel orchestration-handlers.xsd">
<action-handler
class="com.oimclient.CreateLDAPouEventHandler" entity-type="User" operation="CREATE" name="SamplePostprocessExtension" stage="postprocess" order="1000" sync="TRUE"/>
</eventhandlers>

5) Paste the plugin.xml & metadata.xml file inside config folder.

6) Deploy the project. Create user and test the output. 

No comments:

Post a Comment

Other Posts