Thursday, 20 April 2017

OAM Adaptive authentication Scheme mobile number Masking

By default Adaptive authentication scheme for second factor authentication mobile number (used for OTP) masking works for many numbers and masks them
but in some cases it does not mask some numbers
e.g.

+XX-XXX-XXXXXXX
+XX-XXXXXXXXXX

etc.

So we need to change the OOTB (PhoneMaskRegex) regular expression in the
Adaptive Authentication Module
&
Adaptive Authentication Scheme

\d{1,2}\D?\D?(\d{3})\D?\D?(\d{3})\D?(\d{2})\d{2}

\d{1,2} means any 2 digits can be in the beginning
\D? means it can be any Character
(\d{3}) means any 3 digits and these digits will be masked as *

Incase a character comes in the beginning OOTB RE does not handle it
So according to my situation to handle the above mentioned numbers I modified the OOTB RE

\D?\d{1,2}\D?\D?(\d{3})\D?\D?(\d{3})\D?(\d{2})\d{2,3}

Wednesday, 19 April 2017

Notify Management if the User is updated in OIM



import com.thortech.xl.crypto.tcCryptoUtil;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import oracle.core.ojdl.logging.ODLLogger;
import static oracle.iam.identity.usermgmt.api.UserManagerConstants.AttributeName.MANAGER_KEY;
import static oracle.iam.identity.usermgmt.api.UserManagerConstants.AttributeName.USER_LOGIN;
import oracle.iam.identity.exception.AccessDeniedException;
import oracle.iam.identity.exception.NoSuchUserException;
import oracle.iam.identity.exception.UserLookupException;
import oracle.iam.identity.usermgmt.api.UserManager;
import oracle.iam.identity.usermgmt.vo.User;
import oracle.iam.notification.api.NotificationService;
import oracle.iam.notification.vo.NotificationEvent;
import oracle.iam.platform.Platform;
import oracle.iam.platform.kernel.EventFailedException;
import oracle.iam.platform.kernel.OrchestrationEngine;
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;
public class userModifyNotification implements PostProcessHandler{
   
    private ODLLogger logger = ODLLogger.getODLLogger("com.scb.oim.generateEmailID");
   
    /*
      This method is used to send Notification to user when User is updated using Self Service
 */
    
    public EventResult execute(long processId, long eventId, Orchestration orchestration) {
        String usrKey = null;
        logger.entering("Notification", "EventResult execute");
      
      
         String entityType = orchestration.getTarget().getType();
         EventResult result = new EventResult();
       
        if (!orchestration.getOperation().equals("MODIFY")) {
        usrKey = orchestration.getTarget().getEntityId();
        } else {
        OrchestrationEngine orchEngine = Platform.getService(OrchestrationEngine.class);
        usrKey = (String) orchEngine.getActionResult(processId);
        }
       
        try{
                         String templateName = "notifyuserdeleted";
                            NotificationService notService = Platform
                                            .getService(NotificationService.class);
                            NotificationEvent eventToSend = this
                                            .createNotificationEvent(templateName, "17381",usrKey);
                            notService.notify(eventToSend);
                           
                    }
                    catch(Exception e)
                    {
                        }
        logger.exiting("Notification", "ExecuteEvent");
               return new EventResult();
    }
   
   
    /*
     * This method is used to create the Notification Event using the Template Name and User Key
     */
    private NotificationEvent createNotificationEvent(String poTemplateName, String userKey,String userID) {
        logger.entering("Notification", "createNotificationEvent()");
        NotificationEvent event = null;
       
        try {
             String UserIDN=userID;
           
                event = new NotificationEvent();
                String[] receiverUserIds = getRecipientUserIds(userKey);
                event.setUserIds(receiverUserIds);
                event.setTemplateName(poTemplateName);
                event.setSender(null);
                logger.info("User ID: "+receiverUserIds.toString());
                logger.info("Template Name: "+poTemplateName);
                HashMap<String, Object> templateParams = new HashMap<String, Object>();
                templateParams.put("usr_key", UserIDN);
               
                event.setParams(templateParams);
                logger.exiting("Notification", "createNotificationEvent()");
        } catch (Exception e) {
                e.printStackTrace();
                logger.severe("Exception in createNotificationEvent()"+e.getMessage());
        }
        return event;
    }
    public BulkEventResult execute(long l, long l1,
                                   BulkOrchestration bulkOrchestration) {
       return null;
    }
   
    /**
      This method is used to fetch the UserID of the reciepient to whom the Notification needs to be sent
     */
    private String[] getRecipientUserIds(String userKey) throws NoSuchUserException, UserLookupException, AccessDeniedException {
        UserManager usrMgr = Platform.getService(UserManager.class);
        User user = null;
        String userId = null;
        Set<String> userRetAttrs = new HashSet<String>();
        userRetAttrs.add(MANAGER_KEY.getId());
        userRetAttrs.add(USER_LOGIN.getId());
        User manager = null;
        String managerId = null;
        String managerKey = null;
        Set<String> managerRetAttrs = new HashSet<String>();
        managerRetAttrs.add(USER_LOGIN.getId());
        user = usrMgr.getDetails(userKey, userRetAttrs, false);
        userId = user.getAttribute(USER_LOGIN.getId()).toString();
        List<String> userIds = new ArrayList<String>();
        userIds.add(userId);
        if (user.getAttribute(MANAGER_KEY.getId()) != null) {
                managerKey = user.getAttribute(MANAGER_KEY.getId()).toString();
                manager = usrMgr.getDetails(managerKey, managerRetAttrs, false);
                managerId = manager.getAttribute(USER_LOGIN.getId()).toString();
                //userIds.add(managerId);
        }
        String[] recipientIDs = userIds.toArray(new String[0]);
        return recipientIDs;
    }
     public boolean cancel(long l, long l1,
                          AbstractGenericOrchestration abstractGenericOrchestration) {
        return false;
    }
     public void initialize(HashMap<String, String> hashMap) {
    }
     public void compensate(long l, long l1,
                           AbstractGenericOrchestration abstractGenericOrchestration) {
    }
   
   
    
}




Deploy it in JAR file

Create a lib directory and put the JAR file in it

Create a Plugin.xml

Copy the below code in it

</oimplugins>  </plugins>    </plugin>    <plugin pluginclass="com.handler.iam.userModifyNotification" version="1.0" name="userModifyNotification">  <plugins pluginpoint="oracle.iam.platform.kernel.spi.EventHandler"><oimplugins xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><?xml version="1.0" encoding="UTF-8"?>

Create EventHandler.xml

Copy the below code in it

</eventhandlers><action-handler class="com.handler.iam.userModifyNotification" entity-type="User" operation="MODIFY" name="userModifyNotification" stage="postprocess" order="1000"    sync="TRUE" /><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"><?xml version="1.0" encoding="UTF-8"?>

Put the EventHandler.xml in META-INF directory

Deploy the plugin!