use of com.zimbra.cs.mailclient.imap.ImapConnection in project zm-mailbox by Zimbra.
the class AddAccountLogger method addAccountLoggerOnImapServer.
public static void addAccountLoggerOnImapServer(Server server, Account account, String category, String level) {
ImapConnection connection = null;
try {
connection = ImapConnection.getZimbraConnection(server, LC.zimbra_ldap_user.value(), AuthProvider.getAdminAuthToken());
} catch (ServiceException e) {
ZimbraLog.imap.warn("unable to connect to imapd server '%s' to issue X-ZIMBRA-ADD-ACCOUNT-LOGGER request", server.getServiceHostname(), e);
return;
}
try {
ZimbraLog.imap.debug("issuing X-ZIMBRA-ADD-ACCOUNT-LOGGER request to imapd server '%s' for account '%s'", server.getServiceHostname(), account.getName());
connection.addAccountLogger(account, category, level);
} catch (IOException e) {
ZimbraLog.imap.warn("failed to enable account level logging for account '%s' on server '%s'", account.getName(), server.getServiceHostname(), e);
} finally {
connection.close();
}
}
use of com.zimbra.cs.mailclient.imap.ImapConnection in project zm-mailbox by Zimbra.
the class ImapTestBase method connectAndLogin.
protected ImapConnection connectAndLogin(String user) throws IOException {
ImapConnection imapConn = connect(user);
imapConn.login(PASS);
return imapConn;
}
use of com.zimbra.cs.mailclient.imap.ImapConnection in project zm-mailbox by Zimbra.
the class TestImapViaImapDaemon method testClearDaemonCache.
// checking done in called methods
@SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert")
@Test
public void testClearDaemonCache() throws Exception {
// loads the account into the imapd cache
tryConnect(true, "should be able to log in initially");
Account acct = TestUtil.getAccount(USER);
CacheEntry acctByName = new CacheEntry(CacheEntryBy.name, acct.getName());
CacheEntry acctById = new CacheEntry(CacheEntryBy.id, acct.getId());
ImapConnection adminConn = getAdminConnection();
// verify that we can flush an account cache by name
disableImapAndCheckCachedValue(acct);
adminConn.flushCache("account", new CacheEntry[] { acctByName });
tryConnect(false, "should not be able to log in after flushing LDAP cache by account name");
// verify that we can flush an account cache by ID
enableImapAndCheckCachedValue(acct);
adminConn.flushCache("account", new CacheEntry[] { acctById });
tryConnect(true, "should be able to log in after flushing LDAP cache by account ID");
// verify that we can flush an account cache with multiple CacheEntries
disableImapAndCheckCachedValue(acct);
adminConn.flushCache("account", new CacheEntry[] { acctByName, acctById });
tryConnect(false, "should not be able to log in after flushing LDAP cache by account name and ID");
// verify that we can flush an account cache without a CacheEntry value
enableImapAndCheckCachedValue(acct);
adminConn.flushCache("account");
tryConnect(true, "should be able to log in after flushing entire LDAP account cache");
// verify that we can flush multiple cache types at once
disableImapAndCheckCachedValue(acct);
adminConn.flushCache("config,account");
tryConnect(false, "should not be able to log in after flushing multiple cache types");
// verify that we can flush all caches
enableImapAndCheckCachedValue(acct);
adminConn.flushCache("all");
tryConnect(true, "should be able to log in after flushing all caches");
}
use of com.zimbra.cs.mailclient.imap.ImapConnection in project zm-mailbox by Zimbra.
the class TestImapViaImapDaemon method flushNonImapCacheTypes.
@Test
public void flushNonImapCacheTypes() throws Exception {
// Flushing these cache types won't do anything on the imapd server, but
// we want to make sure that this does not fail;
ImapConnection adminConn = getAdminConnection();
Set<CacheEntryType> allTypes = new HashSet<CacheEntryType>(Arrays.asList(CacheEntryType.values()));
Set<CacheEntryType> nonImapTypes = Sets.difference(allTypes, ImapHandler.IMAP_CACHE_TYPES);
for (CacheEntryType type : nonImapTypes) {
try {
adminConn.flushCache(CacheEntryType.license.toString());
} catch (CommandFailedException e) {
fail("should be able issue X-ZIMBRA-FLUSHCACHE command for cache type " + type.toString());
}
}
}
use of com.zimbra.cs.mailclient.imap.ImapConnection in project zm-mailbox by Zimbra.
the class TestImapViaImapDaemon method testReloadLocalConfig.
@Test
public void testReloadLocalConfig() throws Exception {
// to test this, we set imap_max_consecutive_error to 1 and make sure imapd disconnects after
// the first failure
ImapConnection adminConn = getAdminConnection();
int savedMaxConsecutiveError = LC.imap_max_consecutive_error.intValue();
// don't use TestUtil.setLCValue, since it issues a ReloadLocalConfigRequest, which will
// send out its own RELOADLC request
LocalConfig lc = new LocalConfig(null);
lc.set(LC.imap_max_consecutive_error.key(), "1");
lc.save();
connection = connect(USER);
connection.login(PASS);
try {
// sanity check: even though the LC value is changed, imapd should still be using the old value
for (int i = 0; i < savedMaxConsecutiveError; i++) {
try {
connection.select("BAD");
} catch (CommandFailedException e) {
assertEquals("expected 'SELECT failed' error", "SELECT failed", e.getError());
}
}
try {
connection.select("INBOX");
fail("session should be disconnected due to too many consecutive errors");
} catch (CommandFailedException e) {
}
// reload LC and reconnect; imapd should now be using the new value
adminConn.reloadLocalConfig();
connection = connect(USER);
connection.login(PASS);
try {
connection.select("BAD");
} catch (CommandFailedException e) {
assertEquals("expected 'SELECT failed' error", "SELECT failed", e.getError());
}
try {
connection.select("INBOX");
fail("session should be disconnected after 1 error");
} catch (CommandFailedException e) {
}
} finally {
TestUtil.setLCValue(LC.imap_max_consecutive_error, String.valueOf(savedMaxConsecutiveError));
adminConn.reloadLocalConfig();
}
}
Aggregations