示例#1
0
  /** Writes user state information to the shared filesystem */
  private void updateStateCache(
      final Customer customer,
      final int transitionId,
      final CustomerState newState,
      Latch dbLatch) {
    try {
      dbLatch.acquire();
    } catch (InterruptedException e) {
      m_logCategory.fatal(
          "Unable to acquire database latch to write state info for customer "
              + customer.getCustID()
              + " and transition "
              + transitionId,
          e);
      return;
    }

    blockHereIfBadNfs();
    executeWithConnection(
        new ConnectionExecuteFunction<Object>() {
          public Object execute(Connection c) throws SQLException {
            // below does read-only DB and nfs.
            // It iterates multiple users and returning a list here could be
            // detrimental to scalability.
            updateStateCache(customer, transitionId, newState, c);
            return null;
          }
        });
  }
示例#2
0
  private static int getSourceID(Customer cust, String sourceName, Connection c)
      throws SQLException {
    PreparedStatement ps = null;
    ResultSet rs = null;
    try {
      ps =
          c.prepareStatement(
              "select source_id from dat_dirsync_sources where customer_id = ? and source = ?");
      ps.setInt(1, cust.getCustID());
      ps.setString(2, sourceName);
      rs = ps.executeQuery();
      if (rs.next()) {
        return rs.getInt(1);
      }
      rs.close();
      rs = null;
      ps.close();
      ps = null;

      // doesn't already exist, so create it with nulls for scheduling stuff
      ps =
          c.prepareStatement(
              "insert into dat_dirsync_sources (source_id, customer_id, source) values (nextval('seq_source_id'), ?, ?)");
      ps.setInt(1, cust.getCustID());
      ps.setString(2, sourceName);
      ps.executeUpdate();
      ps.close();
      ps = null;

      // and grab the sourceID
      ps = c.prepareStatement("select currval('seq_source_id')");
      rs = ps.executeQuery();
      rs.next();
      return rs.getInt(1);
    } finally {
      if (rs != null) {
        rs.close();
      }
      if (ps != null) {
        ps.close();
      }
    }
  }
  public boolean execute(CommandLine cmdLine) {
    ICustomerManager cm = m_container.getCustomerManager();
    List<String> domains = Collections.singletonList(ICustomerManager.EPA_CUSTOMER_DOMAIN);
    IIslandManager im = m_container.getIslandManager();
    int defaultIslandID = im.getDefaultIsland().getId();

    Customer cust =
        cm.createCustomer(
            ICustomerManager.EPA_CUSTOMER_NAME,
            "System", // fromAddress
            "System", // backendID
            "System", // templateID
            "System", // channel
            domains,
            "emsRootPW", // emsRootPassword
            false, // isPartialEnabled
            "System", // activeBrandKey
            "System", // externalID
            defaultIslandID,
            defaultIslandID,
            false);

    PasswordPolicy policy = new PasswordPolicy();
    policy.setUseStrongPasswords(true);
    cust.setPasswordPolicy(policy);
    cm.updateCustomers(Collections.singletonList(cust));

    IUserManager um = ManagementContainer.getInstance().getUserManager();
    UserAccount emsRoot = um.getUser("emsroot@" + ICustomerManager.EPA_CUSTOMER_DOMAIN);
    IAuthenticationManager am = ManagementContainer.getInstance().getAuthenticationManager();
    long seconds = 31556926; // Seconds in a year
    long time =
        System.currentTimeMillis() + (seconds * 100 * 1000L); // Lock the account for 100 years
    am.lockUserAccount(
        cust.getCustID(), emsRoot.getUserID(), "Locked from user details", "Unknown", time);

    return (cust != null);
  }
