Description: A preprocess event handler which sets the user's middle name using the first letter of the user's first name if the user does not have a value for middle name. The event handler triggers on the creation of an OIM User.
Reference: https://docs.oracle.com/cd/E40329_01/dev.1112/e27150/oper.htm#OMDEV4768
Source Code
package com.blogspot.oraclestack.eventhandlers; import java.io.Serializable; import java.util.HashMap; import oracle.core.ojdl.logging.ODLLevel; import oracle.core.ojdl.logging.ODLLogger; import oracle.iam.identity.usermgmt.api.UserManagerConstants; import oracle.iam.platform.context.ContextAware; import oracle.iam.platform.kernel.spi.PreProcessHandler; 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; /** * A preprocess event handler which sets the user's middle name using the first * letter of the user's first name if the user does not have a value for middle name. * Triggers on the creation of an OIM User * @author rayedchan * @version 1.0 */ public class SetMiddleNamePreprocessEH implements PreProcessHandler { private ODLLogger logger = ODLLogger.getODLLogger(SetMiddleNamePreprocessEH.class.getName()); /** * Execution logic for preprocess event handler to set middle name. * @param l Process Id * @param l1 Event Id * @param orchestration Contains useful user data * @return */ public EventResult execute(long l, long l1, Orchestration orchestration) { logger.log(ODLLevel.NOTIFICATION, "V1.0 Enter execute() with parameters: [{0}], [{1}], [{2}]", new Object[]{l, l1, orchestration}); // Get changed parameter values (E.g. User attributes) from orchestation HashMap<String, Serializable> parameters = orchestration.getParameters(); logger.log(ODLLevel.NOTIFICATION, "Orchestration paramters: [{0}]", new Object[]{parameters}); // Get USR_KEY of target user String usrKey = orchestration.getTarget().getEntityId(); logger.log(ODLLevel.NOTIFICATION, "Target User Key: {0}", new Object[]{usrKey}); // Get "Middle Name" String middleName = getParamaterValue(parameters, UserManagerConstants.AttributeName.MIDDLENAME.getId()); // If the middle name is empty set the first letter of the first name as the middle initial if ((middleName == null) || middleName.equals("")) { String firstName = getParamaterValue(parameters, UserManagerConstants.AttributeName.FIRSTNAME.getId()); // Get "First Name" middleName = firstName.substring(0, 1); // Set middleName to first letter of first name orchestration.addParameter(UserManagerConstants.AttributeName.MIDDLENAME.getId(), middleName); // Pass data to orchestration so OIM can apply the changes } logger.log(ODLLevel.NOTIFICATION, "Middle Name: {0}", new Object[]{middleName}); return new EventResult(); } public BulkEventResult execute(long l, long l1, BulkOrchestration bulkOrchestration) { return null; } public void compensate(long l, long l1, AbstractGenericOrchestration abstractGenericOrchestration) { } public boolean cancel(long l, long l1, AbstractGenericOrchestration abstractGenericOrchestration) { return false; } public void initialize(HashMap<String, String> hashMap) { } /** * Get an attribute value based on the attribute name. * @param parameters User's attributes * @param key Name of the attribute API name * @return Value of the attribute to fetch */ private String getParamaterValue(HashMap<String, Serializable> parameters, String key) { if(parameters.containsKey(key)) { String value = (parameters.get(key) instanceof ContextAware) ? (String) ((ContextAware) parameters.get(key)).getObjectValue() : (String) parameters.get(key); return value; } else { return null; } } }
Plugin XML
<?xml version="1.0" encoding="UTF-8"?> <oimplugins xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <plugins pluginpoint="oracle.iam.platform.kernel.spi.EventHandler"> <plugin pluginclass="com.blogspot.oraclestack.eventhandlers.SetMiddleNamePreprocessEH" version="1.0" name="SetMiddleNamePreprocessEH"/> </plugins> </oimplugins>
Event Handler Metadata
<?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 entity-type="User" operation="CREATE" class="com.blogspot.oraclestack.eventhandlers.SetMiddleNamePreprocessEH" name="SetMiddleNamePreprocessEH" stage="preprocess" order="1050" sync="TRUE"/> </eventhandlers>
Logging
<log_handler name='SetMiddleNamePreprocessEH' level='TRACE:32' class='oracle.core.ojdl.logging.ODLHandlerFactory'> <property name='path' value='${domain.home}/servers/${weblogic.Name}/logs/SetMiddleNamePreProcessEH.log'/> <property name='useThreadName' value='true'/> <property name='maxFileSize' value='5242880'/> <property name='maxLogSize' value='52428800'/> <property name='encoding' value='UTF-8'/> </log_handler>
<logger name="com.blogspot.oraclestack.eventhandlers.SetMiddleNamePreprocessEH" level="TRACE:32" useParentHandlers="false"> <handler name="SetMiddleNamePreprocessEH"/> </logger>Plugin Zip Structure
mycustomplugin.zip | |-------- lib/ | | ---------- JAR FILE | |--------- plugin.xml | |--------- META-INF/ | ------ METADATA XML
No comments:
Post a Comment