OIM 11g R2 PS2 : Associating User to a Manager

This post covers a usual scenario encountered during trusted reconciliation where in the manager of a user cannot be set while reconciliation is running as sometimes the manager is not already created in OIM.

To workaround this problem the manager id is stored in a custom attribute and a daily job executed after the trusted recon which sets the manager id correctly to all users.



  1 package com.dubey.deepak.iam.oim.scheduled.tasks;
  2 
  3 import static com.dubey.deepak.iam.oim.scheduled.tasks.TaskConstants.MANAGERLOGIN;
  4 import static com.dubey.deepak.iam.oim.scheduled.tasks.TaskConstants.MANAGER_KEY;
  5 import static com.dubey.deepak.iam.oim.scheduled.tasks.TaskConstants.SUPERVISORID;
  6 import static com.dubey.deepak.iam.oim.scheduled.tasks.TaskConstants.USERID;
  7 import static com.dubey.deepak.iam.oim.scheduled.tasks.TaskConstants.USERKEY;
  8 import static com.dubey.deepak.iam.oim.scheduled.tasks.TaskConstants.USERROLE;
  9 import static com.dubey.deepak.iam.oim.scheduled.tasks.TaskConstants.USERTYPE;
 10 
 11 import java.util.HashMap;
 12 import java.util.Map;
 13 
 14 import oracle.iam.platform.Platform;
 15 import oracle.iam.scheduler.vo.TaskSupport;
 16 import Thor.API.tcResultSet;
 17 import Thor.API.Exceptions.tcAPIException;
 18 import Thor.API.Exceptions.tcColumnNotFoundException;
 19 import Thor.API.Operations.tcUserOperationsIntf;
 20 
 21 public class AssociateUserToManager extends TaskSupport {
 22 
 23  private int totalExceptions = 0;
 24 
 25  public AssociateUserToManager() {
 26   super();
 27 
 28  }
 29 
 30  @Override
 31  public void execute(HashMap hashMap) throws Exception {
 32 
 33   System.out.println("Starting  Associate User To Manager");
 34   String userType = (String) hashMap.get(USERTYPE);
 35   System.out.println("userType--->" + userType);
 36 
 37   tcUserOperationsIntf userOperationsIntf = null;
 38   try {
 39 
 40    userOperationsIntf = (tcUserOperationsIntf) Platform
 41      .getService(tcUserOperationsIntf.class);
 42 
 43    System.out.println("userOperationsIntf---->" + userOperationsIntf);
 44    Map<String, String> phAttributeList = new HashMap<String, String>();
 45    phAttributeList.put(USERROLE, userType);
 46    tcResultSet resultSet = userOperationsIntf
 47      .findUsers(phAttributeList);
 48    System.out.println("resultSet---->" + resultSet.getRowCount());
 49 
 50    for (int i = 0; i < resultSet.getRowCount(); i++) {
 51     resultSet.goToRow(i);
 52     String userID = resultSet.getStringValue(USERID);
 53     System.out.println("userID-->" + userID);
 54     String userKey = resultSet.getStringValue(USERKEY);
 55     System.out.println("userKey-->" + userKey);
 56     System.out.println("SUPERVISORID-->" + SUPERVISORID);
 57     String supervisorID = resultSet.getStringValue(SUPERVISORID);
 58     System.out.println("supervisorID -->" + supervisorID);
 59     String managerlogin = resultSet.getStringValue(MANAGERLOGIN);
 60     System.out.println("managerlogin  -->" + managerlogin);
 61 
 62     if ((supervisorID != null)
 63       && (!supervisorID.trim().equalsIgnoreCase(""))
 64       && (!supervisorID.equalsIgnoreCase(managerlogin))) {
 65      System.out.println("manager is empty for user ->" + userID);
 66      String managerKey = getManagerKey(supervisorID,
 67        userOperationsIntf);
 68      if (managerKey != null) {
 69       Map<String, String> userKeyMap = new HashMap<String, String>();
 70       userKeyMap.put(USERKEY, userKey);
 71       tcResultSet resultSet1 = userOperationsIntf
 72         .findUsers(userKeyMap);
 73       Map<String, String> updateMap = new HashMap<String, String>();
 74       updateMap.put(MANAGER_KEY, managerKey);
 75 
 76       userOperationsIntf.updateUser(resultSet1, updateMap);
 77       System.out
 78         .println("Done setting the manager to user ->"
 79           + userID);
 80      }
 81     }
 82 
 83    }
 84   } catch (tcAPIException e) {
 85    e.printStackTrace();
 86   } catch (Exception e) {
 87    e.printStackTrace();
 88   } finally {
 89 
 90    try {
 91     if (userOperationsIntf != null) {
 92      userOperationsIntf.close();
 93     }
 94 
 95    } catch (Exception e) {
 96     e.printStackTrace();
 97    }
 98   }
 99   System.out.println("SQL Exceptions --> " + this.totalExceptions);
100   System.out.println("Finishing  Associate User To Manager Task");
101 
102  }
103 
104  public String getManagerKey(String loginID,
105    tcUserOperationsIntf userOperationsIntf) {
106   System.out.println("Entering  getManagerKey->" + loginID);
107   Map<String, String> phAttributeList = new HashMap<String, String>();
108   phAttributeList.put(USERID, loginID);
109   tcResultSet resultSet;
110   String userKey = null;
111   try {
112    resultSet = userOperationsIntf.findUsers(phAttributeList);
113    System.out.println("resultSet---->" + resultSet.getRowCount());
114    for (int i = 0; i < resultSet.getRowCount(); i++) {
115     resultSet.goToRow(i);
116     userKey = resultSet.getStringValue(USERKEY);
117 
118    }
119   } catch (tcAPIException e) {
120    System.out.println("exception  ->" + e.toString());
121    e.printStackTrace();
122   } catch (tcColumnNotFoundException e) {
123    System.out.println("exception  ->" + e.toString());
124    e.printStackTrace();
125   } catch (Exception e) {
126    System.out.println("exception  ->" + e.toString());
127    e.printStackTrace();
128   }
129   System.out.println("Exiting  getManagerKey ->");
130   return userKey;
131  }
132 
133  @Override
134  public HashMap getAttributes() {
135   // TODO Auto-generated method stub
136   return null;
137  }
138 
139  @Override
140  public void setAttributes() {
141   // TODO Auto-generated method stub
142 
143  }
144 
145 }
146 


Plugin.xml

<?xml version="1.0" encoding="UTF-8"?>
<oimplugins>  
<plugins pluginpoint="oracle.iam.scheduler.vo.TaskSupport">
<plugin pluginclass="
com.dubey.deepak.iam.oim.scheduled.tasks.AssociateUserToManager" version="1.0" name="AssociateUserToManager"/>
</plugins>
</oimplugins>
Go to OIM_HOME/plugin_utility/ to register the plugin

ant -f  pluginregistration.xml register 
 
Package the plugin in a zip file for it to be registered correctly.

Comments

Popular posts from this blog

OIM 11g R2 PS2 : SOA Approval Workflow Sample

OHS 12c (12.1.3) webgate deployment and configuration

Oracle Identity Manager (OIM) Interview Questions