@Test public void testExpandMailbox() throws Exception { int customerID = m_user.getCustomerID(); int userID = m_user.getUserID(); String maildir = m_user.getMailDir(); long messageId = 7890; EasyMock.reset(m_mockStoreManager); executeRequest( 500, "uid", -1, "pid", 1, "cid", customerID, "mid", messageId, "private", "true"); EasyMock.reset(m_mockStoreManager); EasyMock.expect(m_mockStoreManager.expandMessageToMeta(customerID, maildir, messageId, 1, true)) .andReturn(true); executeRequest(200, "pid", 1, "uid", userID, "mid", messageId, "sender", "true"); EasyMock.reset(m_mockStoreManager); EasyMock.expect( m_mockStoreManager.expandMessageToMeta(customerID, maildir, messageId, 1, false)) .andReturn(true); executeRequest( 200, "pid", 1, "cid", customerID, "uid", userID, "mid", messageId, "sender", "false"); EasyMock.reset(m_mockStoreManager); EasyMock.expect( m_mockStoreManager.expandMessageToMeta(customerID, maildir, messageId, 1, false)) .andReturn(false); executeRequest( 500, "pid", 1, "cid", customerID, "uid", userID, "mid", messageId, "sender", "false"); }
public ActionForward executeInContext( UserContext uc, ActionMapping mapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) { int uid = Integer.parseInt(request.getParameter(Constants.USER_ID_FULL)); int custID = Integer.parseInt(request.getParameter(Constants.CUSTOMER_ID)); IUserManager um = ManagementContainer.getInstance().getUserManager(); UserAccount user = um.getUserAccount(custID, uid); if (user == null) { return mapping.findForward(FAILURE); } try { um.deleteEpaUser(user.getPrimaryEmail()); } catch (Exception ex) { reportSingleError( request, ActionMessages.GLOBAL_MESSAGE, "error.epa.user.delete.error", ex.getMessage()); return mapping.findForward(FAILURE); } IAuditManager auditManager = ManagementContainer.getInstance().getAuditManager(); auditManager.saveAudit( IAuditManager.AuditCategory.EPA_MGMT, "Removed EPA user " + user.getDisplayName() + " ( " + user.getPrimaryEmail() + " )", "Remove EPA User Audit", null, uc.getCurrentUser().getPrimaryEmail()); return mapping.findForward(SUCCESS); }
@Test public void testDescribeUserSetChanges() throws Exception { String changes = null; HttpSession httpSession = getSession(); UserContext.newContext(getRequest(), m_user, m_customer); changes = DiffUtils.describeUserSetChanges(null, null, null); assertNull("DiffUtils.describeUserSetChanges(null, null, null) should return null", changes); SavedUserSet susOld = new SavedUserSet(m_customer.getCustID()); SavedUserSet susNew = new SavedUserSet(m_customer.getCustID()); changes = DiffUtils.describeUserSetChanges(getRequest(), susOld, susNew); assertNull("Expected no diffs for 2 identical user sets", changes); List<SearchConstraint> constraints; constraints = new ArrayList<SearchConstraint>(); constraints.add( new SearchConstraint( IUserManager.PROP_USERID, SearchConstraintOperator.CONSTRAINT_EQUALS, m_user.getUserID())); susNew.addUsers(constraints); changes = DiffUtils.describeUserSetChanges(getRequest(), susOld, susNew); assertNotNull("Expected diffs on 2 different user sets", changes); }
public CacheFileNames getCacheFileNames(final UserAccount user) { SecureHashKeyResult toRet = executeWithConnection( new ConnectionExecuteFunction<SecureHashKeyResult>() { public SecureHashKeyResult execute(Connection c) throws SQLException { return getSecureHashKey(user, c); } }); if (toRet == null) { // A DB error should have been logged. return null; } // EMSDEV-7854. Signal file manipulation is done outside of a DB transaction. String stateFile = null; String newmailFile = null; ClientHashSupport hash = null; byte[] key = toRet.getKey(); if (key != null) { hash = new ClientHashSupport(); hash.setCustomerId(user.getCustomerID()); hash.setHashKey(key); hash.setUserId(user.getUserID()); hash.getStateCachePath(); hash.setLastActivationId(user.getLastActivationId()); // Lines below don't hit the spindle. File stateFileF = new File(getCacheBase(), hash.getStateCachePath()); stateFile = stateFileF.getAbsolutePath(); File newmailFileF = new File(getCacheBase(), hash.getNewMailCachePath()); newmailFile = newmailFileF.getAbsolutePath(); if (toRet.isJustCreated()) { // If Webmail doesn't find the signal file, it polls the database, // so ensure the files are there. updateSignalFiles(hash, user.getUserState(), user.isDeleted()); } } return new CacheFileNames(stateFile, newmailFile); }
@SuppressWarnings("unchecked") protected void setupFolderSyncZone() throws Exception { int custId = getJspTestUtils().getCustId(); IFolderSyncManager folderMgr = ManagementContainer.getInstance().getFolderSyncManager(); IUserManager userService = ManagementContainer.getInstance().getUserManager(); UserAccount account = userService.getUser(getJspTestUtils().getUserAddress()); m_userId = account.getUserID(); // first create the topology and zone itself CustomerTopology ct = createTopology(); Iterator serverIterator = ct.getAllServers(); if (!serverIterator.hasNext()) { fail("No server in topology."); } CustomerServer server = (CustomerServer) serverIterator.next(); Iterator storesIterator = ct.getAllStores(); if (!storesIterator.hasNext()) { fail("No stores in server."); } CustomerStore store = (CustomerStore) storesIterator.next(); FolderSyncZone zone = new FolderSyncZone(); zone.setCustomerId(getJspTestUtils().getCustId()); zone.setDisplayName("foobar"); zone.setRegistrationKey("12345"); zone.getServers().add(server); folderMgr.saveFolderSyncZone(zone); // now enable the user for folder sync account.setMessageStoreID(store.getStoreID()); userService.updateUsers(Arrays.asList(account)); SavedUserSet userSet = new SavedUserSet(custId); List<Integer> userIDs = Arrays.asList(account.getUserID()); List<SearchConstraint> oldScList = new ArrayList<SearchConstraint>(); oldScList.add( new SearchConstraint( UserManagerConstants.PROP_USERID, SearchConstraintOperator.CONSTRAINT_IN_LIST, userIDs)); userSet.addUsers(oldScList); folderMgr.saveUserSetEnabledForSync(custId, userSet); }
/** Return the user's secure_hash_key. If one wasn't found create one on the fly. */ private SecureHashKeyResult getSecureHashKey(UserAccount user, Connection c) throws SQLException { PreparedStatement select = null; // Create lazily. PreparedStatement update = null; int userId = user.getUserID(); boolean justCreated = false; byte[] key = null; try { // TODO: consider having UserManager returning secure_hash_key. // TODO: We have similar logic in several places for creating secure_hash_key just-in-time. // D.R.Y. this out. Sorry I couldn't resist using this cliche :) select = c.prepareStatement("SELECT secure_hash_key FROM dat_user_account WHERE object_id=?"); select.setInt(1, userId); ResultSet rs = select.executeQuery(); if (!rs.next()) { LogMessageGen lmg = new LogMessageGen(); lmg.setSubject("dat_user_account row not found"); lmg.param(LoggingConsts.USER_ID, userId); // possible that the user simply disappeared by the time we got here. m_logCategory.warn(lmg.toString()); } else { key = rs.getBytes(1); if (key == null || key.length == 0) { // hash key not found; create one on the fly. update = c.prepareStatement("UPDATE dat_user_account SET secure_hash_key=? WHERE object_id=?"); key = createNewRandomKey(); update.setBytes(1, key); update.setInt(2, userId); int ct = update.executeUpdate(); if (ct != 1) { LogMessageGen lmg = new LogMessageGen(); lmg.setSubject("Unable to update dat_user_account.secure_hash_key"); lmg.param(LoggingConsts.USER_ID, userId); m_logCategory.error(lmg.toString()); } else { justCreated = true; } } // needed to set key. } // user found } finally { DbUtils.safeClose(select); DbUtils.safeClose(update); } return new SecureHashKeyResult(key, justCreated); }
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); }
@Test public void testDescribeReviewerGroupReviewerChanges() throws Exception { String changes = null; UserContext.newContext(getRequest(), m_user, m_customer); changes = DiffUtils.describeReviewerGroupReviewerChanges(null, null, null); assertNull( "DiffUtils.describeReviewerGroupReviewerChanges(null, null, null) should return null", changes); List<SearchConstraint> constraints; constraints = new ArrayList<SearchConstraint>(); constraints.add( new SearchConstraint( IUserManager.PROP_USERID, SearchConstraintOperator.CONSTRAINT_EQUALS, m_user.getUserID())); SavedUserSet reviewers = new SavedUserSet(m_customer.getCustID()); reviewers.addUsers(constraints); ReviewerGroup oldRG = new ReviewerGroup(m_customer.getCustID(), 1, "name", reviewers, null, "extra"); ReviewerGroup newRG = new ReviewerGroup(m_customer.getCustID(), 1, "name", reviewers, null, "extra"); changes = DiffUtils.describeReviewerGroupReviewerChanges(getRequest(), oldRG, newRG); assertNull("Expected no diffs for 2 identical user sets", changes); reviewers = new SavedUserSet(m_customer.getCustID()); newRG.setReviewers(reviewers); changes = DiffUtils.describeReviewerGroupReviewerChanges(getRequest(), oldRG, newRG); assertNotNull("Expected diffs on 2 different reviewer groups", changes); SavedUserSet reviewers1 = new SavedUserSet(m_customer.getCustID()); reviewers1.addConstraintSets(InternalUserSets.getAllUsersSet(m_customer.getCustID())); oldRG.setReviewers(reviewers1); SavedUserSet reviewers2 = new SavedUserSet(m_customer.getCustID()); newRG.setReviewers(reviewers2); changes = DiffUtils.describeReviewerGroupReviewerChanges(getRequest(), oldRG, newRG); assertNotNull("Expected diffs on 2 different reviewer groups", changes); }
public File getEventLogFile(UserAccount user, int eventId) { return getEventLogFile(new File(getNfsRoot(), user.getMailDir()), eventId); }
// Use this to set headers that are required on all responses. protected void setResponseHeaders( ActionForm actionForm, HttpServletResponse response, UserAccount user, Device device) throws IOException { // The url is static across all devices in a customer. ICustomerManager customerManager = ManagementContainer.getInstance().getCustomerManager(); Customer cust = customerManager.getCustomer(user.getCustomerID()); IRimManager rimManager = ManagementContainer.getInstance().getRimManager(); String cappUrl = cust.getCappUrl(); if (m_devDebug) { // Our dev boxes use http and specifcy a port, this conflicts with the https // assumption of getCappUrl() cappUrl = "http://turbodog.austin.messageone.com:8080/"; } URL url = null; try { url = new URL(cappUrl); } catch (MalformedURLException e) { LogMessageGen lmg = new LogMessageGen(); lmg.setSubject("Bad URL"); lmg.param(LoggingConsts.URL, cappUrl); lmg.param(LoggingConsts.USER_ID, device.getUserId()); lmg.param(LoggingConsts.CUSTOMER_ID, device.getCustomerId()); lmg.param(LoggingConsts.PIN, device.getPin()); // This would come from the customer config, so it's bad. m_logCategory.error(lmg.toString(), e); response.setHeader(SUCCESS, "false"); return; } int deviceCheckin = cust.getCapabilities().getIntCapability(Capabilities.CAP_RIM_DEVICE_PERIODIC_CHECKIN, 30); response.setHeader("rim-access-url-protocol", url.getProtocol()); response.setHeader("rim-access-url-hostname", url.getHost()); if (url.getPort() > 0) { response.setHeader("rim-access-url-port", Integer.toString(url.getPort())); } response.setHeader(EMS_RIM_DISPLAY_NAME, device.getDisplayName()); response.setHeader("get-mail-path", "wfe/getRimMail.do"); response.setHeader("send-mail-path", "wfe/sendRimMail.do"); response.setHeader("get-display-name-path", "wfe/rimGetDisplayName.do"); response.setHeader("checkin-path", "wfe/rimCheckin.do"); response.setHeader("periodic-checkin", Integer.toString(deviceCheckin)); CustomerState state = user.getUserState(); String stateString = "ready"; if (CustomerState.ACTIVE.equals(state) || CustomerState.TEST.equals(state)) { stateString = "active"; String activationId = rimManager.getActivationId(device.getPin()); if (StringUtils.isEmptyOrNull(activationId)) { // EMSDEV-4722 // If an old agent is installed during activation, the dat_rim_user_connection_status // won't exist and thus no activation ID. If needed, create one on the fly. // Incidently, this will fix most of the problems we've had with activationId's // disappearing for various reasons. LogMessageGen.log( "Old agent activationId not found; will create one on the fly", m_logCategory) .param(LoggingConsts.PIN, device.getPin()) .param(LoggingConsts.USER_ID, device.getUserId()) .info(); activationId = rimManager.activateOldAgent(device.getPin(), device.getCustomerId()); // Try again. if (StringUtils.isEmptyOrNull(activationId)) { LogMessageGen.log("Unable to create activationId for old agent", m_logCategory) .param(LoggingConsts.PIN, device.getPin()) .param(LoggingConsts.USER_ID, device.getUserId()) .error(); } } // no activationId response.setHeader("activation-id", activationId); } // active. response.setHeader("application-state", stateString); response.setHeader(SUCCESS, "true"); }
@Test public void verifyRetentionPolicyFilterForRetentionHolds() throws Exception { // Create a new Test User LOGGER.info("Creating a new Test user"); String currentTime = Long.toString(System.currentTimeMillis()); String userName = "******" + currentTime; String userAddress = userName + "@" + getJspTestUtils().getDomain(); String password = getJspTestUtils().getPasswd(); getJspTestUtils().createTestUser(userName, userAddress, password); int custId = getJspTestUtils().getCustId(); LOGGER.info("Test user creation completed:" + userAddress); LOGGER.info("Customer Id is: " + Integer.toString(custId)); // Get Retention policy manager, Reviewer group manager and User manager IRetentionPolicyManager mgr = ManagementContainer.getInstance().getRetentionPolicyManager(); IReviewerGroupManager rgm = ManagementContainer.getInstance().getReviewerGroupManager(); IUserManager um = ManagementContainer.getInstance().getUserManager(); // Create Reviewer User set-1 for reviewers UserAccount reviewer1 = um.findUserForEmail(getJspTestUtils().m_userAddress); SavedUserSet sus1 = new SavedUserSet(custId); sus1.addUsers( Arrays.asList( new SearchConstraint( IUserManager.PROP_USERID, SearchConstraintOperator.CONSTRAINT_EQUALS, String.valueOf(reviewer1.getUserID())))); // sus1.setInternal(true); sus1.setName("REVIEWERS-1"); um.saveUserSet(sus1); // Create User set-1 for users whose mails will be reviewed by reviewer SavedUserSet scope1 = InternalUserSets.getAllUsersSet(custId); // scope1.setInternal(true); scope1.setName("SCOPE-1"); um.saveUserSet(scope1); // Create Reviewer group-1 LOGGER.info("Creating Reviewer group reviewerGrp1"); ReviewerGroup rg1 = rgm.createReviewerGroup(custId, "reviewerGrp1", sus1, scope1, null); rgm.updateReviewerGroup(rg1); rg1 = rgm.getReviewerGroup(custId, "reviewerGrp1"); LOGGER.info( "Reviewer group creation done. Reviewer group details-> GroupId:" + rg1.getGroupID() + ";GroupName:" + rg1.getGroupName()); RetentionPolicy qblh1 = TestUtils.createPolicy( RetentionPolicy.Mode.QUERY_BASED_LEGAL_HOLD, custId, RetentionPolicy.MAX_RETAIN, "QBLH-1", RetentionPolicy.HIGHEST_PRIORITY, "reviewerGrp1"); LOGGER.info( "Query based legal hold QBLH-1 details-> Policy Id:" + qblh1.getId() + ";Policy Name:" + qblh1.getName()); // Create Reviewer User set-2 for reviewers UserAccount reviewer2 = um.findUserForEmail(userAddress); SavedUserSet sus2 = new SavedUserSet(custId); sus2.addUsers( Arrays.asList( new SearchConstraint( IUserManager.PROP_USERID, SearchConstraintOperator.CONSTRAINT_EQUALS, String.valueOf(reviewer2.getUserID())))); sus2.setName("REVIEWERS-2"); um.saveUserSet(sus2); // Create User set-2 for users whose mails will be reviewed by reviewer SavedUserSet scope2 = InternalUserSets.getAllUsersSet(custId); scope2.setName("SCOPE-2"); um.saveUserSet(scope2); // Create Reviewer group-2 ReviewerGroup rg2 = rgm.createReviewerGroup(custId, "reviewerGrp2", sus2, scope2, null); rgm.updateReviewerGroup(rg2); rg2 = rgm.getReviewerGroup(custId, "reviewerGrp2"); LOGGER.info("Reviewer group details:" + rg2.getGroupID() + ";" + rg2.getGroupName()); RetentionPolicy qblh2 = TestUtils.createPolicy( RetentionPolicy.Mode.QUERY_BASED_LEGAL_HOLD, custId, RetentionPolicy.MAX_RETAIN, "QBLH-2", RetentionPolicy.HIGHEST_PRIORITY, "reviewerGrp2"); LOGGER.info( "Query based legal hold QBLH-2 details-> Policy Id:" + qblh2.getId() + ";Policy Name:" + qblh2.getName()); // Login as reviewer-1 and verify QBLH-1 is visible to reviewer-1 and QBLH-2 is not visible LOGGER.info("Logging in as reviewer-1"); getJspTestUtils() .login(getJspTestUtils().m_cappLoginUrl, getJspTestUtils().m_userAddress, password); getJspTestUtils().navigateToArchivePage(); getJspTestUtils().clickLink(By.id("auto_common_nav_search-reviewer")); getJspTestUtils().clickLink(By.id("auto_add_filter")); getJspTestUtils() .clickLink(By.id("auto_filter_dialog_field-button"), By.linkText("Retention Policy")); getJspTestUtils().clickLink(By.id("auto_filter_dialog_value_select-button")); assertNotNull( "Query Based legal hold QBLH-1 is not present for REVIEWERS-1", getJspTestUtils().findElement(By.linkText("QBLH-1"))); assertFalse( "Query Based legal hold QBLH-2 is present for REVIEWERS-1", getJspTestUtils().isElement(By.linkText("QBLH-2"))); getJspTestUtils().logout(); // Login as reviewer-2 and verify QBLH-2 is visible to reviewer-2 and QBLH-1 is not visible LOGGER.info("Logging in as reviewer-2"); getJspTestUtils().login(getJspTestUtils().m_cappLoginUrl, userAddress, password); getJspTestUtils().clickLink(By.id("auto_common_nav_search-reviewer")); getJspTestUtils().clickLink(By.id("auto_add_filter")); getJspTestUtils() .clickLink(By.id("auto_filter_dialog_field-button"), By.linkText("Retention Policy")); getJspTestUtils().clickLink(By.id("auto_filter_dialog_value_select-button")); assertNotNull( "Query Based legal hold QBLH-2 is not present for REVIEWERS-2", getJspTestUtils().findElement(By.linkText("QBLH-2"))); assertFalse( "Query Based legal hold QBLH-1 is present for REVIEWERS-2", getJspTestUtils().isElement(By.linkText("QBLH-1"))); getJspTestUtils().logout(); }