/** * This is where it all happens * * <p>Logic here is as follows (1) Get all user information out of the comms directories (2) Get * all user information out of the OIM (3) For each user in the comms directories (4) If the user * exists in OIM (5) If status in comms is true and duacmailboxexists = 1 (6) continue, removing * user from OIM list (7) If status in comms is false and duacmailboxexists = 0 (8) continue, * removing user from OIM list (9) If status in comms is true and duacmailboxexists = 0 (10) set * duacmailboxexists = 1, remove user from OIM list (11) if status in comms is false and * duacmailboxexists = 1 (12) set duacmailboxexists = 0, remove user from OIM list, and call * revokeMailbox (14) For each user left in the OIM list (15) if user does not apear in the comms * directories (16) if duacmailboxexists = 1 (17) set duacmailboxexists = 0, remove user from OIM * list, call revokeMailbox * * <p>Really not as complex as it looks. */ public void execute() { // Get the LDAP user data first ldapMap = getLDAPData(); // Check whether the response was null and die if it was if (ldapMap == null) { logger.error(connectorName + " getLDAPData failed to return data -- bailing out"); return; } // Get OIM user data next OIMMap = getOIMData(); // Check whether the response was null and die if it was if (OIMMap == null) { logger.error(connectorName + " getOIMData failed to return user data -- bailing out"); return; } // Now run logic from 3-12 Set ldapKeys = ldapMap.keySet(); Iterator iter = ldapKeys.iterator(); while (iter.hasNext()) { // for each key in the ldapMap hash String lk = (String) iter.next(); // Check whether OIM has this user somewhere if (OIMMap.containsKey(lk)) { // OIM has this user, so proceed Boolean lb = (Boolean) ldapMap.get(lk); if (lb.booleanValue() && OIMMap.get(lk) != null && OIMMap.get(lk).equals("1")) { // has mailbox and exists is 1 -- leave it alone OIMMap.remove(lk); continue; } if ((lb.booleanValue() && OIMMap.get(lk) != null && OIMMap.get(lk).equals("0")) || (lb.booleanValue() && OIMMap.get(lk) != null && OIMMap.get(lk).equals(""))) { // has mailbox and exists is 0 -- set exists // this should be very unlikely, but... HashMap<String, String> doSearchCriteria = new HashMap<String, String>(); doSearchCriteria.put("Users.User ID", lk); doSearchCriteria.put("Users.Status", "Active"); String[] doattrs = {"Users.User ID"}; try { tcResultSet doResultSet = moUserUtility.findUsersFiltered(doSearchCriteria, doattrs); if (doResultSet.getRowCount() != 1) { logger.error( connectorName + " Search in OIM for user " + lk + " returned " + doResultSet.getRowCount() + " results - something is wrong"); OIMMap.remove(lk); continue; } else { HashMap<String, String> attrsForOIM = new HashMap<String, String>(); attrsForOIM.put("USR_UDF_ACMAILBOXEXISTS", "1"); try { moUserUtility.updateUser(doResultSet, attrsForOIM); logger.info(connectorName + " Added duacmailboxexists to user " + lk); } catch (Exception e) { // Failed the update logger.error( connectorName + " Failed add of duacmailboxexists for user " + lk + " due to exception: " + e.getMessage() + " but moving on"); } OIMMap.remove(lk); continue; } } catch (Exception e) { // we failed to get the user from OIM, so nothing to do here -- go back to our homes // except we log it, since we appear to have failed finding a user who is there logger.error( connectorName + " User in OIMMap not present in OIM or setting duACMailboxExists failed -- very odd, but nothing to do here -- might want to investigate " + lk + " though"); OIMMap.remove(lk); // remove it anyway continue; } } if (!lb.booleanValue() && OIMMap.get(lk) != null && OIMMap.get(lk).equals("1")) { // mailbox no longer exists in LDAP, but is on in OIM // turn it off in OIM now HashMap<String, String> doSearchCriteria = new HashMap<String, String>(); doSearchCriteria.put("Users.User ID", lk); doSearchCriteria.put("Users.Status", "Active"); String[] doattrs = {"Users.User ID", "Users.Key"}; try { tcResultSet doResultSet = moUserUtility.findUsersFiltered(doSearchCriteria, doattrs); if (doResultSet.getRowCount() != 1) { logger.error( connectorName + " Search in OIM for user " + lk + " returned " + doResultSet.getRowCount() + " results - something is wrong"); OIMMap.remove(lk); continue; } else { HashMap<String, String> attrsForOIM = new HashMap<String, String>(); attrsForOIM.put("USR_UDF_ACMAILBOXEXISTS", ""); // need to call revokeMailbox() here, once it's written revokeMailbox(doResultSet.getLongValue("Users.Key")); try { moUserUtility.updateUser(doResultSet, attrsForOIM); logger.info(connectorName + " Removed duacmailboxexists from user " + lk); } catch (Exception e) { logger.error( connectorName + " Failed removing duacmailboxexists for " + lk + " please investigate -- moving on past " + e.getMessage()); } OIMMap.remove(lk); continue; } } catch (Exception e) { // We missed on the findUsersFiltered in some fashion, so log an error and move on logger.error( connectorName + " User in OIMap does not exist or failed removing duacmailboxexists for " + lk + " very odd, but nothing to do here -- please investigate"); OIMMap.remove(lk); // remove anyway again continue; } } // Fallthru case, then, is mailbox doesn't exist and the user doesn't have duacmailboxexists // so we leave the fallthru alone, but remove the OIM entry anyway OIMMap.remove(lk); // remove anyway continue; } else { // this user exists in LDAP but not in OIM // we should note that and move on logger.warn( connectorName + " User " + lk + " present in comms directory but missing in OIM. Nothing to do, but be aware this is strange"); // no need to remove, since we're not present in the OIMMap OIMMap.remove(lk); // but remove anyway } } // Now do the same thing with what's left in the OIMMap, but in reverse Set OIMKeys = OIMMap.keySet(); iter = OIMKeys.iterator(); while (iter.hasNext()) { // for each key in the ldapMap hash String ok = (String) iter.next(); // At this point, no one left in the OIM list should be in // the comms list, but we need to be certain, so... if (!ldapMap.containsKey(ok)) { // This is correct -- we're here because the LDAP doesn't contain this user anymore if (OIMMap.get(ok) != null && OIMMap.get(ok).equals("1")) { // We need to undo a duacmailboxexists setting here HashMap<String, String> doSearchCriteria = new HashMap<String, String>(); doSearchCriteria.put("Users.User ID", ok); doSearchCriteria.put("Users.Status", "Active"); String[] doattrs = {"Users.User ID", "Users.Key"}; try { tcResultSet doResultSet = moUserUtility.findUsersFiltered(doSearchCriteria, doattrs); if (doResultSet.getRowCount() != 1) { logger.error( connectorName + " Search in OIM for user " + ok + " returned " + doResultSet.getRowCount() + " results - something is wrong"); continue; } else { HashMap<String, String> attrsForOIM = new HashMap<String, String>(); attrsForOIM.put("USR_UDF_ACMAILBOXEXISTS", ""); // need to call revokeMailbox() here, once it's written revokeMailbox(doResultSet.getLongValue("Users.Key")); try { moUserUtility.updateUser(doResultSet, attrsForOIM); logger.info(connectorName + " Removed duacmailboxexists from user " + ok); } catch (Exception e) { // same as above logger.error( connectorName + " caught eception when trying to remove duacmailboxexists from " + ok + " moving on, but you probably need to investigate " + e.getMessage()); } } } catch (Exception e) { // same story as above logger.error( connectorName + " Failed to find OIM user " + ok + " or otherwise lost on the OIM search -- continuing, but you should investigate"); } } // otherwise, nothing to do -- we're empty in OIM and there is no mailbox // so we're all set. } else { // Something is awry -- we have the user in the LDAP but we got to this branch of the code // indicating that we fell through some sort of wormhole. logger.error( connectorName + " Impossible situation -- comms dir entry cannot exist, yet it does for user " + ok + " -- doing nothing with this case -- please investigate"); } } }