Search in sources :

Example 1 with ZimbraAuthenticator

use of com.zimbra.cs.security.sasl.ZimbraAuthenticator in project zm-mailbox by Zimbra.

the class ImapHandler method doFLUSHCACHE.

private boolean doFLUSHCACHE(String tag, List<CacheEntryType> types, List<CacheEntrySelector> entries) throws IOException {
    if (!checkState(tag, State.AUTHENTICATED)) {
        return true;
    } else if (!checkZimbraAdminAuth()) {
        sendNO(tag, "must be authenticated as admin with X-ZIMBRA auth mechanism");
        return true;
    }
    if (types.isEmpty()) {
        // nothing to do here
        sendOK(tag, "FLUSHCACHE completed");
        return true;
    }
    AuthToken authToken = ((ZimbraAuthenticator) authenticator).getAuthToken();
    try {
        AdminAccessControl aac = AdminAccessControl.getAdminAccessControl(authToken);
        Server localServer = Provisioning.getInstance().getLocalServer();
        aac.checkRight(localServer, Admin.R_flushCache);
    } catch (ServiceException e) {
        if (e.getCode().equalsIgnoreCase(ServiceException.PERM_DENIED)) {
            ZimbraLog.imap.error("insufficient rights for flushing cache on IMAP server", e);
        } else {
            ZimbraLog.imap.error("error while checking rights for flushing cache on IMAP server", e);
        }
        return canContinue(e);
    }
    CacheSelector cacheSelector = new CacheSelector();
    cacheSelector.setEntries(entries);
    for (CacheEntryType type : types) {
        try {
            FlushCache.doFlush(null, type, cacheSelector);
        } catch (ServiceException e) {
            ZimbraLog.imap.error("error flushing cache on IMAP server", e);
            return canContinue(e);
        }
    }
    sendOK(tag, "FLUSHCACHE completed");
    return true;
}
Also used : CacheSelector(com.zimbra.soap.admin.type.CacheSelector) ZimbraAuthenticator(com.zimbra.cs.security.sasl.ZimbraAuthenticator) Server(com.zimbra.cs.account.Server) AccountServiceException(com.zimbra.cs.account.AccountServiceException) ServiceException(com.zimbra.common.service.ServiceException) MailServiceException(com.zimbra.cs.mailbox.MailServiceException) AuthToken(com.zimbra.cs.account.AuthToken) AdminAccessControl(com.zimbra.cs.service.admin.AdminAccessControl) CacheEntryType(com.zimbra.soap.admin.type.CacheEntryType)

Aggregations

ServiceException (com.zimbra.common.service.ServiceException)1 AccountServiceException (com.zimbra.cs.account.AccountServiceException)1 AuthToken (com.zimbra.cs.account.AuthToken)1 Server (com.zimbra.cs.account.Server)1 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)1 ZimbraAuthenticator (com.zimbra.cs.security.sasl.ZimbraAuthenticator)1 AdminAccessControl (com.zimbra.cs.service.admin.AdminAccessControl)1 CacheEntryType (com.zimbra.soap.admin.type.CacheEntryType)1 CacheSelector (com.zimbra.soap.admin.type.CacheSelector)1