示例#4
0
  /** Writes user state information to the shared filesystem */
  private void updateStateCache(
      Customer customer, int transitionId, CustomerState newState, Connection c)
      throws SQLException {
    PreparedStatement pst = null;
    ResultSet rs = null;

    try {
      pst =
          c.prepareStatement(
              "SELECT u.secure_hash_key, u.object_id, u.user_state, u.is_deleted, u.last_activation_id "
                  + "FROM dat_user_account u, dat_transition_users tr "
                  + "WHERE u.object_id = tr.user_id AND u.customer_id=? "
                  + "AND tr.transition_id=?;");

      // The state files are used by Outlook, BB, and maybe future clients.
      pst.setInt(1, customer.getCustID());
      pst.setInt(2, transitionId);
      rs = pst.executeQuery();
      while (rs.next()) {
        int i = 0;
        byte[] key = rs.getBytes(++i);
        int userId = rs.getInt(++i);
        CustomerState state = CustomerState.fromInt(rs.getInt(++i));
        int isDeletedInt = rs.getInt(++i);
        int lastActivationId = rs.getInt(++i);

        // If the user is marked deleted but has a key, we'll try cleaning
        // up state files.
        boolean isDeleted = isDeletedInt != IUserManager.USER_NOT_DELETED;
        if (key == null || key.length == 0) {
          LogMessageGen lmg = new LogMessageGen();
          lmg.setSubject("dat_user_account.secure_hash_key not set");
          lmg.param(LoggingConsts.USER_ID, userId);
          m_logCategory.info(lmg.toString());

          // Without a key, we can't determine the signal filenames
          // so no cleanup is possible.
          continue;
        }

        ClientHashSupport hash = null;
        hash = new ClientHashSupport();
        hash.setCustomerId(customer.getCustID());
        hash.setUserId(userId);
        hash.setHashKey(key);
        hash.setLastActivationId(lastActivationId);

        if (m_logCategory.isInfoEnabled()) {
          LogMessageGen lmg = new LogMessageGen();
          lmg.setSubject("Updating signal files");
          lmg.param(LoggingConsts.USER_ID, userId);
          m_logCategory.info(lmg.toString());
        }
        // wrt EMSDEV-7854 nfs calls and database transactions.
        // Above is only doing a select; no locks are taken and this
        // method is private.
        updateSignalFiles(hash, state, isDeleted);
      } // each row.
    } finally {
      DbUtils.safeClose(rs);
      DbUtils.safeClose(pst);
    }
  }
