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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 | 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
1 2 3 4 5 6 | <? xml version = "1.0" encoding = "UTF-8" ?> < 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
1 2 3 4 | <? 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
1 2 3 4 5 6 7 | < 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 > |
1 2 3 | < logger name = "com.blogspot.oraclestack.eventhandlers.SetMiddleNamePreprocessEH" level = "TRACE:32" useParentHandlers = "false" > < handler name = "SetMiddleNamePreprocessEH" /> </ logger > |
mycustomplugin.zip | |-------- lib/ | | ---------- JAR FILE | |--------- plugin.xml | |--------- META-INF/ | ------ METADATA XML
No comments:
Post a Comment