示例#5
0
  @SuppressWarnings("unchecked")
  @Test
  public void testReadNextCustomer() throws Exception {
    CustomerDAO dao =
        EasyMock.createMockBuilder(CustomerDAO.class)
            .addMockedMethod("readDomainsAndGuids")
            .createStrictMock();
    ResultSet resultSet = EasyMock.createStrictMock(ResultSet.class);
    List<ICustomer> customerList = new LinkedList<ICustomer>();

    int custID = 34;
    int state = 3;
    String name = "myName";
    String fromAddress = "myFromAddr";
    String clientID = "myClientId";
    String clientKey = "myClientKey";
    String backendId = "myBackendId";
    String templateId = "myTemplateId";
    String externalID = "myExternalId";
    int estMailboxCount = 34453;
    int estCloudMailboxCount = 345234;
    int estOnpremisesJournalMailboxCount = 3523;
    int estWelcomedCount = 938423;
    int estNotificationCount = 3423;
    int estAdminCount = 45345;
    Date countsUpdatedTime = new Date();
    int estTotalContacts = 345234;
    int estTotalUsersWithContacts = 87432;
    int estTotalCalendarEntries = 343460;
    int estTotalUsersWithCalendar = 9892;
    int estTotalDLists = 8932;
    int estTotalDListMembers = 34982;
    int estTotalPDLs = 12342142;
    int estTotalPDLMembers = 8732324;
    int estNoWelcomeResponseCount = 734232;
    int estNoLoginCount = 90832;
    int estNoActiveLoginCount = 89923;
    int estIgnoredCount = 349823;
    String channel = "myChannel";

    EasyMock.expect(resultSet.getInt(1)).andReturn(custID);
    EasyMock.expect(resultSet.getInt(2)).andReturn(state);
    EasyMock.expect(resultSet.getString(3)).andReturn(name);
    EasyMock.expect(resultSet.getString(4)).andReturn(fromAddress);
    EasyMock.expect(resultSet.getString(5)).andReturn(clientID);
    EasyMock.expect(resultSet.getString(6)).andReturn(clientKey);
    EasyMock.expect(resultSet.getString(7)).andReturn(backendId);
    EasyMock.expect(resultSet.getString(8)).andReturn(templateId);
    EasyMock.expect(resultSet.getString(9)).andReturn(externalID);
    EasyMock.expect(resultSet.getInt(14)).andReturn(estMailboxCount);
    EasyMock.expect(resultSet.getInt(15)).andReturn(estCloudMailboxCount);
    EasyMock.expect(resultSet.getInt(16)).andReturn(estOnpremisesJournalMailboxCount);
    EasyMock.expect(resultSet.getInt(17)).andReturn(estWelcomedCount);
    EasyMock.expect(resultSet.getInt(18)).andReturn(estNotificationCount);
    EasyMock.expect(resultSet.getInt(19)).andReturn(estAdminCount);
    EasyMock.expect(resultSet.getTimestamp(20))
        .andReturn(new Timestamp(countsUpdatedTime.getTime()));
    EasyMock.expect(resultSet.getInt(21)).andReturn(estTotalContacts);
    EasyMock.expect(resultSet.getInt(22)).andReturn(estTotalUsersWithContacts);
    EasyMock.expect(resultSet.getInt(23)).andReturn(estTotalCalendarEntries);
    EasyMock.expect(resultSet.getInt(24)).andReturn(estTotalUsersWithCalendar);
    EasyMock.expect(resultSet.getInt(25)).andReturn(estTotalDLists);
    EasyMock.expect(resultSet.getInt(26)).andReturn(estTotalDListMembers);
    EasyMock.expect(resultSet.getInt(27)).andReturn(estTotalPDLs);
    EasyMock.expect(resultSet.getInt(28)).andReturn(estTotalPDLMembers);
    EasyMock.expect(resultSet.getInt(29)).andReturn(estNoWelcomeResponseCount);
    EasyMock.expect(resultSet.getInt(30)).andReturn(estNoLoginCount);
    EasyMock.expect(resultSet.getInt(31)).andReturn(estNoActiveLoginCount);
    EasyMock.expect(resultSet.getInt(32)).andReturn(estIgnoredCount);
    EasyMock.expect(resultSet.getString(33)).andReturn(channel);

    EasyMock.expect(
            dao.readDomainsAndGuids(
                EasyMock.eq(resultSet),
                EasyMock.eq(custID),
                EasyMock.isA(Set.class),
                EasyMock.isA(Set.class)))
        .andReturn(true);

    EasyMock.replay(dao, resultSet);
    assertTrue(
        "Should have found another customer.", dao.readNextCustomer(resultSet, customerList));
    EasyMock.verify(dao, resultSet);

    assertEquals("Should have customer in list.", 1, customerList.size());
    Customer cust = (Customer) customerList.get(0);

    assertEquals("Wrong customer id.", custID, cust.getCustID());
    assertEquals("Wrong customer state.", state, cust.getState().toInt());
    assertEquals("Wrong customer name.", name, cust.getName());
    assertEquals("Wrong from address.", fromAddress, cust.getFromAddress());
    assertEquals("Wrong backend id.", backendId, cust.getBackendHostname());
    assertEquals("Wrong template id.", templateId, cust.getTemplateId());
    assertEquals("Wrong channel.", channel, cust.getChannel());
    assertEquals("Wrong client id.", clientID, cust.getClientID());
    assertEquals("Wrong client key.", clientKey, cust.getClientKey());
    assertEquals("Wrong channel.", channel, cust.getChannel());
    assertEquals("Wrong est mailbox count.", estMailboxCount, cust.getEstMailboxCount());
    assertEquals(
        "Wrong est cloud mailbox count.", estCloudMailboxCount, cust.getEstCloudMailboxCount());
    assertEquals(
        "Wrong est on premises journal mailbox count.",
        estOnpremisesJournalMailboxCount,
        cust.getEstOnpremisesJournalMailboxCount());
    assertEquals("Wrong est not welcomed count.", estWelcomedCount, cust.getEstNotWelcomedCount());
    assertEquals(
        "Wrong est notification not set count.",
        estNotificationCount,
        cust.getEstNotificationNotSetCount());
    assertEquals("Wrong est admin count.", estAdminCount, cust.getEstAdminCount());
    assertEquals("Wrong counts updated time.", countsUpdatedTime, cust.getCountsUpdatedTime());
    assertEquals("Wrong total contacts.", estTotalContacts, cust.getTotalContacts());
    assertEquals(
        "Wrong total users with contacts.",
        estTotalUsersWithContacts,
        cust.getTotalUsersWithContacts());
    assertEquals(
        "Wrong total calendar entries.", estTotalCalendarEntries, cust.getTotalCalendarEntries());
    assertEquals(
        "Wrong total users with calendar entries.",
        estTotalUsersWithCalendar,
        cust.getTotalUsersWithCalendarEntries());
    assertEquals("Wrong total dlists.", estTotalDLists, cust.getTotalDlists());
    assertEquals("Wrong total dlist members.", estTotalDListMembers, cust.getTotalDlistMembers());
    assertEquals("Wrong total pdls.", estTotalPDLs, cust.getTotalPDLs());
    assertEquals("Wrong total pdl members.", estTotalPDLMembers, cust.getTotalPDLMembers());
    assertEquals(
        "Wrong est no welcome reponse count.",
        estNoWelcomeResponseCount,
        cust.getEstNoWelcomeResponseCount());
    assertEquals("Wrong est no login count.", estNoLoginCount, cust.getEstNoLoginCount());
    assertEquals(
        "Wrong est no active login count.", estNoActiveLoginCount, cust.getEstNoActiveLoginCount());
    assertEquals("Wrong est ignored count.", estIgnoredCount, cust.getEstIgnoredCount());
    assertEquals("Wrong external id.", externalID, cust.getExternalID());
  }